Re:Learn Makefiles with the Tastiest Examples
by lenkite on Tuesday May 16, 2023 @02:31AM
(#35958344)
Why do we need to add `.PHONY` for every target ? This is one of the things I utterly despise about make.
[ Parent
| on HN ]
Re:Learn Makefiles with the Tastiest Examples
by jbverschoor on Tuesday May 16, 2023 @02:42AM
(#35958407)
Because make is misused
Make is a tool to make files based on dependencies
It was not created as a scripting language. It understands trees.
It is not to “make” your project. It “makes” “files”
Re:Learn Makefiles with the Tastiest Examples
by jbverschoor on Wednesday May 17, 2023 @04:02AM
(#35972464)
If 'make' was called makefile, I don't think it'd be so popular. Naming is important
Re:Learn Makefiles with the Tastiest Examples
by paulddraper on Tuesday May 16, 2023 @04:34AM
(#35959075)
.PHONY is how you distinguish between targets that are actual files vs targets that are virtual.
Seems like useful information to me....
It's best practice, though the only time you need it is when a virtual target happens to have the same name as an actual file.
Re:Learn Makefiles with the Tastiest Examples
by tpoacher on Tuesday May 16, 2023 @08:29AM
(#35960919)
You don't. You can specify this in a single line.
Unless the question was, why do I have to mark targets as PHONY more generally.
In which case the answer is, you don't. You only do this when you want the recipe to always run when invoked, as opposed to the standard mode where invocation is conditional on the file being out-of-date.