Makefile 匹配任何规则作为中间

Makefile match anything rule as intermediate

考虑这个简单的 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

但是如果我制定一个没有任何中间规则 prefix/suffix:

%.one: %
    echo one
%: %.three
    echo one
%.three: %.four
    echo one

all: hi.one

Make 会失败,说没有规则可以制作 hi.one。这对 Make 来说是不可能的吗?

不,这是不可能的,对于模式规则的依赖性,将忽略非终结符匹配任何规则。

手册中实际上并未提及,但 make 源代码 (implicit.c:321) 中的以下注释清楚地表明了这一点

      /* Rules that can match any filename and are not terminal
         are ignored if we're recursing, so that they cannot be
         intermediate files.  */