質問

The Makefile:

define t1
a = $1
$(info  $(a) -- $(1))
endef

list = x y z

$(foreach  v,$(list),$(eval $(call t1,$(v))))

The output

 -- x
x -- y
y -- z

The problem is delaying of value of 'a' by one invocation. Even a := $1 shows the same issue.

Any quick fixes ?

This is gnu make 3.81 .

役に立ちましたか?

解決

This is one of the confusing things about using call and eval together: when to add extra quoting. The problem is that the call function is invoked first, and that will expand the argument once. Then eval is called and that evaluates its argument (the output from call).

In your example, the info function is being evaluated by call, the first time, and so in that situation a has not been set yet (because it's not set until the eval function runs). So you need to escape that function, and the expansion of a:

define t1
a = $1
$$(info $$(a) -- $(1))
endef
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top