0

I know we can set up commands such as all, clean, install etc in makefile and use .PHONY to tell make they're not associated with files.

But I was wondering - when creating make and makefile - was this kind of use (to run such commands) combined with .PHONY designed for that purpose? Or maybe .PHONY was added later to easily extend make to support those kind of commands?

I also read this but there wasn't anything else there except the regular known usage.

Thanks!

arieljannai
  • 2,124
  • 3
  • 19
  • 39
  • Is your question about the history of GNU make (at what date was the `.PHONY` special target added?) or about the use of `.PHONY` or the use of phony targets? – Renaud Pacalet Aug 10 '17 at 08:54
  • It's combined, I wanted to know if that was the purpose of it and if there are more uses (that maybe no one uses) for it. In second thought - maybe it's more suitable for the unix site? – arieljannai Aug 10 '17 at 09:00

1 Answers1

3

I do not know the history of GNU make.

The use of .PHONY is exactly what you suspect: have targets (which can thus be goals, or commands, if you wish) that are not files, and that work even if, by accident, a file with the same name exists. It is one single and clearly defined purpose.

In certain cases you want to force a target file to be re-built even if it is up-to-date, and you can declare it a prerequisite of .PHONY for this purpose, but it is frequently the sign that your makefile is not what it should be.

Another frequent situation is the grouping of several targets (real or phony) as prerequisites of one single other phony target.

But in both cases, we can say that the resulting phony target is a kind of command. In the first case it is a command that forces the build of a file. In the second it is a kind of alias for a series of actions.

Renaud Pacalet
  • 25,260
  • 3
  • 34
  • 51