Makefile:只订购先决条件和$ ^

Joh*_*ohn 1 makefile gnu-make

我在makefile中有以下内容:

.PHONY: preq_test a b c d

a b c d:
    @echo building $@

preq_test : a b | c d
    @echo preq prequisites are: $^;
Run Code Online (Sandbox Code Playgroud)

现在,$^应该根据文档列出所有先决条件(除了重复):

$^
$+
    The names of all the prerequisites, with spaces between them. For prerequisites
    which are archive members, only the named member is used (see Archives). The value
    of $^ omits duplicate prerequisites, while $+ retains them and preserves their
    order.
Run Code Online (Sandbox Code Playgroud)

但仅限订单的先决条件不会出现在$^:

building a
building b
building c
building d
preq prequisites are: a b
Run Code Online (Sandbox Code Playgroud)

我可以依赖当前的行为,还是应该以其他方式工作,还是应该将其视为未定义的行为?

谢谢,

约翰

Ant*_*nko 6

$^记录的行为是省略订单仅先决条件,所以你可以依靠它(您可以使用 $|获得公正订单仅先决条件,BTW).