GNU Make Build Automation
Build, repair, or review a GNU Makefile with correct incremental rebuilds, generated prerequisites, and parallel-safe targets. Use when make rebuilds too much, misses a dependency, or fails under make -j.
Produce a Makefile whose dependency graph describes the files each recipe reads and writes. Verify clean, no-op, incremental and parallel builds before treating a passing serial run as sufficient. ## Key Points - [GNU Make prerequisite types](https://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html) - [GNU Make automatic prerequisites](https://www.gnu.org/software/make/manual/html_node/Automatic-Prerequisites.html) - [GNU Make grouped targets](https://www.gnu.org/software/make/manual/html_node/Multiple-Targets.html) - [GCC preprocessor dependency options](https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html)
skilldb get build-tools-skills/gnu-make-build-automationFull skill: 61 linesGNU Make Build Automation
Produce a Makefile whose dependency graph describes the files each recipe reads and writes. Verify clean, no-op, incremental and parallel builds before treating a passing serial run as sufficient.
Model files and actions
Start with the default deliverable, the actual tools used to make it and the inputs that can change it. Use one target per file or an explicit grouped target when a single invocation creates multiple files. Mark commands such as test and clean with .PHONY; avoid making a real output depend on a phony target when that would cause an unconditional rebuild. Put objects and generated files in a bounded, project-owned build directory. Check that any cleanup rule targets only that directory.
Use a normal prerequisite when a newer input invalidates an output. Use order-only prerequisites after | for directories or ordering that should not trigger rebuilds on timestamp changes. Tool or configuration changes still need a dependency, a per-configuration output directory, or another explicit invalidation strategy. Make does not generally rebuild because you changed a recipe or variable value alone.
For a GNU-compatible C compiler driver with the documented flags, adapt this pattern to the project's actual source layout:
CC ?= cc
OBJ := build/main.o build/parse.o
.PHONY: all
all: build/demo
build/demo: $(OBJ)
$(CC) $(LDFLAGS) -o "$@" $(OBJ) $(LDLIBS)
build/%.o: src/%.c | build
$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -MF "$(@:.o=.d)" -MT "$@" -c "$<" -o "$@"
build:
mkdir -p "$@"
-include $(OBJ:.o=.d)
The example recipes use tabs and a POSIX-style shell. Verify the shell and compiler used on each target host. The optional included dependency files allow the first build when they do not exist. If a header is generated before the first compile, add an explicit prerequisite; the dependency file cannot bootstrap a header that the compiler has not read.
Each dependency file in this example is a side effect of compiling its object. Deleting only a dependency file does not make its current object out of date. If one is missing, remove or force-rebuild its matching object before trusting incremental header checks. If the project needs automatic recovery of individually missing outputs, model the pair explicitly and test both deletion paths.
Eliminate parallel races
Every consumed generated file needs an edge to its producer. If one command emits a header and source together, verify support for GNU Make grouped targets (&:) or redesign the build so one declared step owns both outputs. Two independent rules running the same generator may race even if serial execution usually works. Use $(MAKE) for recursive sub-builds that are genuinely needed so GNU Make can propagate its flags and job coordination; avoid unmanaged parallel pools.
Make incomplete output visible as failure. Let recipe failures propagate. Where possible, generate or link through a temporary file and rename it only after the tool exits successfully. Review .DELETE_ON_ERROR for targets that would otherwise leave a changed, unusable artifact. Keep unrelated user files and source trees outside automatic cleanup.
Verify the graph against observable outputs
From a fresh build directory, run the normal target serially and in parallel. Compare the expected outputs and program result. Rerun with no changes and check that the expensive recipes do not execute. Change a shared header and verify all dependent objects rebuild. Change an unrelated file and confirm they do not. For grouped or otherwise explicitly modeled outputs, delete one and verify make recreates it without duplicate work. Run a failing recipe and check that stale or partial output is not reported as usable. Use GNU Make's diagnostic output and captured recipe invocations to identify the causal edge.
Record GNU Make version, compiler, shell, flags and observed commands. Treat a correct local fixture as evidence for its exact layout and host; separately test the user's generated sources and target platforms.
References and rights
- GNU Make prerequisite types
- GNU Make automatic prerequisites
- GNU Make grouped targets
- GCC preprocessor dependency options
Original SkillDB instructions under LicenseRef-SkillDB-Content. References were checked 2026-11-13 and used for technical verification.
Install this skill directly: skilldb add build-tools-skills
Related Skills
Rollup
Rollup configuration for building JavaScript libraries with tree shaking and multiple output formats
Swc
SWC compiler configuration for fast TypeScript and JavaScript transpilation and minification
Tsconfig
TypeScript compiler configuration, project references, and tsconfig best practices
Vite
Vite configuration, plugins, and dev server optimization for modern JavaScript projects
Webpack
Webpack 5 setup, optimization, code splitting, and plugin configuration for JavaScript applications
Biome
Biome linter, formatter, and code analysis configuration for JavaScript and TypeScript projects