xilef97
xilef97

Reputation: 33

GNU make - implicit rule is not used, but static pattern rule is

Consider the following makefile (and any hi.c):

.PHONY: analyze-%


hi: hi.c
    gcc -o $@ $<

%.json: %
    touch $@ # actually created by analysis-tool

analyze-%: %.json # why does this not work?

As my comment in the makefile points out, the implicit rule does not work:

$ make analyze-hi
make: *** No rule to make target 'analyze-hi'.  Stop.

It only works after transforming it into a static pattern rule:

...
analyze-hi: analyze-%: %.json

Why is this the case? Shouldn't make be able to figure this out on its own, without me having to explicitly write the full target name? There is no ambiguity or anything (as far as I'm aware).

Upvotes: 0

Views: 224

Answers (1)

MadScientist
MadScientist

Reputation: 100781

Pattern rules must have recipes. If they don't have a recipe then they're not creating a pattern rule, they're canceling one.

See https://www.gnu.org/software/make/manual/html_node/Canceling-Rules.html

A static pattern rule, contrary to what's implied by its name, is not actually creating an implicit rule (pattern or suffix rule). It's creating explicit rules, just based on a pattern. Explicit rules don't have to have recipes.

Upvotes: 2

Related Questions