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