Reputation: 3520
If I create an implicit rule with a prerequisite (but no recipe), then the dependency does not seem to be honored. If, on the other hand, I define the prerequisite in the block where I define the recipe, or if I specify a dependency of a particular instance of the target, it does seem to work. I have the following Makefile (GNU make 3.81)
all: foo.a foo.b bar.b bar.c
dep1:
@echo "running $@"
%.a: dep1
%.a:
@echo "running $@ (depends on: $^)"
bar.b: dep1
%.b: dep1
@echo "running $@ (depends on: $^)"
bar.c: dep1
bar.c:
@echo "running $@ (depends on: $^)"
If I run make, I get:
~/tmp/tmp5> make
running foo.a (depends on: )
running dep1
running foo.b (depends on: dep1)
running bar.b (depends on: dep1)
running bar.c (depends on: dep1)
It seems that even though I have %.a
depend on dep1
, that foo.a
can be built without dep1
being built. Is this a bug in make, or is there a reason for this behavior?
Thanks,
John
Upvotes: 3
Views: 1877
Reputation: 126203
Pattern rules with the same target don't get combined into a single rule like non-pattern rules do. When you have two non-pattern rules for the same target, they get combined into a single rule with all the dependencies of the two rules and the actions from the rule that has actions (and it is an error for both rules to have actions). With pattern rules, that does not happen -- they are treated as two completely independent rules, either of which can be used to update the target.
The reason for that is pretty obvious when you think of the builtin pattern rules -- there are multiple rules for %.o
which can compile a source file in a variety of languages. If they all got combined into a single rule, it simply wouldn't work.
Upvotes: 3