Core GNU Make concepts, syntax, and best practices for writing effective Makefiles
Instructions for writing and reviewing GNU Make Makefiles following best practices.
Use this skill when:
make resolves targetsAlways declare phony targets to avoid conflicts with files of the same name:
.PHONY: build test clean help
Set a sensible default goal (usually all or help):
.DEFAULT_GOAL := help
Use SHELL := /bin/bash at the top to ensure consistent shell behaviour.
Group variables at the top, targets in logical sections below.
?= for overridable defaults (caller can override via environment or CLI).:= for immediate (simple) expansion to avoid repeated evaluation.= only when deferred (recursive) expansion is intentional.@ to suppress echoing, or omit @ when the command itself is informative.$(MAKE) (not make) to invoke sub-makes so flags and variables propagate.Add ## comment after each target declaration and generate a help screen:
.PHONY: help