makefile
This page contains notes on makefiles.
Pattern Rules
Since suffix rules have been deprecated, pattern rules should be used instead:
%.o : %.c
# rule defining how to make a file with .o suffix from a .c file
Automatic Variables
Below are a few automatic variables commonly used in makefiles. For others, check here before writing code to define your own.
$@ filename of the target of the rule
$< the name of the first prerequisite
$^ the name of all of the prerequisites with spaces between them
$* the stem with which the implicit rules matches
Intermediate Objects
make removes intermediate objects by default. To save them instead, add the line:
.PRECIOUS: %.o # example for .o suffix files
This stackoverflow thread presents several alternatives.
Example: Simple Makefile
This makefile converts markdown to html. Note that the intermediate file (suffix ihtml) will be automatically deleted by make.
# turn off implicit rules
.SUFFIXES:
# turn off deletion of intermediate files (see .PRECIOUS above)
.SECONDARY:
%.html: %.ihtml
tpage --define mdfile=$< main.tt > $@
%.ihtml: %.md
markdown $< > $@
clean:
rm -f *.ihtml *.html
Links
A helpful tutorial on makefiles. It has guidelines for conventions and automatically generating dependencies.