arieljannai
arieljannai

Reputation: 2146

Makefile - does using .PHONY for running commands was intended when creating make?

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!

Upvotes: 0

Views: 122

Answers (1)

Renaud Pacalet
Renaud Pacalet

Reputation: 29220

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.

Upvotes: 3

Related Questions