I have come across this many times: .PHONY
at the end of files Makefile
and would like to know what it means. I have used Makefiles
but never needed to add that.
A concrete example of what I found now:
.PHONY: \
all \
test \
clean \
release
Translating George Y. 's answer from Stack Overflow to the question What is the purpose of .PHONY in a makefile? . The explanation is simple and quite good.
Let's assume you have the "install" target, which is very common in makefiles. If you don't use
.PHONY
, and there is a file called "install" in the same directory as the Makefile, then the commandmake install
will do nothing. This occurs because Make interprets the rule as "execute this-and-this recipe to create the file named install". Since the file is already there, and the dependencies haven't changed, nothing will happen.However, if you make the "install" target a PHONY, you will tell the tool
make
that the target is dummy, and thatmake
it should not create the file. Therefore it will not check that the "install" file exists, which means that:stat()
extra will not be calledGenerally all targets in your Makefile that do not produce an output file with the same name as the target name should be of type PHONY. This typically includes a
all
,install
,clean
,distclean
, etc.The following example of the answer taken from the same question created by Eli Bendersky should make it clearer.
These special targets are called PHONY and you can explicitly tell Make that they are not associated with files, for example: