3

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?

Community
  • 1
  • 1
solstice333
  • 3,399
  • 1
  • 31
  • 28

1 Answers1

4

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.

user657267
  • 20,568
  • 5
  • 58
  • 77
  • Thanks. I was just about to say that I missed the connection of how pattern matching is considered an implicit rule. That makes a ton of sense now. – solstice333 Feb 12 '16 at 23:51
  • Yeah the make manual terminology can be a little confusing; built-in implicit rules, pattern rules, last resort rules, and suffix rules are all considered implicit rules. – user657267 Feb 13 '16 at 00:00
  • Also found the doc to that double colon target/dep line for reference: https://www.gnu.org/software/make/manual/html_node/Static-Usage.html#Static-Usage – solstice333 Feb 13 '16 at 00:01