makefile Using .PHONY for non-files targets


Example

Use .PHONY to specify the targets that are not files, e.g., clean or mrproper.

Good example

.PHONY: clean
clean:
    rm *.o temp

Bad example

clean:
    rm *.o temp

In the good example make knows that clean is not a file, therefore it will not search if it is or not up to date and will execute the recipe.

In the bad example make will look for a file named clean. If it doesn't exist or is not up to date it will execute the recipe, but if it does exist and is up to date the recipe will not be executed.