On Mon, Nov 14, 2011 at 1:29 PM, Philip Guenther <guent...@gmail.com> wrote: > On Mon, Nov 14, 2011 at 4:39 PM, Marc Smith <marc.sm...@mcc.edu> 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 > >
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-- [marc.smith@catskill testing]$ cat Makefile blah = $$(date) all: @ echo $(blah) @ sleep 10 @ echo $(blah) --snip-- --snip-- [marc.smith@catskill 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 > _______________________________________________ Help-make mailing list Help-make@gnu.org https://lists.gnu.org/mailman/listinfo/help-make