|
From: | Chen Jun (陈军) |
Subject: | Re: (solved)Can I defer make-var expansion until a command is executed |
Date: | Tue, 05 Aug 2008 08:37:13 +0800 |
User-agent: | Thunderbird 2.0.0.16 (Windows/20080708) |
Brian Dessent wrote:
Well Brian, in theory you're correct -- by using shell commands. But there is another important factor that matters: "user convenience". Sometimes, using make's internal functions to do some process is more convenient than shell commands, imaging make provide some great functions like $(patsubst ), $(foreach ) etc. Using shell functions may some other times be more powerful, but consider running GNU make on M$ Windows, I'd like to avoid shell commands if that can be processed by make functions.Chen Jun wrote:Well Brian, the example presented by me is just a fabricated one, not for my real world use. I use $(shell ) just to introduce a make variable or a make function so that my question becomes concrete. My real world case regarding this problem is quite a bit complex so I'd like not to talk about to it directly.Regardless, I think the same principle holds: if you need logic that considers factors that change during the execution of a recipe, then code that logic using the shell rather than make's functions. I can't think of a situation where this would not be possible; you can pass through to shell variables the contents of any makefile variables that might be required by that logic. And if all else fails there's always the universal hammer of recursively invoking a sub-make. Brian
Finally, I've come up with an solution to my example question, that is, using double colon rule:
======== IsFileExist = $(shell if [ -f $1 ]; then echo 1; fi ) outfile = out.txt$(outfile):: @echo "STRT: $@ $(if $(call IsFileExist,$@),exist,absent)"
@touch $@$(outfile):: @echo "DONE: $@ $(if $(call IsFileExist,$@),exist,absent)"
========And my real world problem can be solved with that method. Also thanks to the great foresight of GNU make. Although the make manual says "the cases where double-colon rules really make sense are those where the order of executing the commands would not matter", I found in my example it really make sense even if the execution order does matter.
chenjun.vcf
Description: Vcard
[Prev in Thread] | Current Thread | [Next in Thread] |