On 8/21/2009 9:14 AM, Yuri Shtil wrote:
Philip Guenther wrote:
On Thursday, August 20, 2009, Yuri Shtil <[email protected]> wrote:
It look like the shell function is evaluated even though commented
out in the following code:
define FUNC
###FOO := $(shell sleep 10)
endef
all:
@echo DONE
$(eval $(call FUNC,$(platform)))
What's so surprising? The $(shell) is evaluated in the following too:
define FUNC
###FOO := $(shell sleep 10)
endef
all:
@echo DONE
noop =
$(noop $(call FUNC,$(platform)))
And ditto if you replace the last line with
$(noop $(FUNC))
In each case, FUNC has to be expanded to determine the argument to a
function. In your post, that function is $(eval), in mine it's
$(noop).
The argument to $(eval) is expanded TWICE: one before $(eval) 'starts'
and then once by $(eval). If you don't understand that and choose
when each variable should be expanded, the results will be fragile.
It may be subtle and only show up when you decide to reference both
normal and automatic variables or a variable that contains shell
commands using shell variables...which just means you're laying a trap
for a time when you've forgotten the details.
Philip Guenther
What is surprising is that a line segment starting with a hash sign
must be ignored up to the end of the line, this is the whole purpose
of having comments in the code.
You have to admit that Yuri has a valid point here. 99.9999 percent of
all developers know that a hash mark starts a comment, wherein the
following text is ignored until the next newline. .0001 percent of
developers have read the GNU make manual /closely enough/ to understand
that under certain conditions, a hash mark doesn't necessarily mean that
the following text is ignored till the next newline.
Cheers,
John
John
_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make