On Fri, 2014-01-17 at 18:45 +0000, Doug Konrad wrote:
> I am having difficulty using eval and shell together. Here is my makefile:

The best way to debug eval issues is to replace the eval function with
info.  This will print out the content that make is parsing in the eval.
It's almost always quite obvious where the problem lies.

>      define aaa
>      $(1)_VAR1 = World
>      $(1)_VAR2 = $(shell echo Hello $($(1)_VAR1))
>      endef
> 
>      $(eval $(call aaa,DEMO))
> 
>      $(info $(DEMO_VAR1))
>      $(info $(DEMO_VAR2))
> 
> Output:
>      ~$ make
>      World
>      Hello
>      make: *** No targets.  Stop.
> 
> I would have thought the second line of output would have been:
>      Hello World
> 
> Why isn't it, and how can I fix the makefile so it is?

If you take my suggestion above, and add $(info $(call aaa,DEMO)) to
your makefile, you'll see this output:

    aaa_VAR1 = World
    aaa_VAR2 = Hello

Why?  Because the call function _expands its arguments_.  That means
that the shell function, etc. is evaluated by $(call ...), BEFORE the
eval even sees it.

For anything that you want to be expanded as part of the eval you have
to escape it, so the call doesn't see it.  Try:

     define aaa
     $(1)_VAR1 = World
     $(1)_VAR2 = $$(shell echo Hello $$($(1)_VAR1))
     endef

instead.  One rule of thumb for writing eval/call combinations might be
"every $ that is not representing a call variable ($1, $2, etc.) should
be escaped".  That's not necessarily always true, but it _usually_ does
what you want.


_______________________________________________
Help-make mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-make

Reply via email to