Why .PHONY: goal, not goal: .PHONY?

I still don't understand why the "fake" rules in Make files have ".PHONY" as their target. This would be much more logical as a prerequisite.

Should I dwell on this in detail? If A depends on B and B is false, then A also false. Therefore, the dependency graph .PHONYBA is unexpected compared to .PHONYBA (Another argument is that the make implementation must handle the target .PHONY object .PHONY very special.)

Although this criticism may seem rather theoretical (meaningless) - "since the brand is so ancient, its syntax is here to stay." But I do not suggest any syntactic changes, there is an alternative:

With GNU Make (at least), the following Makefile declares a fake target_A :

 target_A: _PHONY touch target_A _PHONY: #noop 

Question 1 : It is so simple and clean, of course, I am not its first inventor. In fact, given this alternative, why do you need special syntax?

It seems to me that this would also very well solve wildcard issues for fake purposes and even shed some light on .PHONY means when beginners doubt it.

Question 2 : Can you come up with any circumstance when this approach is inferior? ( make .PHONY any use called?)

(I should mention that although I called other make s, GNU Make is the only implementation I have experience with reading and writing Make files.)

+7
source share
1 answer

One of the big problems with using target_A: .PHONY is that it is much harder to use many built-in variables. Take this general recipe as an example:

 %.a: $(OBJ_FILES) $(LD) $(LFLAGS) -o $@ $^ 

The variable $^ pulls into everything that is indicated as a necessary condition. If .PHONY was also specified .PHONY , then it will be passed to the linker on the command line, which probably will not lead to anything good. Using meta targets such as .PHONY , since the prerequisites make these built-in variables much less useful, since they require a lot of extra processing, like $(filter-out .PHONY,$^) every time they are used. .PHONY inverting the relationship and creating .PHONY , the target is a little awkward to think about dependency trees, but it clears the rest of the makefile.

+3
source

All Articles