Clark Grubb's Makefile style guide recommends that:
- All phony targets should be declared by making them prerequisites of .PHONY.
- add each phony target as a prerequisite of .PHONY immediately before the target declaration, rather than listing all the phony targets in a single place.
- No file targets should be prerequisites of .PHONY.
- phony targets should not be prerequisites of file targets.
For your example, this would mean:
.PHONY: all
all:
echo "Executing all ..."
.PHONY: of
of:
echo "Executing of ..."
.PHONY: my
my:
echo "Executing my ..."
.PHONY: rules
rules:
echo "Executing rules ..."
Multiple PHONY
targets are allowed; see also this Stack Overflow question: "Is it possible to have multiple .PHONY targets in a gnu makefile?"
Also, while this isn't mentioned directly in your question, care must be taken not to have a PHONY
target with the same name of an actual input or intermediate files in your project. Eg, if your project hypothetically had a source code file named rules
(with no suffix), the inclusion of that string in a PHONY
target could break expected make
behavior.