makefile - Multi-line define in GNU make -
i'm trying make sense out of multi-line define directive of gnu make , cannot. example:
define 1 2 endef all: @echo w=$(word 1,$(a)) running make produces result have expected least:
w=1 make: 2: command not found make: *** [all] error 127 it appears part of $(a) has spilled outside $(word) function.
is bug or intended behavior? if "spill" intentional, how works?
p.s. gnu make v3.81 on linux/x64
the $(word) function splitting on spaces. not whitespace, spaces.
there no spaces in a macro nothing gets split.
add trailing space on 1 line or leading space on 2 line , expected behaviour.
this consistent across gnu make 3.81, 3.82, 4.0, , 4.1 in quick testing here.
the reason see "spill" called because of how define expanded. expanded literally, newline , all. (think template expansion.)
so make expands define call $(word 1,...) expands result (the whole define including newline) recipe template , ends 2 lines executes recipe.
consider macro this:
define somecommands echo foo echo bar echo baz endef all: $(somecommands) what expect happen here? how many lines body of all? how many shells run here? commands executed? answer 3 lines, 3 shells , 3 echo commands.
if newlines weren't counted run echo foo echo bar echo baz in 1 command , foo echo bar echo baz output instead of expected (and far more useful) foo, bar, , baz on 3 different lines.
Comments
Post a Comment