Makefile: implicit rule condition not working?
If I create an implicit rule with a precondition (but not a recipe), then the dependency doesn't seem to deserve it. If, on the other hand, I define a precondition in the block where I define the recipe, or if I specify a dependency on a specific target instance, it seems 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 although it %.a
depends dep1
, foo.a
you can build without dep1
. Is this a bug in make, or is there a reason for this behavior?
Thank,
John
source to share
Template rules with the same purpose are not combined into a single rule, such as rules without templates. When you have two rules without a template for the same target, they are combined into one rule with all dependencies of the two rules and actions from the rule that has actions (and this is a bug for both rules for actions) .With template rules, this is not happens - they are viewed as two completely independent rules that can be used to update the target.
The reason for this is pretty obvious when you think of the built-in template rules - there are many rules for %.o
that can compile a source file in different languages. If they were all combined into one rule, it simply wouldn't work.
source to share