The GNU make manual says
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).
So it surprised me that:
$ 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
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.
What am I missing?
You are probably using a make version lower than
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 version3.82
. That version does choose the rule with the most specific stem, which is according to your expectations.From the file
NEWS
in themake
source tree: