PeopleMoutainPeopleSea
PeopleMoutainPeopleSea

Reputation: 1512

Precedence of empty explicit rule and implicit rule

My understanding of implicit rule is that implicit rule will only be used if there is no explict rule that matches a target. If there are both explicit rule and implicit rule that match a target, that the explicit rule will be used, the implicit rule will be ignored.

But running the following example shows that implicit rule is used, and empty explicit rule is not used.

Makefile

all:

%:
      #match-anything implicit rule

the output of make is #match-anything implicit rule

Makefile

all:
      #explicit rule

%:
      #match-anything implicit rule

the output of make is #explicit rule

Upvotes: 1

Views: 929

Answers (2)

Hai Zhang
Hai Zhang

Reputation: 5832

From Using Empty Rules in GNU make manual:

It is sometimes useful to define recipes which do nothing. This is done simply by giving a recipe that consists of nothing but whitespace. For example:

target: ;

defines an empty recipe for target. You could also use a line beginning with a recipe prefix character to define an empty recipe, but this would be confusing because such a line looks empty.

You may be wondering why you would want to define a recipe that does nothing. The only reason this is useful is to prevent a target from getting implicit recipes (from implicit rules or the .DEFAULT special target; see Implicit Rules and see Defining Last-Resort Default Rules).

Upvotes: 0

Etan Reisner
Etan Reisner

Reputation: 80921

This behaviour is documented in the GNU make manual in the Multiple Rules for One Target section.

If none of the explicit rules for a target has a recipe, then make searches for an applicable implicit rule to find one see Using Implicit Rules).

Additional information (as relevant to understand the various interconnected behaviours) is available in the Rule Syntax and What Makefiles Contain sections.

Upvotes: 1

Related Questions