I often use them to tell the default target not to fire.
superclean: clean andsomethingelse
blah: superclean
clean:
@echo clean
%:
@echo catcher $@
.PHONY: superclean
Without PHONY, make superclean
would fire clean
, andsomethingelse
, and catcher superclean
; but with PHONY, make superclean
won't fire the catcher superclean
.
We don't have to worry about telling make the clean
target is PHONY, because it isn't completely phony. Though it never produces the clean file, it has commands to fire so make will think it's a final target.
However, the superclean
target really is phony, so make will try to stack it up with anything else that provides deps for the superclean
target — this includes other superclean
targets and the %
target.
Note that we don't say anything at all about andsomethingelse
or blah
, so they clearly go to the catcher.
The output looks something like this:
$ make clean
clean
$ make superclean
clean
catcher andsomethingelse
$ make blah
clean
catcher andsomethingelse
catcher blah