On Sun, 2021-01-17 at 17:43 -0800, Fangrui Song wrote: > % cat Makefile > .SUFFIXES: > %.o: %.c > touch $@ > %.o: %.d > touch $@
It might be more clear what was happening if you made the recipes for these two rules different in some way: %.o : %.c ; echo from .c > $@ %.o : %.d ; echo from .d > $@ > % rm -f a.o b.o; touch a.c b.d; make a.o b.o > removed 'a.o' > removed 'b.o' > touch a.o > touch b.o > > The behavior is similar to double-colon rules. No, not really; as Nick explains if it were similar to double-colon rules BOTH rules would be run for BOTH targets. > It can not be explained by > > > If more than one rule gives a recipe for the same file, make uses > > the ast one given and prints an error message. > > in > https://www.gnu.org/software/make/manual/html_node/Multiple-Rules.html That section deals only with _explicit_ rules. You are working with implicit (pattern) rules, which follow a completely different algorithm for matching; see here: https://www.gnu.org/software/make/manual/html_node/Pattern-Match.html If it helps you can think of explicit rules like classes in C++: there can be only one with that name. Pattern rules are like templates in C++: each template must be different (can't have exactly the same set of target and prerequisite patterns) but they can apply to a large number of different targets. The section above shows how make chooses which implicit rule (template) to apply in a given situation.
