GNU Make and gmake

The dependency-graph and timestamp model that still underlies almost every C and C++ build, plus the rules, automatic variables, parallelism hazards, and debugging flags an interviewer expects you to know cold.

Overview

Fifty years old and still the substrate

make is still the substrate under most C and C++ builds. GNU Make is the dialect everyone means (called gmake on the BSDs and Solaris, where make is a different, weaker program). Version 4.4.1 is the current documented edition, and the pattern rules, functions and jobserver real builds depend on are GNU extensions, not POSIX make.

Everything make does comes down to one check, made for every target in the graph.

Key concepts

  • Rule
  • Automatic variables
  • Order-only prerequisite
  • Variable flavor
  • .PHONY
  • .DELETE_ON_ERROR
  • Generated dependencies (-MMD -MP)
  • Jobserver

Interview questions

  • Explain exactly how make decides to rebuild, and where that model breaks down.
  • Write a pattern rule for compiling C++ with automatic header dependencies, and explain every piece.
  • What breaks when you switch from make to make -j, and how do you find it?
  • Explain variable flavors in make and give a case where recursive expansion causes a real problem.
  • What is the argument in "Recursive Make Considered Harmful", and what does the non-recursive alternative look like?
  • A build rebuilds everything on every invocation even with no source changes. How do you debug it?

Sign up free to read the full topic

More DevOps topics

Start free on Cariara · Coding problems · System design studio