user2830528
user2830528

Reputation: 169

make does not require rule for phony prerequisite

.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.

Upvotes: 0

Views: 193

Answers (1)

MadScientist
MadScientist

Reputation: 100781

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.

Upvotes: 1

Related Questions