Home

PHONY

PHONY refers to a category of targets used in build systems, most prominently GNU Make, that do not correspond to actual files. A phony target is treated as always out of date, so its recipe is executed whenever the target is requested, regardless of whether a file with the same name exists or what its timestamp is.

In Makefiles, phony targets are declared with the special target .PHONY followed by one or more target

.PHONY: clean

clean:

rm -f *.o

rm -f core

Common phony targets include build, test, install, all, and clean. These are typically used to perform actions

The behavior of phony targets interacts with prerequisites in the same way as ordinary targets. If a

PHONY usage is supported by GNU Make and is widely adopted in other make implementations. It helps

names.
Declaring
a
target
as
phony
helps
ensure
that
Make
runs
its
recipe
instead
of
trying
to
decide
whether
a
corresponding
file
is
up
to
date.
For
example:
rather
than
to
produce
or
update
a
file
with
the
same
name.
By
declaring
them
as
phony,
make
avoids
confusion
if
a
file
with
the
same
name
appears
in
the
directory.
phony
target
has
prerequisites,
Make
will
build
those
prerequisites
as
needed
before
executing
the
phony
target’s
recipe.
However,
the
phony
target
itself
is
not
gated
by
the
existence
or
timestamp
of
a
file
named
after
it;
its
recipe
will
be
executed
when
invoked.
prevent
accidental
clashes
with
real
files
and
clarifies
the
intended
actions
of
the
build
process.