Compare commits

10 Commits

Author SHA1 Message Date
M.V. Hutz
edfee89bad feat: explicitly set help as default target
Adds .DEFAULT_GOAL := help to make it clear that running 'make'
with no arguments will display the help message.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 16:38:37 -05:00
M.V. Hutz
b3db983f62 fix: add lambda binary to .gitignore
Adds the lambda binary to .gitignore to prevent accidentally
committing the build artifact. Previously only *.exe was ignored,
which didn't cover the Unix binary name.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 16:38:19 -05:00
M.V. Hutz
997794eaa5 docs: add documentation of Makefile improvements
Documents all issues found and fixes applied to the Makefile,
including both implemented changes and remaining suggestions.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 16:36:13 -05:00
M.V. Hutz
8f70bfbbdb refactor: use .SILENT directive instead of @ prefixes
Adds .SILENT directive to suppress command echoing for all targets,
replacing individual @ prefixes. Also moves TEST variable to top with
other variables for better organization.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 16:34:07 -05:00
M.V. Hutz
3158c35df2 fix: add profile dependency to graph target
Makes graph target depend on profile to ensure cpu.prof exists
before attempting to generate visualizations.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 16:29:25 -05:00
M.V. Hutz
bb48d0777b fix: ensure profile directory exists before writing
Creates profile directory in profile and explain targets to prevent
errors on first run.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 16:29:09 -05:00
M.V. Hutz
24fdc1c17c feat: add help target to document available commands
Adds help target that displays all available Make targets and their
descriptions, improving discoverability.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 16:28:48 -05:00
M.V. Hutz
7927df4660 feat: add clean target to remove build artifacts
Adds standard clean target to remove binary, output files, and
profile directory.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 16:28:29 -05:00
M.V. Hutz
e5ceeb2fcc feat: add .PHONY declarations for all targets
Declares all non-file targets as phony to prevent conflicts with
files of the same name and improve Make's performance.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 16:28:08 -05:00
M.V. Hutz
e0b0b92a8a refactor: remove redundant chmod +x command
Go build already sets the executable bit on binaries, making the
explicit chmod +x unnecessary.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 16:27:55 -05:00
3 changed files with 148 additions and 12 deletions

3
.gitignore vendored
View File

@@ -9,6 +9,9 @@
*.so *.so
*.dylib *.dylib
# Build artifacts
lambda
# Test binary, built with `go test -c` # Test binary, built with `go test -c`
*.test *.test

View File

@@ -1,21 +1,40 @@
BINARY_NAME=lambda BINARY_NAME=lambda
it:
@ go build -o ${BINARY_NAME} ./cmd/lambda
@ chmod +x ${BINARY_NAME}
TEST=simple TEST=simple
.DEFAULT_GOAL := help
.SILENT:
.PHONY: help it run profile explain graph clean
help:
echo "Available targets:"
echo " it - Build the lambda binary"
echo " run - Build and run with sample input (default: simple.txt)"
echo " profile - Build and run with CPU profiling enabled"
echo " explain - Run with explanation mode and profiling"
echo " graph - Generate CPU profile visualization"
echo " clean - Remove build artifacts"
echo ""
echo "Usage: make run TEST=<sample-name>"
it:
go build -o ${BINARY_NAME} ./cmd/lambda
run: it run: it
@ ./lambda - < ./samples/$(TEST).txt > program.out ./lambda - < ./samples/$(TEST).txt > program.out
profile: it profile: it
@ ./lambda -p profile/cpu.prof - < ./samples/$(TEST).txt > program.out mkdir -p profile
./lambda -p profile/cpu.prof - < ./samples/$(TEST).txt > program.out
explain: it explain: it
@ ./lambda -x -p profile/cpu.prof - < ./samples/$(TEST).txt > program.out mkdir -p profile
./lambda -x -p profile/cpu.prof - < ./samples/$(TEST).txt > program.out
graph: graph: profile
@ go tool pprof -raw -output=profile/cpu.raw profile/cpu.prof go tool pprof -raw -output=profile/cpu.raw profile/cpu.prof
@ go tool pprof -svg profile/cpu.prof > profile/cpu.svg go tool pprof -svg profile/cpu.prof > profile/cpu.svg
@ echo "Profile graph saved to 'file://profile/cpu.svg'" echo "Profile graph saved to 'file://profile/cpu.svg'"
clean:
rm -f ${BINARY_NAME} program.out
rm -rf profile/

