help-make
[Top][All Lists]
Advanced

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

Re: Missing Something Obvious


From: Marc Smith
Subject: Re: Missing Something Obvious
Date: Mon, 14 Nov 2011 13:27:12 -0500

Never mind, I get it. I re-read what you said the first time -- the
entire recipe is expanded before it starts going through it, so if I
used that variable in a different recipe then I would get my expected
results.

Thanks!


--Marc

On Mon, Nov 14, 2011 at 11:39 AM, Marc Smith <address@hidden> wrote:
> On Mon, Nov 14, 2011 at 11:26 AM, Paul Smith <address@hidden> wrote:
>> On Mon, 2011-11-14 at 11:17 -0500, Marc Smith wrote:
>>> Did that behavior change recently in GNU make?
>>
>> No.
>>
>>> I've been reading the O'Reilly book titled Managing Projects with GNU
>>> Make (3rd edition) and on page 70 it gives this example to highlight
>>> the difference between simple/recursive variables with the shell
>>> function:
>>>
>>> START_TIME := $(shell date)
>>> CURRENT_TIME = $(shell date)
>>> "The START_TIME variable causes the date command to execute once when
>>> the variable is defined. The CURRENT_TIME variable will reexecute date
>>> each time the variable is used in the makefile."
>>
>> Sure.  But that's at all the same thing as what you did.  What you did
>> is this:
>>
>>>> blah = $(shell date)
>>>> all:
>>>>         @ echo $(blah)
>>>>         @ sleep 10
>>>>         @ echo $(blah)
>>
>> In the O'Reilly book they are using first a simple variable which has
>> immediate expansion, so START_TIME is evaluated when the makefile is
>> read in, while END_TIME is a recursive variable and not evaluated until
>> the variable is used.
>>
>> Your example puts the variables in the same recipe twice.  You are
>> assuming that make will expand the first line of the recipe, run it,
>> expand the second line of the recipe, run that, then expand the third
>> line of the recipe and run that.
>
> Gotcha, I'm not trying to be difficult, just wrapping my head around this. =)
> So, something like this should yield different values:
>
> --snip--
> blah := $(shell date)
> blah2 = $(shell date)
>
> all:
>        @ echo $(blah)
>        @ sleep 10
>        @ echo $(blah2)
> --snip--
>
> Right?
>
> Is there another way to use the same variable and have the shell
> function execute each time the variable is used in a makefile?
>
> Thanks for your help.
>
>
> --Marc
>>
>> But that's not how GNU make works, nor has it ever worked that way.
>> Instead, make expands the first, second, and third lines at the same
>> time and then runs the first one, then the second, then the third in
>> order.
>>
>> --
>> -------------------------------------------------------------------------------
>>  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]