help-make
[Top][All Lists]
Advanced

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

Re: Missing Something Obvious


From: Paul Smith
Subject: Re: Missing Something Obvious
Date: Mon, 14 Nov 2011 11:26:59 -0500

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.

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]