Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
744 views
in Technique[技术] by (71.8m points)

makefile - 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 example 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...