Make Commands

make commands cheatsheet.

Run targets, build in parallel, override variables and control rebuilds — the GNU Make commands you reach for. Tap to copy.

Running targets
makeRun the default (first) target in the Makefile
make <target>Run a specific named target
make -C <dir> <target>Change to a directory before running make
make allBuild the conventional "all" target
make cleanRemove build artifacts (conventional target)
make installInstall the built program (conventional target)
Flags
make -jRun recipes in parallel with unlimited jobs
make -j4Run up to 4 recipes in parallel
make -f <file>Use an alternate Makefile
make -nDry run — print commands without running them
make -BUnconditionally rebuild every target
make -kKeep going after a target fails
make -sSilent — don't echo recipe commands
make -iIgnore all errors in recipes
make --debugPrint debugging information while building
make -dPrint full (verbose) debug information
make -pPrint the rules and variables database
make -qQuestion mode — set exit status, run nothing
Variables
make VAR=value <target>Override a variable from the command line
make -eLet environment variables override the Makefile
Info & help
make --versionPrint the GNU Make version
make --helpList available command-line options
make --warn-undefined-variablesWarn when an undefined variable is referenced

What make actually does

Make is a build tool that decides what needs rebuilding and runs the commands to do it. You describe your project in a file called a Makefile: a set of targets (files or task names), the prerequisites each one depends on, and the recipe of shell commands that produces it. Run make and it walks that graph, comparing timestamps, and only rebuilds targets whose prerequisites are newer. That timestamp check is the whole point — on a big project make skips work that is already up to date instead of rebuilding everything.

Running targets

With no argument, make builds the first target in the Makefile — by convention that's usually all. To run a specific one, name it: make test, make clean, make install. These last few are conventions, not built-ins, but almost every project defines them. If your Makefile lives in a subdirectory, make -C <dir> <target> changes into that directory first, which is how recursive builds drive sub-projects.

Flags worth knowing

A handful of flags change make's behaviour dramatically. make -j (or -j4 to cap it) runs independent recipes in parallel and is the single easiest way to speed up a slow build. make -n is a dry run that prints the commands without executing them — invaluable for checking what a target would do. make -B forces a full rebuild when timestamps lie to you, and make -k keeps going after a failure so you see every error in one pass instead of one at a time.

Variables and debugging

You can override any Makefile variable from the command line by passing VAR=value before or after the target, which is how flags like make CFLAGS=-O2 get injected without editing the file. When a build misbehaves, make -p dumps the full rules-and-variables database so you can see exactly what make thinks is defined, and make -d traces every decision it makes. These pair naturally with the Git commands for version control and the Linux commands for everything around the build.

FAQ

What does make -j do?
make -j runs independent recipes in parallel. Add a number like -j4 to cap it at 4 concurrent jobs; a bare -j runs as many jobs as possible, which can speed up large builds dramatically.
How do I run a specific target?
Run make followed by the target name, for example make test or make clean. With no target given, make runs the first target defined in the Makefile.

More cheatsheets