将Makefile匹配任何规则作为中间规则
考虑这个简单的Makefile:将Makefile匹配任何规则作为中间规则,makefile,gnu,Makefile,Gnu,考虑这个简单的Makefile: %.one: %.two echo one %.two: %.three echo two %.three: %.four echo three all: hi.one 正如预期的那样,make all将产生: echo three three echo two two echo one one 但是如果我制定了一个没有任何前缀/后缀的中间规则: %.one: % echo one %: %.three echo o
%.one: %.two
echo one
%.two: %.three
echo two
%.three: %.four
echo three
all: hi.one
正如预期的那样,make all
将产生:
echo three
three
echo two
two
echo one
one
但是如果我制定了一个没有任何前缀/后缀的中间规则:
%.one: %
echo one
%: %.three
echo one
%.three: %.four
echo one
all: hi.one
Make将失败,因为没有规则来生成
hi.one
。使用Make这是不可能的吗?不,这是不可能的,对于模式规则的依赖项,将忽略非终端匹配任何规则
手册中实际上没有提到这一点,但makesource()中的以下注释清楚地说明了这一点
/* Rules that can match any filename and are not terminal
are ignored if we're recursing, so that they cannot be
intermediate files. */
hi.four
存在吗?是的,它确实存在。这让我很难过。@CinoltYuklair你的例子没有理由使用匹配任何规则;几乎可以肯定的是,有一种更好的方法来处理您在这里真正想要完成的任何事情。Unix中的二进制文件没有任何前缀/后缀,因此当前目录中的二进制文件只需在模式规则中使用%
。@CinoltYuklair当然,但为什么二进制文件会成为模式规则的目标?%:%.o gcc-o$@$^