Makefile explainer
Paste a GNU Makefile and a list of files with their times: see what make -n would run and why, in order, with the recipes expanded; a dependency graph where you can touch a file; every rule and variable explained; and lints for missing .PHONY, spaces instead of tabs, $VAR in recipes and recursive-make pitfalls.
Added
How to use it
A Makefile is a small program, and like any program it is easier to understand when you can run it and poke at it. This page reads the Makefile the way GNU make does and tells you what it would do — without running anything.
How to use it
Paste a Makefile (or open one, or pick an example) and list the files that exist with their
modification times: a bigger number is newer. Choose a goal and, if you like, command-line
variables (CFLAGS=-O3) and -r.
-
What runs — the output of
make -nfor that goal, then each target that would be remade, in order, with the reason (it doesn’t exist, it is.PHONY, these prerequisites are newer), the recipe lines after expansion, and the automatic variables$@ $< $^ $? $* $|. -
Graph — the dependency graph for the goal, prerequisites on the left. Rebuilt targets are highlighted; order-only prerequisites are dashed. Click any box to
touchthat file and see the rebuild ripple through. The file list does the same: touch makes a file the newest, × deletes it. -
Rules — each explicit rule explained (prerequisites, order-only prerequisites, static pattern stems, double-colon rules, target-specific variables), your pattern rules, and the built-in rules make falls back on.
-
Variables — every variable with its flavour (
=recursive or:=simple), its origin (file, command line, override), what was written and what it expands to now; target- and pattern-specific variables; and a box to expand any text. -
Lints — what make itself stops on (
missing separator (did you mean TAB instead of 8 spaces?), recipe before the first target, unclosedifeq), and the mistakes it doesn’t catch: task targets likecleanortestwithout.PHONY,makeinstead of$(MAKE)and the costs of recursive make,cdon a line of its own,$HOMEmeaning$(H)OME,=with$(shell), overridden recipes and variables used but never set.
What is supported: logical lines and continuations, comments, ifeq/ifneq/ifdef/ifndef
with else if…, include and -include (paste the files), define/endef, =, :=, ::=,
:::=, ?=, +=, !=, override, export, undefine, target- and pattern-specific variables
(inherited by prerequisites, private respected), explicit, pattern, static pattern, suffix and
double-colon rules, order-only prerequisites, .PHONY, .DEFAULT_GOAL, chained implicit rules
with intermediate files, substitution references, $(@D) and friends, and the functions
subst patsubst strip findstring filter filter-out sort word wordlist words firstword lastword dir
notdir suffix basename addsuffix addprefix join wildcard abspath realpath if or and intcmp foreach
let call value origin flavor eval info warning error shell.
$(shell …) never runs: common commands (uname, git describe, git rev-parse, date,
nproc, find, ls) get a plausible stand-in computed from the file list, others expand to
nothing, and the page lists every call. vpath, .SECONDEXPANSION, archive members and -j
scheduling are not modelled.
Checked against GNU make
I wrote 9 Makefiles with 29 scenarios (a C project with a build directory, the variable and
function tour, static pattern and double-colon rules, built-in rules only, include with
command-line variables, define/call/eval templates, chained rules that delete an
intermediate file, and broken files), created the files with those modification times and
recorded make -n from GNU make 4.4.1. The page’s output matches it line for line, including
"Nothing to be done for" and "is up to date". macOS ships GNU make 3.81 as /usr/bin/make; I used
Homebrew’s gmake 4.4.1, whose behaviour is what this page follows. The built-in rules and
variables are the ones gmake -p prints, except that CXX is g++ as on Linux.
Privacy
Everything happens in this page; nothing is uploaded or run. The Makefile, included files and the file list are kept in this browser’s local storage. Share link puts them in the link.
Related: GitHub Actions workflow explainer, bash explainer for the recipe lines, dependency tree viewer, diagrams.
Feedback is a gift. Something to improve, a feature to add, or a bug? Tell me.
Runs entirely in your browser; nothing you type leaves this page.