
Pick the Right Assignment in Make: =, :=, ?= and +=
Learn the difference between = and := in GNU Make, when ?= and += fit, and how a recursive variable can silently run a shell command many times.
Tag
7 posts

Learn the difference between = and := in GNU Make, when ?= and += fit, and how a recursive variable can silently run a shell command many times.

Declare clean, all and test as .PHONY so a file with the same name cannot stop them, and learn phony prerequisites, subdirectory loops and force rules.

Replace one rule per source file with a single %.o: %.c pattern rule, add automatic header dependencies with -MMD, and know when make's built-in rule is enough.

What $@, $<, $^ and $? mean inside a make recipe, with a Makefile that uses each one and the mistakes that make $< and $^ behave unexpectedly.

What a make rule is made of: the target, its prerequisites and the recipe, how make walks the dependency graph and decides what is out of date.

Write a working Makefile for a small C program with a compiler variable, flags, object files and a clean target, and see how make decides what to rebuild.

A complete guide to GNU Make for C: rules, variables, pattern rules, header dependencies, build directories, parallel builds, libraries and debugging.