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 14:43:06 -0500

On Mon, Nov 14, 2011 at 1:29 PM, Philip Guenther <address@hidden> wrote:
> 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:
>       address@hidden ${start_time}
>       address@hidden 10
>       address@hidden
>
>

I was just using 'date' as an example; my real need involves grep'ing
files that are generated at the top of a recipe. Yes, I realize I
could just create another recipe and make it a prerequisite.

I also just found that this works as well:

--snip--
address@hidden testing]$ cat Makefile
blah = $$(date)

all:
        @ echo $(blah)
        @ sleep 10
        @ echo $(blah)
--snip--

--snip--
address@hidden testing]$ make
Mon Nov 14 14:41:47 EST 2011
Mon Nov 14 14:41:57 EST 2011
--snip--


Thanks again for the help!


--Marc


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