Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile wildcard (static rule?) with phony

I'm just starting to really grok the inner workings of make. Yet I do not understand why the following doesn't work:

test%: test%.foo
     @echo $@
     @echo $<

all: test1 test2

.PHONY: all test1 test2

Expected behavior:

$ make
test1
test1.foo
test2
test2.foo
# 1,2 Order not important

However, I get:

$ make
make: Nothing to be done for `all'.

("make all", "make test1", etc make no difference).

Can someone explain why the PHONY test rules aren't being executed?

like image 981
Pat Avatar asked Oct 25 '11 09:10

Pat


1 Answers

Excerpt from the GNU make manual.

Since it knows that phony targets do not name actual files that could be remade from other files, make skips the implicit rule search for phony targets (see section Using Implicit Rules). This is why declaring a target phony is good for performance, even if you are not worried about the actual file existing.

This means that as your test1 and test2 targets are phony, make does not search for implicit rules for them. Even if what you use is more accurately named pattern rules, all pattern rules are implicit rules.

like image 181
Didier Trosset Avatar answered Oct 10 '22 21:10

Didier Trosset