Makefile Notes
Notes on using GNU Makefiles: hints, tips & tricks, and peculiarities.Whitespace
- Variable names All characters are valid except for the colon (
:
), pound sign
(#
), and equals sign (=
). Leading and trailing
whitespace is ignored. However, intermediate whitespace in a variable name
is allowed when using the define
directive or the loop variable
of the foreach
directive. For example:
define MY VAR
abcd,123
endef
...
all: ; echo $(MY VAR)
- Variable assignments
<var> = <value>
<var> := <value>
<var> ?= <value>
Whitespace between the equal sign ("=" or ":=") and <value> is ignored.
Whitespace trailing <value> is not ignored.
- Functions general
Whitespace between the function name and the first parameter is ignored.
addsuffix suffix, names...
Leading or trailing whitespace around names is ignored as is leading whitespace before suffix. However, trailing whitespace after suffix is reduced to one space after the entire expansion.
foreach var, list, commands
Words in list are stripped from leading and trailing whitespace when they are assigned to var.
subst from,to,text
All whitespace counts, except between subst and <from>.
sort list
Removes leading, trailing, and intermediate whitespace.
findstring find,in
Whitespace following find up until the comma is part of the search string. This means words in in have to be separated by this same amount of trailing whitespace else it won't match.
basename names...
Removes leading, trailing, and intermediate whitespace.
dir names...
Removes leading, trailing, and intermediate whitespace.
notdir names...
Removes leading, trailing, and intermediate whitespace.
if condition,then-part[,else-part]
Leading and trailing whitespace around
condition
is removed
before expansion.