您应该如何在包含的 Makefile 中使用 .PHONY?
How should you use .PHONY in included Makefiles?
假设我有一组 Makefile 模块:
# foo.mk
rule1: prereq1
recipe1
和
# bar.mk
rule2: prereq2
recipe2
和一个主要的 Makefile:
# Makefile
include foo.mk
include bar.mk
是否应该 .PHONY:
包含在每个单独的 .mk 文件中,只包含在该文件中的虚假目标,或者应该有一些仅包含在主要 Makefile 中的累积列表?
# foo.mk
TARGETS += rule1
...
# bar.mk
TARGETS += rule2
...
# Makefile
.PHONY: $(TARGETS)
我没有在 GNU Make docs 或类似问题中找到任何相关内容。
声明
.PHONY: rule1
告诉 Make 它不应该考虑 "rule1" 要构建的文件的名称。假设你把它放在 Makefile
中。当您 运行 另一个 makefile(foo.mk
或包含它的 makefile 时会发生什么?
当您运行 rule1
规则时,您是否希望 Make 将其视为 PHONY 目标?如果您的答案不是 "that depends on which makefile I'm using", 那么您应该在 makefile 中包含定义规则的语句。
假设我有一组 Makefile 模块:
# foo.mk
rule1: prereq1
recipe1
和
# bar.mk
rule2: prereq2
recipe2
和一个主要的 Makefile:
# Makefile
include foo.mk
include bar.mk
是否应该 .PHONY:
包含在每个单独的 .mk 文件中,只包含在该文件中的虚假目标,或者应该有一些仅包含在主要 Makefile 中的累积列表?
# foo.mk
TARGETS += rule1
...
# bar.mk
TARGETS += rule2
...
# Makefile
.PHONY: $(TARGETS)
我没有在 GNU Make docs 或类似问题中找到任何相关内容。
声明
.PHONY: rule1
告诉 Make 它不应该考虑 "rule1" 要构建的文件的名称。假设你把它放在 Makefile
中。当您 运行 另一个 makefile(foo.mk
或包含它的 makefile 时会发生什么?
当您运行 rule1
规则时,您是否希望 Make 将其视为 PHONY 目标?如果您的答案不是 "that depends on which makefile I'm using", 那么您应该在 makefile 中包含定义规则的语句。