bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: $(eval) expansion within $(eval)


From: Philip Guenther
Subject: Re: $(eval) expansion within $(eval)
Date: Tue, 15 Apr 2008 21:25:09 -0600

On Tue, Apr 15, 2008 at 2:47 PM, Tony Strauss
<address@hidden> wrote:
> Calling $(eval) within $(eval) can lead to very unintuitive (at least to me
> :) behavior.  In particular, the inner $(eval) is expanded *and* executed
> during the expansion of the outer $(eval).

Right, because make needs to know what the inner $(eval) expands to so
that it knows what the outer $(eval) is getting as its argument.


> For instance (I've also attached
> this example, since my email client mangled the tabs in the code below):
>
> define func2
>   MY_FUNC2_VAR := $$(SOME_VALUE)
>   all::
>        @echo "Here2: $$(MY_FUNC2_VAR)"
> endef
>
> define func3
>   MY_FUNC3_VAR := $$(SOME_VALUE)
>   all::
>         @echo "Here3: $$(MY_FUNC2_VAR)"
> endef
>
> define func1
>   SOME_VALUE := 1
>   MY_FUNC1_VAR := $$(SOME_VALUE)
>   all::
>         @echo "Here1: $$(MY_FUNC1_VAR)"
>   $(eval $(call func2))
>   ifndef SOME_VALUE
>      $(eval $(call func3))
>   endif
> endef
>
> $(eval $(call func1))
> all::

Umm, why are you using $(call funcN)?  Since you're not passing any
arguments and they aren't recursive, that's the same as $(funcN).

(This appears to be a common misconception, that $(call) is needed
with $(eval).  It's not.)


> The execution of the inner $(eval)s before the execution of the outer
> $(eval) means that:
> 1.) SOME_VALUE is not defined when either func2 or func3 is executed.
> 2.) func3 is expanded and executed despite being within a conditional that
> never will be true.

Right.  If you don't want those effects, then don't use inner
$(eval)s!  If you leave out the $(eval)s and just reference $(func2)
and $(func3) inside the definition of func1, those issues don't arise:

define func1
  SOME_VALUE := 1
  MY_FUNC1_VAR := $$(SOME_VALUE)
  all::
        @echo "Here1: $$(MY_FUNC1_VAR)"
  $(func2)
  ifndef SOME_VALUE
     $(func3)
  endif
endef


$ make
Here1: 1
Here2: 1
$


Philip Guenther




reply via email to

[Prev in Thread] Current Thread [Next in Thread]