.PHONY mean in a Makefile? The
make manual describes the
.PHONY target as,
A phony target is one that is not really the name of a file; rather it is just a name for a recipe to be executed when you make an explicit request.
However, what does this mean?
.PHONY in a makefile?
By default, targets are “target files”. For the following rule,
make asks: “Is
hello.txt out of date?” To determine if it is out of date, it follows the logic:
dependency.txtmore recent than
hello.txt? If so, run the instructions.
hello.txtdoes not exist, run the instructions.
However, for targets that do not output files, a
.PHONY label is used. In the following rule,
format target formats
go code. It does not produce a file.
.PHONY important in a makefile?
For some cases,
.PHONY is not needed. For example,
lint target surfaces various code issues. As long as a file named
lint does not exist (or will not exist in the future), this command will continue working. From the
lint will always be out of date since the file will never exist.
.PHONY is only important if a target’s name can collide with a file name.