SFbay007
SFbay007

Reputation: 2027

Do pattern implicit rules get executed even if there was another rule already that match the target?

Basically, if I have a target that already has a rule but still match another pattern implicit rule. How make handles this situation?

targ.bin :: dep

dep: some-req
   some rules

%.bin : some-reqs
   some rules

In this case do both rules apply on targ.bin? Meaning, would dep be called with it's prereqs and rules then make executed the %.bin pattern implicit prereqs and rules?

Upvotes: 1

Views: 58

Answers (1)

Mike Kinghan
Mike Kinghan

Reputation: 61202

See the GNU Make manual 4.13 Double-Colon Rules, especially:

Each double-colon rule should specify a recipe; if it does not, an implicit rule will be used if one applies. See Using Implicit Rules.

Your double-colon rule:

targ.bin :: dep

has no recipe. Therefore it only expresses the dependency targ.bin -> dep and the implicit rule:

%.bin : some-reqs
   some rules

specifies that targ.bin shall be made up-to-date by executing:

some rules

as well as implying the dependency targ.bin -> some-reqs.

Make combines all prerequisites of target targ.bin. So your Makefile implies that:

dep: some-req
   some rules

targ.bin : some-reqs dep
   some rules

is the complete recipe for targ.bin. As bourne out by:

Makefile

targ.bin :: dep

dep: a
    echo '$@ -> $^'

%.bin : b
    echo '$@ -> $^'

which runs like:

$ touch a b
$ make
echo 'dep -> a'
dep -> a
echo 'targ.bin -> b dep'
targ.bin -> b dep

Later

Assuming in the example you provided the double-colon rule had a recipe, does that mean the implicit one wont be applied?

See 10.1 Using Implicit Rules, especially:

In general, make searches for an implicit rule for each target, and for each double-colon rule, that has no recipe.

So yes, if the double-colon rule had a recipe the implicit rule would not be applied. I'll leave the experiment to you.

Upvotes: 1

Related Questions