文件目标是否仅作为 PHONY 目标的先决条件?

File targets to be prerequisites of PHONY targets order-only or not?

Makefile style guide提到"No file targets should be prerequisites of .PHONY."

我假设您可以将其改写为 "Don't declare file targets PHONY"?

为了表达依赖性,对于人类 reader 以及 Make,我猜你有时需要文件目标作为 PHONY 目标的先决条件。 那么,这些目标应该是仅限订单的目标吗? 据我所知,在这种情况下,order-only 和 not 之间的唯一区别是它们出现在 $^ 还是 $| 中,所以这可能取决于你在这件事上想要什么样的行为,分别是你想要哪种依赖关系表达。

我说得对吗? (如果没有一个明确的案例,)是否有任何理由选择一个而不是另一个(是否仅订购)?

I guess you sometimes need file targets be prerequisites of PHONY targets

事实上,大多数时候。考虑 "standard" 东西:

.PHONY: all
all: myprog other_stuff
myprog: $(OBJECTS)
    ...

但是"Don't declare file targets PHONY / No file targets should be prerequisites of .PHONY"是完全不同的事情。这意味着 .PHONY: myprog 不好,应该避免。原因是(1)无条件触发异常的myprog重建; (2) 它可能会让人误以为 myprog 是 "not a file".

如果您需要在执行 make -B myprog 后强制重建 myprog。如果每次make运行时真的需要重建,那么你可以这样做:

myprog: $(OBJECTS) FORCE
    ...
FORCE:;

或者类似的东西。

As far as I understand, in this case the only difference between order-only and not is if they appear in $^ or in $|

order-only 先决条件很少使用 GNU 扩展。没有必要把它们放进去只是为了表明左侧的 "phony stuff" 无论如何都会被重建。所以没有人写 all: | myprog,尽管它和 all: myprog.

一样好用