help-make
[Top][All Lists]
Advanced

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

Re: Missing Something Obvious


From: Philip Guenther
Subject: Re: Missing Something Obvious
Date: Mon, 14 Nov 2011 18:29:40 +0000

On Mon, Nov 14, 2011 at 4:39 PM, Marc Smith <address@hidden> wrote:
...
> 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?

No.  That will expand 'blah' immediately, then expand all the lines in
the rules for all (thus expanding 'blah2') then run those commands,
including the sleep.  So blah2 will *not* be expand after the sleep.

What I don't understand is why you're using $(shell) there.  What's so
hard about just running 'date' in the commands?  Capture the time of
the start of the reading of the makefile with an immediate shell
variable, then run date directly for the final time:

start_time := $(shell date)
all:
        @echo ${start_time}
        @sleep 10
        @date


> Is there another way to use the same variable and have the shell
> function execute each time the variable is used in a makefile?

No.  The commands in rules are run by the shell; use the shell!  Make
variables are not the only hammer in your toolbox, or shouldn't be.


Philip Guenther



reply via email to

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