[Top][All Lists]

[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 11:17:52 -0500

Did that behavior change recently in GNU make? 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."

That being said, although the book doesn't explicitly say it, I assume
CURRENT_TIME would give a different value (assuming there is enough
delay between when its used).

So, the way it works is not what I expected -- is there a different
method to get the results I'm looking for?


On Mon, Nov 14, 2011 at 10:17 AM, Paul Smith <address@hidden> wrote:
> On Mon, 2011-11-14 at 09:53 -0500, Marc Smith wrote:
>> I must be missing something obvious... I'm using the shell function in
>> my Makefile with a recursive variable, however, it seems the command
>> in my shell function is only being evaluated once. I've tried this on
>> two different Linux distributions and get the same result; from
>> everything I read (even in the O'Reilly GNU Make book), this should
>> not be working this way. See below for an example:
>> --snip--
>> address@hidden testing]$ cat Makefile
>> blah = $(shell date)
>> all:
>>         @ echo $(blah)
>>         @ sleep 10
>>         @ echo $(blah)
>> --snip--
> The behavior you're seeing is expected.
> GNU make IS evaluating that function twice.  However, make expands all
> the lines in a recipe before it invokes the first one.  It does not
> expand them one at a time, just before it invokes them.
> So even though make is running the "date" command twice, it's doing this
> one right after the other so they have the same result.
> --
> -------------------------------------------------------------------------------
>  Paul D. Smith <address@hidden>          Find some GNU make tips at:
>  "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]