Self-Documenting Makefile Pattern
Intermediatev1.0.0
Create self-documenting Makefiles with auto-generated help targets — every target gets a description, and 'make help' displays all available commands with explanations.
Content
Overview
A self-documenting Makefile includes a help target that automatically lists all available targets with descriptions. Developers type make help (or just make) to see what's available — no readme needed.
Why This Matters
- -Discoverability — new developers find all commands instantly
- -Up-to-date docs — descriptions live next to the targets
- -Onboarding —
make helpis the first command to run - -No guessing — every target's purpose is clear
How It Works
The Pattern
Output
Grouped Help (Advanced)
Best Practices
- -Set .DEFAULT_GOAL to help — bare
makeshows available commands - -Comment format: `## Description` after target name and colon
- -Every .PHONY target gets a description — no undocumented targets
- -Group related targets with prefixed descriptions for large Makefiles
- -Keep descriptions under 60 characters for clean alignment
Common Mistakes
- -No help target (developers guess at available commands)
- -Descriptions that duplicate the target name ("build: Build")
- -Help target not set as default goal
- -Using # instead of ## (help grep misses single-# comments)
FAQ
Discussion
Loading comments...