首页 > 解决方案 > 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例如,如果我想构建,则找不到配方。我该如何解决?

标签: makefilegnu-make

解决方案


您的问题来自调用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)foreachcall


推荐阅读