Skip to main content Skip to navigation

6. The phony target

One of the many special target names in make is the .PHONY target name. A .PHONY target is used to avoid conflict with a file name that might be the same as one of your target names.

Take the example of the clean target. The commands associated with this target do not make a file called 'clean'. So long as there is no file called clean in your build directory, the make clean command should always work (and delete files like it should). However, if a file called 'clean' was present, since it has no dependencies, the file `clean' would inevitably be considered by make to be up-to-date, and its commands would not be executed. To prevent this happening, label the clean target declaration in the following way:

.PHONY : clean
	rm -f core ${OBJ}

Now, make clean will run the commands regardless of whether there is a file named `clean'.