help-make
[Top][All Lists]
Advanced

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

RE: another really dumb question


From: Paul Smith
Subject: RE: another really dumb question
Date: Thu, 20 Jan 2011 09:23:13 -0500

On Thu, 2011-01-20 at 03:15 -0800, Mark Galeck (CW) wrote:
> When I do
> 
> define FOOBAR
> FOO := bar
> $(info $(FOO))
> endef
> 
> $(eval $(call FOOBAR))
> 
> what I thought was going to happen, is, 
> 1. eval expands $(call), then
> 
> 2.
> FOO :=bar
> $(info $(FOO))
> 
> is parsed. When that happens, the result is first
> $(info bar)
> and then this is parsed and the result is nothing as syntax, but "bar"
> printed to stdout
> 
> and that should be it.  Where am I going wrong here?

Because you are not considering carefully the consequences of your "step
1".  Make (not eval) expands the call function.  That expansion will
expand the value of the variable.  The results of that expansion are
given to eval.  So you have to escape the contents of the variable from
the first expansion (by call) so it will live to be expanded in the
second expansion (by eval).

It goes like this (taking just the info line):

FOOBAR = $(info $(FOO))
$(eval $(call FOOBAR))

We expand the inner call function first, which is here equivalent to
just $(FOOBAR).  This results in the info function being invoked and the
result of that expansion is the empty string:

$(eval )

Now we eval that and do nothing.

Here, of course, where your "function" takes no arguments (has no
reference to $1, $2, etc.) the $(call ...) function is completely
unnecessary.  You could equivalently write:

$(eval $(FOOBAR))

That might easier for you to see what happens: $(FOOBAR) is expanded
(running the info function) then the results of that are given to eval.

In this particular case (obviously this is a corner case and almost any
real-world use of these capabilities would be too complex to allow this)
you can use:

$(eval $(value FOOBAR))

to get what you want without escaping the info function.

The problems with this in more complex situations is left as a
exercise... if you understand that then you're well on your way to
figuring out eval/call/etc.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.net
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

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