当多个模式规则与目标匹配时 [英] when multiple pattern rules match a target
问题描述
一个以上的模式规则可能会满足这些条件.在这种情况下,make将选择词干最短的规则(即最匹配的模式).
It is possible that more than one pattern rule will meet these criteria. In that case, make will choose the rule with the shortest stem (that is, the pattern that matches most specifically).
所以我很惊讶:
$ touch make_specific.cpp
$ cat Makefile.general_first
%.o: %.cpp
@echo using general rule
$(CXX) -c $< -o $@
%_specific.o: %_specific.cpp
@echo using specific rule
$(CXX) -c $< -o $@
$ make -B -f Makefile.general_first make_specific.o
using general rule
g++44 -c make_specific.cpp -o make_specific.o
多个模式规则与目标匹配,并且由于%_specific.o : %_specific.cpp
规则的主干(在这种情况下为'make')比%.o : %.cpp
规则的主干短,因此我希望选择特定的规则,但是不是.
Multiple pattern rules match the target, and since the stem for the %_specific.o : %_specific.cpp
rule ('make' in this case) is shorter than the stem for the %.o : %.cpp
rule, I expected the specific rule to be selected, but it's not.
我想念什么?
推荐答案
您可能使用的版本低于3.82
.
You are probably using a make version lower than 3.82
.
在版本3.81
及更低版本中,选择标准不同; make
将选择与模式匹配的第一个规则.您引用的文档适用于版本3.82
.该版本会根据您的期望选择具有最特定词干的规则.
In version 3.81
and lower, the selection criterion was different; make
would choose the first rule that matched the pattern. The documentation you are referring to is for version 3.82
. That version does choose the rule with the most specific stem, which is according to your expectations.
从文件 NEWS
在make
源树中:
Version 3.82
...
* WARNING: Backward-incompatibility!
The pattern-specific variables and pattern rules are now applied in the
shortest stem first order instead of the definition order (variables
and rules with the same stem length are still applied in the definition
order). This produces the usually-desired behavior where more specific
patterns are preferred. To detect this feature search for 'shortest-stem'
in the .FEATURES special variable.
这篇关于当多个模式规则与目标匹配时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!