theTrickster
theTrickster

Reputation: 99

make implicit rules don't work without command

I have a simple Makefile like this:

%.t1:   %.t2

%.t2:
    echo "t2"

When I type make x.t2 it works fine. But when I type make x.t1 I get

make: *** No rule to make target 'x.t1'.  Stop.

If I modify the %.t1 target to say

%.t1:   %.t2
    echo

Then it works. Why doesn't it work without a command? I'm using GNU make 4.0 on Fedora 23.

Upvotes: 2

Views: 1561

Answers (1)

Etienne Laurin
Etienne Laurin

Reputation: 7184

A pattern rule with no recipe does not add a rule, it cancels implicit rules. See http://www.gnu.org/software/make/manual/make.html#Canceling-Rules:

You can cancel a built-in implicit rule by defining a pattern rule with the same target and prerequisites, but no recipe. For example, the following would cancel the rule that runs the assembler:

%.o : %.s

A semi-colon can be added to tell make that it has an empty recipe:

%.t1: %.t2 ;
%.t2:
    echo t2

Which yields:

$ make x.t1
t2

Upvotes: 3

Related Questions