> I have gone through this, but it is too complicated
Really?
4.6 Phony Targets
A phony target is one that is not really the name of a file; rather it is just a name for a recipe to be executed when you make an explicit request. <…>
clean:
rm *.o temp
Since it has no prerequisites, the file clean would inevitably be considered up to date, and its recipe would not be executed. To avoid this problem, you can explicitly declare the target to be phony, using the special target .PHONY (see Special Built-in Target Names) as follows:
.PHONY : clean
Once this is done, ‘make clean’ will run the recipe regardless of whether there is a file named clean.
I did not dig up the changelog of the make homepage but the linked post is fairly old (2010) and the make manual gets updated somewhat frequently[1].
Why this was posted and upvoted tho I don't quite understand. It's not some kind of arcane concept barely anybody knew/knows about. The accepted answer doesn't seem to be better than the part in the current manual about it either.
[1]:
> This is Edition 0.72, last updated 9 October 2013, of The GNU Make Manual, for GNU make version 4.0.
4 comments
[ 5.8 ms ] story [ 24.8 ms ] threadReally?
4.6 Phony Targets
A phony target is one that is not really the name of a file; rather it is just a name for a recipe to be executed when you make an explicit request. <…>
Since it has no prerequisites, the file clean would inevitably be considered up to date, and its recipe would not be executed. To avoid this problem, you can explicitly declare the target to be phony, using the special target .PHONY (see Special Built-in Target Names) as follows: Once this is done, ‘make clean’ will run the recipe regardless of whether there is a file named clean.I did not dig up the changelog of the make homepage but the linked post is fairly old (2010) and the make manual gets updated somewhat frequently[1].
Why this was posted and upvoted tho I don't quite understand. It's not some kind of arcane concept barely anybody knew/knows about. The accepted answer doesn't seem to be better than the part in the current manual about it either.
[1]: > This is Edition 0.72, last updated 9 October 2013, of The GNU Make Manual, for GNU make version 4.0.