The make utility automatically determines
which pieces of a large program need to be
recompiled, and issues commands to recompile
them.
There are several options that are generally useful with make:
target: [prerequisites]
- TAB - action
- TAB - action
- TAB - ...
Rules must consist of consecutive lines that start with a TAB character.
Since these are usually interpreted as shell commands, you can do things such as multi-lines (but use the backslash to make sure that the “single-linedness” of your construction is clear):
for name in dir1 dir2 dir3 \
do ; \
${MAKE} $name ; \
done
ifeq (ARG1,ARG2)
...
endif
ifdef (ARG1)
...
endif
You can use “=” and “?=” to set ordinary variables:
CFLAGS ?= -g -O3 # conditionally set ${CFLAGS} to ‘‘-g -O3’’ iff it is not already defined
CC = /usr/bin/gcc ${CFLAGS} # unconditionally set ${CC} to ‘‘/usr/bin/cc’’
One of the nice things that you can do with make is create “pattern rules”.
These are rules that let you abstract a pattern from a set of similar rules, and use that pattern in lieu of explicitly naming all of those rules.
For instance:
%.o : %.c
cc -c $< -o $@
# $@ refers to the target
# $< refers to the *first*
# (and only) prerequisite
$@ # the target of the rule
$< # the first prerequisite
$^ # all of the prerequisites
$? # all of the prerequisites that
# are newer than the target file
$* # the ‘‘stem’’ only; essentially,
# this is the complement of the static
# portion of the target definition
pandoc_options=--latexmathml --latex-engine=xelatex
targets = 1.html 1.pdf 2.html 2.pdf 3.html 3.pdf \
4.html 4.pdf 5.html 5.pdf 6.html 6.pdf \
14-programdev.html 14-programdev.pdf \
15-makefiles.html 15-makefiles.pdf
all : $(targets) $(pictures)
%.html : %.txt
pandoc $(pandoc_options) --ascii -t \
dzslides+pipe_tables -s $< -o $@
%.tex : %.txt
pandoc -t beamer --ascii -s $< -o $@
%.pdf : %.tex
pdflatex $<
%.png : %.dot
dot -Tpng $< > $@
It is common to such default targets such as: