Next: Secondary Expansion, Previous: How make
Reads a Makefile, Up: Writing Makefiles [Contents][Index]
GNU make
parses makefiles line-by-line. Parsing proceeds using
the following steps:
make
Reads a
Makefile).
An important consequence of this is that a macro can expand to an entire rule, if it is one line long. This will work:
myrule = target : ; echo built $(myrule)
However, this will not work because make
does not re-split lines
after it has expanded them:
define myrule target: echo built endef $(myrule)
The above makefile results in the definition of a target ‘target’
with prerequisites ‘echo’ and ‘built’, as if the makefile
contained target: echo built
, rather than a rule with a recipe.
Newlines still present in a line after expansion is complete are
ignored as normal whitespace.
In order to properly expand a multi-line macro you must use the
eval
function: this causes the make
parser to be run on
the results of the expanded macro (see The eval
Function).
Next: Secondary Expansion, Previous: How make
Reads a Makefile, Up: Writing Makefiles [Contents][Index]