0
votes

(Note -- this is similar to my previous question, but it seems to have a different cause, so I'm posting a new question here).

I'm debugging some makefiles which are littered with some very convoluted eval's. I'd like to be able to accurately dump what the eval's are expanding to, and then call the evals. I need to do this such that I can easily turn on/off the debugging, but I'm finding some odd behaviour with eval from within a function. I have:

FOO := a:=foo
$(eval $(FOO))
$(info a=$(a))   #a=foo -- OK

define eval_dbg
$(info eval_dbg: running [$1]) # $1 is "a:=bar"
$(eval $(1))                   # fails - missing seperator...
endef

$(call eval_dbg,a:=bar)    #causes error...
$(info a=$a)

But, I get:

a=foo
eval_dbg: running [a:=bar]
test2.mk:17: *** missing separator.  Stop.

Is it possible to eval a call parameter?


** minimal reproducable example: **

tmp> more test3.mk
FOO := a:=foo
$(eval $(FOO))
$(info a=$(a))

define eval_dbg
$(info eval_dbg: running [$1])
$(eval $(1))
endef

$(call eval_dbg,a:=bar)
$(info a=$a)

all:
        @echo running $@

tmp> make -f test3.mk
a=foo
eval_dbg: running [a:=bar]
test3.mk:10: *** missing separator.  Stop.

tmp> make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-unknown-linux-gnu
2
How are you stuck with 3.81? Maybe we can help with this - I don't know why 3.81 is still so popular, its incompatibilities come up every 3 weeks or so. - Vroomfondel

2 Answers

1
votes

The problem is due to comments inside "define".

Basically, "define" is the same as variable assignment (except newlines). "Call" does expansion, but not evaluation. Hence the comments got into stream without being evaluated --> error occurs!

So the moral:

  1. Define is not a macro; it's a string
  2. Call is not an evaluation; it's an expansion
  3. Comments are not whitespace; they are evaluated

UPD. As it turns out another problem is an old make version. It looks that v3.81 cannot simply ignore whitespace, as modern make versions do.

An additional eval fixes this issue:

$(eval $(call eval_dbg,a:=bar))
0
votes

The problem is that the result of a call to eval(...) is the empty string, so in effect you are passing call an argument -- the defined function eval_dbg -- that contains whitespace, and call doesn't like whitespace.

define func_1
$(info hello)
endef

$(call func_1) # this works                                                     

define func_2
$(info hello)

endef

$(call func_2) # this fails 

define func_3
$(info hello)
$(eval a:=b)
endef

$(call func_3) # this also fails

But there's no reason to call eval from within the function. As you've shown, you can print the statement and then call eval on it. Or you can pass eval the result of a call to call:

define foo_double
$(1):=foo_$(1)$(1)
endef

$(info $(call foo_double,a))
$(eval $(call foo_double,a))

$(info a is $a)