2013-06-20 00:00:00 -0700

Makefile Refresher


A good plan violently executed now is better than a perfect plan executed next week.

George S. Patton

Makefiles Skeletons

Makefile Papers

Recursive Make Considered Harmful

Makefile Utility Functions

$(subst from,to,text) and $(patsubst pattern,replacement,text)

replace from/pattern with to/replacement in text patsubst looks for whitespace separated words in text which matches pattern. There is an escapable wildcard character ’%’, which matches any number of characters in a word. If ‘%” is also present in the replacement, it will replace the first occurence of from in a word with replacement. Otherwise, it replaces the entire word if the pattern matches a part of a word. subst replaces every occurence of from with to in text

$(subst .c, .o, text) is therefore equilavent with $(patsubst %.c, %.o, text)

$(wildcard pattern)

returns a space separated list of all files which match the pattern

$(dir names) and $(notdir names)

returns a space separated list of either directory portion or the file portion of a space separated list of file paths

$(call name, param1, param2, …)

create new function $(name param1 param2 …)

Makefile Macros

$@

name of the current target

foo: foo.c
	gcc foo.c -o $@
bar: bar.c
	gcc bar.c -o $@

will produce foo.o and bar.o respectively

$?

all dependencies more recent than the target


comments powered by Disqus