Tool cheatsheet
GNU Make 4 Cheatsheet
Write Makefiles with targets, variables, pattern rules and phony targets, and the options for running make.
Rules and targets
- Basic rule — A target, its prerequisites and a recipe. Recipe lines must begin with a tab, not spaces.
- Declare phony targets — Mark targets that are commands, not files, so a file with the same name doesn't stop them running.
- Set the default target — Run this target when you type make with no arguments.
- Write a clean target — Remove build outputs. The leading minus ignores errors, such as files that don't exist.
- Compile every source file — Build any .o file from the matching .c file. $< is the first prerequisite and $@ is the target.
- Hide commands from the output — Start a recipe line with @ so make doesn't print it.
- Run commands in one shell — Each recipe line runs in its own shell, so join commands with && or use a line continuation.
- Create a folder before building — An order-only prerequisite (after |) must exist but doesn't force a rebuild.
Variables and functions
- Define variables — = is evaluated when used, := is evaluated once when defined, and ?= sets a default.
- Automatic variables — $@ is the target, $< the first prerequisite, $^ all prerequisites.
- List files and change extensions — Find source files, then derive object file names from them.
- Run a command and capture its output — Store the output of a shell command in a variable.
- Use conditionals — Choose settings based on a variable.
- Include another makefile — Include shared rules. The leading minus ignores a missing file.
- Pass variables to commands — Export a variable to the environment of recipe commands.
- Self-documenting help — Print each target's ## comment. Run it with make help.
Running make
- Run a target — Run one specific target from the Makefile.
- Preview the commands — Print what would run without running it.
- Build in parallel — Run up to four jobs at once. Use $(nproc) for one per CPU core.
- Set a variable on the command line — Command-line variables override those in the Makefile.
- Force a rebuild — Rebuild everything even if files look up to date.
- Use another Makefile — Read a different file, or run in another directory.
- Continue after errors — Keep building independent targets after a failure.
- Print why targets are rebuilt — Show make's decisions, useful when a target rebuilds unexpectedly.
Related cheatsheets
- Ansible 2 cheatsheet — Run ad-hoc commands and playbooks, manage inventories, roles, collections and secrets with Ansible.
- Argo CD 3 cheatsheet — Install Argo CD, define Applications declaratively, and manage sync, diffs, history and rollbacks with the argocd CLI.
- AWS CLI 2 cheatsheet — Configure credentials and manage S3, EC2, Lambda, logs, containers and secrets with the AWS CLI v2.
- Azure CLI 2 cheatsheet — Sign in and manage resource groups, VMs, web apps, storage, Kubernetes, registries and secrets with the az command.
- Bash and Linux 5 cheatsheet — Everyday shell and Linux commands for files, searching text, permissions, processes and servers.
- Claude API cheatsheet — Call Claude from Python, TypeScript or curl: messages, streaming, thinking, tools, structured output, caching, batches and error handling.