makefile - Gnu make:来自subst的宏中的目标
问题描述
我想生成一个等效目标列表:
TARGETLIST = a b c d e f
define RULE
$(subst X,$(1),file_X.txt) $(subst X,$(1),otherfile_X.txt) &: # some dependency
# some commands
endef
$(foreach _t, $(TARGETLIST), $(eval $(call RULE, $(_t))))
这不符合我的要求:file_b.txt
例如,如果我想构建,则找不到配方。我该如何解决?
解决方案
您的问题来自调用foreach-eval-call
. 你需要加倍$
你的$(subst...
: $$(subst...
。但是为什么不简单地让call
你的替换呢?
TARGETLIST = a b c d e f
define RULE
file_$(1).txt otherfile_$(1).txt &: # some dependency
# some commands
endef
$(foreach _t,$(TARGETLIST),$(eval $(call RULE,$(_t))))
call
自动用循环的当前替换宏中的$(1)
出现。这就是为之而生的。RULE
$(_t)
foreach
call