Inside the Makefile
of a project you can find a .PHONY
element followed by a label and then the same label used as a target for the Makefile.
For example:
.PHONY: build
build:
go build
.PHONY
is actually itself a target for the make
commandand and it denotes labels that do not represent files of the project. What does it mean?
In the general case, assuming that there are no files called build in the project, when not using the .PHONY
target, like so
build:
go build
everytime the make build
command is invoked it will execute the specified command (in this case go build
). However, if there was a file named build, the make build
would be bound by the presence of this file and executed only if that file was updated.
The .PHONY
target overrides this last behaviour and let's the make build
execute no matter of the presence of a file named build.
For a more in-depth overview head to the make
command reference.
Top comments (2)
Simple and easier to understand.
Actualy the better and simplier explanation about .PHONY directive.