On Mon, Nov 14, 2011 at 2:51 PM, Paul Smith <psm...@gnu.org> wrote: > On Mon, 2011-11-14 at 14:43 -0500, Marc Smith wrote: >> 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'm not sure why that makes a difference. You're invoking a shell from > the $(shell ...) function... but you're already in a shell, in your > recipe line. Why do you need to use make's $(shell ...) function in > this case if you're already in a shell? > > If you use := then that's a good reason, but if you use "=" then you > might as well just invoke the command in the recipe shell rather than > using $(shell ...).
I guess for maintenance reasons -- storing a shell command in a variable makes it easier to take care of if that shell command ever changes; that way I won't have to update the same shell command in X places. I can just modify it in one spot. Using ":=" wouldn't work in this case since the same grep command is called multiple times in the recipe and the list it produces should/will be different each time. --Marc > > See below as well. > >> 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-- > > Just so you're clear, by doing this you're actually following Philip's > suggestion. > > The "$$(date)" is expanded to the string "$(date)" which is then passed > to the shell. > > POSIX shells support a syntax "$(command ...)" which is equivalent to > backticks (`command ...`). So it's the shell that's running date, not > make, and that's why you are getting the behavior you expect. > > The makefile above is EXACTLY equivalent to this: > > blah = `date` > all: > @ echo $(blah) > @ sleep 10 > @ echo $(blah) > > which is identical to: > > all: > @ echo `date` > @ sleep 10 > @ echo `date` > > which is exactly what Philip was suggesting: not using make's > $(shell ...) function at all and instead letting the shell invoke the > command for you. > > _______________________________________________ Help-make mailing list Help-make@gnu.org https://lists.gnu.org/mailman/listinfo/help-make