makefile 模式规则先决条件可以是模式规则吗?
Can a makefile Pattern Rule prerequisite be a Pattern Rule?
我有这个生成文件:
.PHONY: all
all: foo.o
makefile: ;
%.inc:
echo INC
touch $@
%.o: bar.inc
echo O
touch $@
%.o:
FAIL
我希望它使用第一个 %.o
规则,创建 bar.inc 作为先决条件,然后创建 foo.o。相反,它使用最后一条规则,我得到这个:
FAIL
make: FAIL: Command not found
make: *** [foo.o] Error 127
如果我将 %.inc
更改为 bar.inc
或将 %.o
更改为 foo.o
,它会正常工作。
documentation 表示
In order for the pattern rule to apply, its target pattern must match the file name under consideration and all of its prerequisites (after pattern substitution) must name files that exist or can be made.
模式规则%.inc
不算"can be made"吗?我正在使用 GNU Make 3.81。
您缺少的相关详细信息在 10.5.4 How Patterns Match 部分。
具体(强调我的):
A pattern rule can be used to build a given file only if there is a target pattern that matches the file name, and all prerequisites in that rule either exist or can be built. The rules you write take precedence over those that are built in. Note however, that a rule whose prerequisites actually exist or are mentioned always takes priority over a rule with prerequisites that must be made by chaining other implicit rules.
所以问题不是你的先决条件不能满足,而是因为你的其他规则 "wins".
之后 make 甚至没有尝试
MadScientist 在他的回答 .
中提供了一些额外的信息和细节
我有这个生成文件:
.PHONY: all
all: foo.o
makefile: ;
%.inc:
echo INC
touch $@
%.o: bar.inc
echo O
touch $@
%.o:
FAIL
我希望它使用第一个 %.o
规则,创建 bar.inc 作为先决条件,然后创建 foo.o。相反,它使用最后一条规则,我得到这个:
FAIL
make: FAIL: Command not found
make: *** [foo.o] Error 127
如果我将 %.inc
更改为 bar.inc
或将 %.o
更改为 foo.o
,它会正常工作。
documentation 表示
In order for the pattern rule to apply, its target pattern must match the file name under consideration and all of its prerequisites (after pattern substitution) must name files that exist or can be made.
模式规则%.inc
不算"can be made"吗?我正在使用 GNU Make 3.81。
您缺少的相关详细信息在 10.5.4 How Patterns Match 部分。
具体(强调我的):
A pattern rule can be used to build a given file only if there is a target pattern that matches the file name, and all prerequisites in that rule either exist or can be built. The rules you write take precedence over those that are built in. Note however, that a rule whose prerequisites actually exist or are mentioned always takes priority over a rule with prerequisites that must be made by chaining other implicit rules.
所以问题不是你的先决条件不能满足,而是因为你的其他规则 "wins".
之后 make 甚至没有尝试MadScientist 在他的回答