GNU Make
Purpose
Guide agents through idiomatic Makefile patterns for C/C++ projects: phony targets, pattern rules, automatic dependency generation, and common build idioms.
Triggers
- "How do I write a Makefile for my C project?"
- "My Makefile rebuilds everything every time"
- "How do I add dependency tracking to Make?"
- "What does
$@,$<,$^mean?" - "I'm getting 'make: Nothing to be done for all'"
- "How do I convert my shell compile script to a Makefile?"
Workflow
1. Minimal correct Makefile for C
Automatic variables:
$@— target name$<— first prerequisite$^— all prerequisites (deduplicated)$*— stem (the%part in a pattern rule)$(@D)— directory part of$@
2. Automatic dependency generation
Without this, changing a header doesn't trigger a rebuild of .c files that include it.
3. Pattern rules cheatsheet
4. Common Make patterns
Debug and release builds
Usage: make BUILD=debug
Parallel builds
Add -Otarget (or -O) for ordered output: make -j$(nproc) -O
Verbose output
Override silence: make V=1 if you guard with $(V):
Installing
5. Multi-directory projects
For medium projects, avoid recursive make (fragile, slow). Use a flat Makefile that includes sub-makefiles:
6. Common errors
For a full variable and function reference, see references/cheatsheet.md [blocked].
Related skills
- Use
skills/build-systems/cmakefor CMake-based projects - Use
skills/build-systems/ninjafor Ninja as a make backend - Use
skills/compilers/gccfor CFLAGS details


