What does .PHONY mean in a Makefile?
I have gone through this, but it is too complicated.
Can somebody explain it to me in simple terms?
What does .PHONY mean in a Makefile?
I have gone through this, but it is too complicated.
Can somebody explain it to me in simple terms?
Sometimes you want make to just execute some commands, without being tied to some target filename. This is when you use a "phony target".
The document you linked to supplies the rationale:
There are two reasons to use a phony target: to avoid a conflict with a file of the same name, and to improve performance.
There's also a really nice tutorial explaining it here.
P.S. if you don't understand this feature, then you probably don't need it.
Let's assume you have 'install' target, which is a very common in makefiles. If you do NOT use PHONY, and the file named "install" exists in the same directory with Makefile, the "make install" will do NOTHING as it will be interpreted as "execute such and such rules to create the install file". Since the file is already there, and its dependencies didn't change, nothing will be done.
However if you make the install target PHONY, it will tell the make tool that the target is fictional, and that make should not expect it to create the actual file. Hence it will not check whether the "install" file exists, meaning a) its behavior will not be altered and b) extra stat() will not be called.
Generally all targets in your Makefile, which do not produce the file with the target name, should be PHONY. This typically includes all, install, clean, distclean and so on.