0
votes
.PHONY: foo bar baz
all: foo bar baz foo bar
    # @=$@
    # ?=$?
    # <=$<
    # ^=$^
    # +=$+

Here is the output of this:

# @=all
# ?=foo bar baz
# <=foo
# ^=foo bar baz
# +=foo bar baz foo bar

If if comment first line as:

#.PHONY: foo bar baz

Then output is:

make: *** No rule to make target `foo', needed by `all'.  Stop.

i have two question:

1) Why make does not complain for a rule in first case when "foo bar and baz" are declared PHONY.

2) I started commands with a pound(#). Why these commands are not treated as a comment.

1
The recipe lines are treated as comments... by the shell. make still expands the variables and passes the lines to the shell though. - Etan Reisner
Phony targets don't represent files. They aren't used by later targets as files/etc. themselves. As such I imagine make decided that they shouldn't fail to build if no rule exists since there's nothing to create for that target anyway. - Etan Reisner

1 Answers

1
votes

Etan has the right info in his comments. Just to be a little more verbose:

1) Declaring a target PHONY creates it as a target inside make. So thereafter, if you list it as a prerequisite, make knows about it just as if you'd written foo: as a target. It could be argued this is a bug in make; I'm not sure, but that's how it works.

2) The important detail from Etan's answer is that if there's a line in your makefile [1] that starts with a TAB, make will send it to the shell. Make doesn't try to interpret the line, even to see if it's a comment or not (other than expanding variables/functions of course). Whatever you write, is sent to the shell.

[1] "in a target context", which is hard to describe concretely... best bet is to never use TAB unless you're trying to write a recipe line.