Makefile Build Order Planner

make does not read a Makefile top to bottom: it starts at a goal, walks that target's prerequisites depth first from left to right, and runs a recipe only after everything it depends on is done. Paste a Makefile and name a goal to see that order, the pattern rules that fill in the gaps, and which names it will treat as files that already exist.

Makefile and goal

explicit rules, pattern rules, simple variables, .PHONY and .DEFAULT_GOAL; recipe lines start with a tab

leave it empty to use .DEFAULT_GOAL or the first target

Nothing is executed: the page reads the text and prints the order make would take. Commands that need the shell, such as git push, are only listed.

Build order

Recipes make would run, in order—

Steps
—
Commands
—
Assumed files
—
Deepest chain
—
—

Every target that gets built, in the order make reaches it; prerequisites without a rule are assumed files
#TargetKindRule lineNeeds first

Recipe commands as make -n would print them

      How the order is worked out

      1. Start at the goal. The goal is the target you name, otherwise .DEFAULT_GOAL, otherwise the first rule in the file whose target is not special (a name starting with a dot) and contains no %.
      2. Walk prerequisites depth first, left to right. For each target, make finishes its first prerequisite and everything below it before it looks at the second, and only then runs its own recipe. That post-order walk is the build order shown here.
      3. Build each target once. A target reached twice, as happens when several objects share a header, is built on its first visit only. The planner marks it done at that point and never repeats it.
      4. Fill gaps from pattern rules. A rule such as %.o: %.c supplies a recipe for main.o by matching the stem main and substituting it into the prerequisites, which is why main.c is required without being named anywhere.
      5. Treat unknown prerequisites as files. A prerequisite with no rule of its own is assumed to exist on disk, exactly as make assumes it. This page cannot see your filesystem, so those names are listed separately as assumed files rather than silently dropped.
      6. Refuse a cycle. If following prerequisites leads back to a target already on the current path, no build order exists; the planner names the loop and stops. make itself would warn and drop one prerequisite, which quietly builds something other than what the file describes.
      7. Read rule lines early, recipes late. Targets and prerequisites are expanded when the line is read, so a variable reassigned further down does not change an earlier rule. Recipes are expanded at run time by make, so the commands here use the values your variables hold at the end of the file.

      What is not modelled. Conditionals (ifeq, ifdef) are not evaluated: every branch is read, which can add rules and recipes make would skip. included files are not followed, $(shell …), $(wildcard …), $(call …) and other functions are left as written and reported in the notes, automatic variables such as $@ and $< keep their names, an undefined variable expands to nothing as it does in make and is reported in the notes, target-specific variables and suffix rules are ignored, and a target whose prerequisites cannot be known without the filesystem is treated as a file that already exists. Timestamps, incremental rebuilds, parallel jobs and make -j ordering are outside the question: this is dependency order, not what would be out of date.