help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

$(eval ) and $(shell )


From: zoltan
Subject: $(eval ) and $(shell )
Date: Fri, 3 Jul 2009 14:55:53 +1000 (EST)

I have a problem with delaying the evaluation of variables.
The make in question is 3.81.

The much simplified issue is a makefile like this:

VAR = $(shell non-existent-command $@)

all:    foo

define myrule
$(1): Makefile
        @echo "rule entered"
        @echo "shell is <" $(VAR) ">"
        @echo "rule finished"
endef

$(eval $(call myrule,foo))

Note that the non-existent-command is chosen so that the error message
would indicate when it was called. Now running the above Makefile results:

make: non-existent-command: Command not found
rule entered
shell is < >
rule finished

Which is fine, $(VAR) and thus $(shell ) was evaluated when make called
myrule to generate the actual rule. It is mentioned in the info, together
with advice about escaping the $ or using $(value VAR).

However, changing $(VAR) to $$(VAR) generates the same result. Changing
$(shell ... ) to $$(shell ... ) in the definition of VAR is the same
again. Using $(value VAR) is the same again. Using double $ in both
or $$(shell ) and $(value VAR) results in:

rule entered
/bin/sh: shell: command not found
shell is < >
rule finished

suggesting that the word 'shell' was passed to sh as a command.

Could someone explain me the actual evaluation order of variables and
how $, $$, $(value ), $(eval ), $(call ) and $(shell ) operate?

Reading the info page of $(eval ) gave me the impression that it gets its
argument, evaluates it once then parses the resulting text as makfile
source (and interprets it). Obviously that's a rather naive assumption and
make is doing something more sophisticated. I'd appreciate if someone
could tell me what or at least directed me towards some docs (other than
the source of make).

Thanks,

Zoltan





reply via email to

[Prev in Thread] Current Thread [Next in Thread]