GNU Make的多通配符模式规则 [英] multi-wildcard pattern rules of GNU Make
问题描述
我想写一些正则表达式:
I want to write something like regex:
SRC:="a.dat.1 a.dat.2"
$(SRC): %.dat.%: (\\1).rlt.(\\2)
dat2rlt $^ $@
,以便 a.dat.1 和 a.dat.2 分别为 a.rlt.1 和 a. rlt.2 .
在GNU Make信息页面中,显示%只能使用一次".
In GNU Make info page, it says "the % can be used only once".
在GNU Make中是否有一些技巧可以实现这一目标?
Is there some trick to achieve this in GNU Make?
推荐答案
恐怕您尝试执行的操作不可能像您建议的那样进行,因为-正如您已经提到的-(GNU)仅使允许单个词干%",请参见 http://www. gnu.org/software/make/manual/make.html#Pattern-Rules :
I'm afraid what you are trying to do is not possible the way you suggest to do it, since - as you already mention - (GNU) make only allows a single stem '%', see http://www.gnu.org/software/make/manual/make.html#Pattern-Rules:
模式规则看起来像一个普通规则,除了它的目标 包含字符%"(恰好是其中之一).
A pattern rule looks like an ordinary rule, except that its target contains the character ‘%’ (exactly one of them).
没有它,创建这样的多维"目标很麻烦.
Without it, creating such 'multi-dimensional' targets is cumbersome.
解决此问题的一种方法是通过在命令中(而不是在依赖项列表中)重建依赖项的名称:
One way around this is by rebuilding the name of the dependency in the command (rather than in the dependency list):
SRC := a.dat.1 a.dat.2
all : $(SRC:%=%.dat2rlt)
%.dat2rlt :
dat2rtl $(word 1,$(subst ., ,$*)).rlt.$(word 2,$(subst ., ,$*)) $*
但是,当然,通过这种方式,您将失去依赖关系,并且在rlt更新后将不会重建依赖关系.
Of course, however, this way you would lose the dependency, it will not rebuild once the rlt has been updated.
我看到的唯一解决方法是显式生成规则:
The only way I can see to address that is by generating the rules explicitly:
SRC := a.dat.1 a.dat.2
all : $(SRC)
define GEN_RULE
$1.dat.$2 : $1.rlt.$2
dat2rtl $$< $$@
endef
$(foreach src,$(SRC),$(eval $(call GEN_RULE,$(word 1,$(subst ., ,$(src))),$(word 3,$(subst ., ,$(src))))))
这篇关于GNU Make的多通配符模式规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!