1
votes

I have this minimal Makefile:

.PHONY: foo.bar
%.bar:
    echo $*

I run $ make foo.bar and I expect it to match the %.bar pattern, populate the stem $* with "foo", and echo "foo" all the time because foo.bar is a phony target. However, the output I get is

make: Nothing to be done for 'foo.bar'.

Am I missing something here?

EDIT:

I forgot to mention that removing the .PHONY line performs the expected behavior where it echo's "foo", and also making it an explicit target "foo.bar" without the pattern matching. Both of which make perfect sense since in the former, the file, foo.bar, doesn't exist and in the latter, well, it's just explicit.

EDIT:

This might be a duplicate of this actually: When declaring the pattern rule as PHONY, it is not triggered. Here is something that works:

.PHONY: foo.bar

foo.bar: %.bar:
    echo $*

For whatever reason the target/dependency line is more like target/(dependency|target)/dependency. Can someone explain this or point me to the documentation?

1

1 Answers

2
votes

From the make manual section on .PHONY targets:

The implicit rule search (see Implicit Rules) is skipped for .PHONY targets.

meaning your rule for %.bar: is simply ignored.

Getting rid of .PHONY of course works as expected; using the rule foo.bar: %.bar: works because static pattern rules are not implicit rules and so won't be ignored for .PHONY targets.