Say I have a set of Makefile modules:
# foo.mk
rule1: prereq1
recipe1
and
# bar.mk
rule2: prereq2
recipe2
and a primary Makefile:
# Makefile
include foo.mk
include bar.mk
Should .PHONY:
be included in each individual .mk file for the phony targets just in that file, or should there be some acculmulated list that is included only in the primary Makefile?
# foo.mk
TARGETS += rule1
...
# bar.mk
TARGETS += rule2
...
# Makefile
.PHONY: $(TARGETS)
I didn't find anything relevant in the GNU Make docs or similar questions.
.PHONY
is never overridden. Like any other target, each new.PHONY
definition adds more prerequisites to the existing list. No, there is no best practice that I'm aware of. Both work identically (except one has a variable defined, which might be useful for other things besides.PHONY
, and one doesn't). For the same reason there's no need for a "documented & defined" method. Whichever one you like better, you should use. – MadScientist