Chris Collins

Tools · dev

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 -n for 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 touch that 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, unclosed ifeq), and the mistakes it doesn’t catch: task targets like clean or test without .PHONY, make instead of $(MAKE) and the costs of recursive make, cd on a line of its own, $HOME meaning $(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.

Browser support

Any current browser. Nothing to install.

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.

Runs entirely in your browser; nothing you type leaves this page.