From 90c205db2e0e06236b38ef698f04ab760f88094b Mon Sep 17 00:00:00 2001 From: "M.V. Hutz" Date: Sun, 11 Jan 2026 21:13:41 +0000 Subject: [PATCH] refactor: improve Makefile structure and usability (#11) ## Description This PR refactors the Makefile to improve usability, maintainability, and cross-platform compatibility. The changes modernize the Makefile structure and make it more user-friendly. Changes made: - Renamed the `it` target to `build` for better clarity and conventional naming. - Added a `help` target as the default goal to display available targets and their descriptions. - Moved the TEST variable to the top with other configuration variables for better organization. - Updated binary name from `lambda.exe` to `lambda` and used `${BINARY_NAME}` variable consistently throughout. - Replaced all `@` prefixes with the `.SILENT:` directive for cleaner syntax. - Added a `clean` target to remove all build artifacts (binary, program.out, profile directory). - Made the `graph` target cross-platform by replacing macOS-specific `open` command with file:// URL echo. - Updated .gitignore to include the `lambda` binary. ### Decisions - Used `.SILENT:` directive instead of individual `@` prefixes for a cleaner, more maintainable Makefile. - Made `help` the default target so users can run `make` without arguments to see available commands. - Removed platform-specific commands (like `open`) in favor of cross-platform alternatives. ## Benefits - Improved discoverability: Users can run `make` to see all available targets. - Better maintainability: Using `${BINARY_NAME}` variable consistently makes future changes easier. - Cross-platform compatibility: Removed macOS-specific commands. - Cleaner syntax: `.SILENT:` directive eliminates repetitive `@` prefixes. - More conventional: Renamed `it` to `build` follows standard Makefile conventions. ## Checklist - [x] Code follows conventional commit format. - [x] Branch follows naming convention (\`/\`). Always use underscores. - [x] Tests pass (if applicable). - [x] Documentation updated (if applicable). Reviewed-on: https://git.maximhutz.com/mvhutz/lambda/pulls/11 Co-authored-by: M.V. Hutz Co-committed-by: M.V. Hutz --- .gitignore | 1 + Makefile | 54 +++++++++++++++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 71b2ceb..0b209db 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore # # Binaries for programs and plugins +lambda *.exe *.exe~ *.dll diff --git a/Makefile b/Makefile index fa74ef9..45742d2 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,43 @@ -BINARY_NAME=lambda.exe - -.PHONY: it run profile explain graph docs - -it: - @ go build -o ${BINARY_NAME} ./cmd/lambda - @ chmod +x ${BINARY_NAME} - +BINARY_NAME=lambda TEST=simple -run: it - @ ./lambda.exe - < ./samples/$(TEST).txt > program.out +.PHONY: help build run profile explain graph docs clean +.DEFAULT_GOAL := help +.SILENT: -profile: it - @ ./lambda.exe -p profile/cpu.prof - < ./samples/$(TEST).txt > program.out +help: + echo "Available targets:" + echo " build - Build the lambda executable" + echo " run - Build and run the lambda interpreter (use TEST= to specify sample)" + echo " profile - Build and run with CPU profiling enabled" + echo " explain - Build and run with explanation mode and profiling" + echo " graph - Generate and open CPU profile visualization" + echo " docs - Start local godoc server on port 6060" + echo " clean - Remove all build artifacts" -explain: it - @ ./lambda.exe -x -p profile/cpu.prof - < ./samples/$(TEST).txt > program.out +build: + go build -o ${BINARY_NAME} ./cmd/lambda + chmod +x ${BINARY_NAME} + +run: build + ./${BINARY_NAME} - < ./samples/$(TEST).txt > program.out + +profile: build + ./${BINARY_NAME} -p profile/cpu.prof - < ./samples/$(TEST).txt > program.out + +explain: build + ./${BINARY_NAME} -x -p profile/cpu.prof - < ./samples/$(TEST).txt > program.out graph: - @ go tool pprof -raw -output=profile/cpu.raw profile/cpu.prof - @ go tool pprof -svg profile/cpu.prof > profile/cpu.svg - @ open profile/cpu.svg + go tool pprof -raw -output=profile/cpu.raw profile/cpu.prof + go tool pprof -svg profile/cpu.prof > profile/cpu.svg + echo ">>> View at 'file://$(PWD)/profile/cpu.svg'" docs: - @ echo ">>> View at 'http://localhost:6060/pkg/git.maximhutz.com/max/lambda/'" - @ go run golang.org/x/tools/cmd/godoc@latest -http=:6060 + echo ">>> View at 'http://localhost:6060/pkg/git.maximhutz.com/max/lambda/'" + go run golang.org/x/tools/cmd/godoc@latest -http=:6060 + +clean: + rm -f ${BINARY_NAME} + rm -f program.out + rm -rf profile/