Makefile Tips
Vince Buffalo edited this page Oct 15, 2013
·
6 revisions
Choose the available version of a program in $PATH
:
GZCAT := $(shell (command -v gzcat || command -v zcat) 2>/dev/null)
Things get a bit messy when directories are the names of targets, and when they are prerequisites. Directory timestamps change whenever the contents change, so directories as prerequisites would lead to the target being rebuilt if the prerequisite directory changes. One way around this is to use the automatic variable $(@D)
, which is the directory party of the prerequisite to create new directories. For example:
dir/target: perquisites
mkdir -p $(@D)
Also, order-only prerequisites can be used specified too, with |
:
dir/target: perquisites | dir
# stuff
dir:
mkdir -p dir/
This will create dir/
the first time, but the target dir/target
won't be updated when dir
's timestamp changes.