help-make
[Top][All Lists]
Advanced

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

Re: a really dumb question: why can't I eval just the recipe


From: Paul Smith
Subject: Re: a really dumb question: why can't I eval just the recipe
Date: Mon, 10 Jan 2011 20:24:15 -0500

(Mark, if you're going to be a regular around here it's probably a good
idea to subscribe to the list.  If you're not a subscriber then all your
email is held for moderation, and it could be hours, days, or even
longer before it's approved.)

On Mon, 2011-01-10 at 16:19 -0800, Mark Galeck (CW) wrote:
> I know this must be a dumb question...  In the manual, the example it
> gives for eval function, involves the multiline variable that is a
> whole rule.  Why can't I eval just the recipe?
> 
> Why doesn't this work:
> 
> EMPTY :=#
> TAB :=$(EMPTY)        #
> 
> FOOBAR := $(TAB)touch foobar#
> 
> .PHONY: foobar
> foobar:
> $(eval $(call FOOBAR))

Just like the shell, make itself has a defined order in which it parses
each line; that order goes only one direction (that is, once make has
decided that a line is or is not some type of syntax, it never goes back
and reconsiders that decision).

For make, one of the very first things it does is look for the recipe
prefix character (TAB by default).  If make is in a "rule context", and
the line begins with a TAB, it is considered a recipe line and added to
the existing recipe lines for the current rule and make is done with it.

If the line does not begin with the recipe prefix character (or make is
not in a rule context) then the line is not considered part of the
recipe, the previously-being-defined rule (if any) is marked as complete
and stored, and this line is considered to be some other type of make
syntax.

All this happens BEFORE make expands any variables that might appear on
the line because, if the line is a recipe, then make MUST NOT expand it
at all!  That's a fundamental fact of make; variables (and functions!)
in recipe lines are never expanded until (and only if) the target is
about to be built.

-- 
-------------------------------------------------------------------------------
 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]