114
makefile-improvements.md Normal file
View File

@@ -0,0 +1,114 @@
# Makefile Improvements
This document lists the issues identified in the original Makefile and the improvements that were implemented.
## Issues Fixed
### 1. Hardcoded `.exe` extension on Unix
**Problem**: `BINARY_NAME=lambda.exe` used a Windows extension on macOS/Linux systems.
**Solution**: Changed to `BINARY_NAME=lambda` since Unix executables don't use extensions.
**Commit**: `0d06fac` - fix: remove Windows .exe extension from binary name
---
### 2. Redundant `chmod +x`
**Problem**: The `chmod +x` command was unnecessary since `go build` already sets the executable bit.
**Solution**: Removed the redundant `chmod +x ${BINARY_NAME}` line.
**Commit**: `e0b0b92` - refactor: remove redundant chmod +x command
---
### 3. Missing `.PHONY` declarations
**Problem**: Without `.PHONY`, if files named `run`, `graph`, etc. existed, Make would skip those targets.
**Solution**: Added `.PHONY: help it run profile explain graph clean` declaration.
**Commit**: `e5ceeb2` - feat: add .PHONY declarations for all targets
---
### 4. No `clean` target
**Problem**: No standard way to remove build artifacts.
**Solution**: Added `clean` target to remove binary, output files, and profile directory:
```makefile
clean:
rm -f ${BINARY_NAME} program.out
rm -rf profile/
```
**Commit**: `7927df4` - feat: add clean target to remove build artifacts
---
### 5. Missing `help` or default target
**Problem**: Running `make` with no arguments was unclear about available targets.
**Solution**: Added `help` target documenting all available commands and their usage.
**Commit**: `24fdc1c` - feat: add help target to document available commands
---
### 6. Profile directory not created
**Problem**: The `profile` and `explain` targets wrote to `profile/cpu.prof` but never created the directory, causing failures on first run.
**Solution**: Added `mkdir -p profile` to both `profile` and `explain` targets.
**Commit**: `bb48d07` - fix: ensure profile directory exists before writing
---
### 7. No dependency check on `graph`
**Problem**: The `graph` target assumed `profile/cpu.prof` exists but didn't depend on `profile`.
**Solution**: Changed `graph:` to `graph: profile` to ensure profiling runs first.
**Commit**: `3158c35` - fix: add profile dependency to graph target
---
### 8. Verbose command prefixes
**Problem**: Every command used `@` prefix individually to suppress output, cluttering the file.
**Solution**: Added `.SILENT:` directive at the top and removed all `@` prefixes. Also moved `TEST` variable to top with other variables.
**Commit**: `8f70bfb` - refactor: use .SILENT directive instead of @ prefixes
---
## Additional Suggestions (Not Yet Implemented)
### 9. Missing `lambda` binary in `.gitignore`
**Issue**: The `.gitignore` has `*.exe` but not the actual `lambda` binary name. Since we removed the `.exe` extension, the binary won't be ignored.
**Recommendation**: Add `lambda` to `.gitignore`:
```
# Build artifacts
lambda
```
---
### 10. No explicit default target
**Issue**: While `help` is currently the first target (and thus default), it's not explicitly declared.
**Recommendation**: Add `.DEFAULT_GOAL = help` at the top for clarity:
```makefile
BINARY_NAME=lambda
TEST=simple
.DEFAULT_GOAL := help
.SILENT:
.PHONY: help it run profile explain graph clean
```
---
## Summary
The Makefile has been significantly improved with better organization, proper dependency management, directory creation, helpful documentation, and cleaner syntax. The remaining suggestions are minor quality-of-life improvements that can be addressed as needed.