help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dumb Questions


From: Kaz Kylheku (gmake)
Subject: Re: Dumb Questions
Date: Mon, 11 Nov 2019 10:21:09 -0800
User-agent: Roundcube Webmail/0.9.2

On 2019-11-10 23:18, Lee Eric wrote:
Hi,

New to Make and after reading some pages from the GNU Make book I'm
confused about some explanations.

1. From the O'Reilly book it mentions "Normally, phony targets will be
always be executed ...". I don't quite follow it as "clean" is a
typical phony target but it's not executed every time until we tell
Make. So my question is, if a Makefile has multiple targets, what's
the rule of Make to process the targets? Because after reading the
book I have no idea what targets would be executed.

The direct rules in a Makefile form the familiar directed acyclic graph
(DAG). The target in a Makefile that is not a prerequisite of other
targets is the root of the DAG. If there are multiple such targets then
there are multiple roots. In that case we can choose the root by giving
a target on the command line. If no target is given on the command line,
then the first one that occurs in the Makefile is updated.

A phony target's recipe is always executed if that phony target is
involved in a dependency tree that is part of an update.

A phony target that is not part of a tree being updated, of course,
doesn't have its recipe executed. (Like your "clean" target example
when "make clean" isn't being run).

Because a phony target isn't a real file, it is always considered
to be missing. Whenever it is required as a prerequisite, or explicitly
required as a goal from the command line, its recipe is executed.

However, it is executed only once. A phony target is in fact a real
object; just not one in the filesystem. It's an object that exists in
make's memory somehow. When the recipe for that object runs, it is
then considered up-to-date, even though no file was created or touched.
when evaluation continues and other rules are processed which require
that same target, the rule is not run again; the target is known to be
up-to-date.

Therefore, it is subtly misleading to say "the phony target always executes".

If a phony target is required by three rules that all execute,
it doesn't execute three times, as "always" would imply.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]