Make
More generally, see Build systems.
Snippets
Adding a suffix to a list of files
BINS := $(SRC:=.bin)
Depending on the Makefile
# All rules should depend on the Makefile itself
THIS = $(abspath $(lastword $(MAKEFILE_LIST)))
Listing (phony) targets
See above for $(THIS).
.PHONY: help
help:
@printf 'Targets:\n'
@grep '^\.PHONY: ' $(THIS) | cut -d ' ' -f2
Setting the shell
SHELL = bash
.SHELLFLAGS = -euo pipefail
Useful functions
addprefixaddsuffixdir: Like Bash’sdirnamenotdir: Like Bash’sbasenamesubst
Automatic variables
$@
Q. In GNU Make, what does the $@ variable denote?
A. The target.
$<
Q. In GNU Make, what does the $< variable denote?
A. The first prerequisite.
$?
Q. In GNU Make, what does the $? variable denote?
A. All prerequisites that are newer than the target.
$^
Q. In GNU Make, what does the $^ variable denote?
A. All the prerequisites.