GNU make differences in multiline variable declarations
I read this question, and I was surprised it wasn't working:
Why GNU Make canned recipe doesn't work?
So I tried it myself and got the same results. Here's an exa开发者_JAVA技巧mple makefile:
define foo
bar
baz
endef
define bar =
foo
baz
endef
$(info foo: $(foo))
$(info bar: $(bar))
all:
And here's the output from running it:
$ make
foo: bar
baz
bar:
make: Nothing to be done for `all'.
What's happening here? The GNU make manual seems to indicate that these two variable declarations should be the same - what am I missing here?
Edit:
Some quotations from the manual that I was referring to:
3.7 How make Reads a Makefile
define immediate deferred endef define immediate = deferred endef
5.8 Defining Canned Recipes
Here is an example of defining a canned recipe:
define run-yacc = yacc $(firstword $^) mv y.tab.c $@ endef
6.8 Defining Multi-Line Variables
... You may omit the variable assignment operator if you prefer. If omitted, make assumes it to be ‘=’ and creates a recursively-expanded variable...
As you can see, the canned recipes section explicitly uses the =
case. I'm using GNU Make 3.81.
From the CHANGELOG in 3.82:
* read.c (do_define): Modify to allow assignment tokens (=, :=, etc.)
after a define, to create variables with those flavors.
It seems like using '=' isn't supported prior to that in define statements
It's probably your make
version. I tested that makefile on my machine using make 3.81 in Cygwin and got:
$ make
foo: bar
baz
bar:
make: Nothing to be done for `all'.
I tested the same makefile using make 3.82 (native Windows build) and got:
C:\>C:\make\make.exe
foo: bar
baz
bar: foo
baz
make: Nothing to be done for `all'.
I believe the online make
manual is for v3.82.
精彩评论