你忘了保护变量和函数不受双重扩展的影响。双全
$
除了
$(1)
你应该看看你想要什么(除了第二个
$(info...)
这将产生比你期望的更多的产出)。
host> cat Makefile
TARGETS=foo bar
define GEN_HEADER_RULE
$(1)_INCS = $$(wildcard $(1)/*.h)
$$(info $$$$($(1)_INCS) is [$$($(1)_INCS)])
$$(info $$$$(wildcard $(1)/*) is: [$$(wildcard $(1)/*)])
endef
$(foreach t,$(TARGETS),$(eval $(call GEN_HEADER_RULE,$t)))
all:
@echo "DONE"
host> make
$(foo_INCS) is [foo/foo.h]
$(wildcard foo/*) is: [foo/foo.h]
$(bar_INCS) is [bar/bar.h]
$(wildcard bar/*) is: [bar/bar.h]
DONE
使用时
foreach-eval-call
请记住,第一个扩展是
eval-call
以及make在将结果解析为make语法时的第二个扩展。您经常需要避开第一个扩展(
$$
)有时甚至是第二个(
$$$$
)见
the GNU make manual
详细的解释。