Makefile 先决条件中的多个词干 (%)

Multiple stems (%) in a Makefile prerequisite

我正在尝试使用以下 Makefile 创建目标 foo.a,以 foo.foo.b 作为先决条件,使用主干字符 (%),如图所示。

%.a: %.%.b
    touch $@

但是 运行 touch foo.foo.b; make foo.a 不适用于 No rule to make target。下面的调试输出显示词干 % 仅展开一次。如何获得替换先决条件中所有 % 的所需行为?

Considering target file 'sdf.a'.
 File 'sdf.a' does not exist.
 Looking for an implicit rule for 'sdf.a'.
 Trying implicit prerequisite 'sdf.%.b'.
 Looking for a rule with intermediate file 'sdf.%.b'.
  Avoiding implicit rule recursion.
  Trying pattern rule with stem 'sdf.%.b'.
  Trying implicit prerequisite 'sdf.%.b,v'.
  (..)
 No implicit rule found for 'sdf.a'.
 Finished prerequisites of target file 'sdf.a'.
Must remake target 'sdf.a'.
make: *** No rule to make target 'sdf.a'.  Stop.

旁注:这似乎是一个微不足道的问题,但出于某种原因我找不到答案,也许我使用了错误的搜索词或忽略了一些简单的东西,如果是这样的话,我很抱歉。

阀杆只更换一次。如果您希望多次插入词干内容,则需要使用 secondary expansion,即:

$ cat Makefile
.SECONDEXPANSION:

%.a: $$*.$$*.b
        echo Making $@ from $<

输出:

$ touch foo.foo.b
$ make -s foo.a
Making foo.a from foo.foo.b