Gnu make:目标来自subst的宏
Gnu make: Target in macro from 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
自动将 RULE
宏中出现的 $(1)
替换为 foreach
循环的当前 $(_t)
。这就是 call
的用途。
我想生成等效目标列表:
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
自动将 RULE
宏中出现的 $(1)
替换为 foreach
循环的当前 $(_t)
。这就是 call
的用途。