invocation
# override variables
make CFLAGS='-g -O'
arguments
-B always make, force compiling of all targets
variables
CC = gcc will be expanded when it is used
CC := gcc will be expanded when it is set
CC ?= gcc will be set when it doesn't already have a value, may be overwritten by
any environment
CFLAGS += -ansi append
automatic variables
$@ file name of target
$* stem of matching, target: dir/a.foo.b, pattern: a.%.b, stem: dir/foo
$< name of first prerequisite
$? names of all the prerequisites that are newer than the target
$^ names of all the prerequisites, with spaces between them
$+ names of all the prerequisites, with spaces between them, with duplicates
- following two work with
<, ?, ... in place of @ as well:
$(@F) dir part of the file name of the target, without trailing slash
$(@D) file-within-directory part of the file name of the target
functions
sources := $(wildcard *.src)
targets := $(sources:.src=.trg)
filtered := $(filter-out broken.src, $(sources))
term_cols := $(shell tput cols)
special targets
.DELETE_ON_ERROR
.NOTPARALLEL affects all targets in file
.PHONY
.IGNORE old way to ignore errors in recipe
commands
- before command ignores its errors
@ don't display command
pattern
loops
subdirs := $(wildcard */)
.PHONY: all
all: $(subdirs)
.PHONY: $(subdirs)
$(subdirs):
$(MAKE) -C $@
conventions
variables
uppercase letters are traditional, however gnu recommends lowercase for internal
purposes and uppercase for variables that control implicit rules or parameters
intended to be overwritten by caller.
gnu standard targets
all
dist create distribution tar file
check run tests which require build but no installation
installcheck perform tests after install, don't assume $(bindir) is in path
install
install-strip strip removes information such as debugging symbols
uninstall
clean don't delete config files
distclean like a fresh checkout
mostlyclean like clean, but leave costly files
maintainer-clean distclean plus more: may need other tools to rebuild, not intended for normal users
html, pdf, install-html, install-pdf doc in other format than info