makefile中处理组件的顺序
在 makefile 中,依赖行的形式为 -
abc: x y z
所有三个组件 (x,y,z) 本身都是 makefile 中依赖行中的目标。
如果调用make abc,三个目标x、y、z将以什么顺序执行?
In a makefile, the dependency line is of the form -
abc: x y z
All three of the components (x,y,z) are themselves targets in dependency lines further down in the makefile.
If make abc is invoked, in what order will the three targets x,y,z be executed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
默认情况下,执行顺序与先决条件列表中指定的顺序相同,除非这些先决条件之间定义了任何依赖关系。
顺序是
xy z
。顺序为
xz y
。但理想情况下,您应该设计 Makefile,使其不依赖于指定先决条件的顺序。也就是说,如果
y
应在z
之后执行,则必须存在y : z
依赖性。请记住,GNU Make 可以并行执行一些配方,请参阅 Mat 的回答。
By default, the order of execution is the same as specified in the prerequisites list, unless there are any dependencies defined between these prerequisites.
The order is
x y z
.The order would be
x z y
.But ideally, you should design your Makefiles so that it wouldn't rely on the order in which prerequisites are specified. That is, if
y
should be executed afterz
, there must be ay : z
dependence.And keep in mind that GNU Make can execute some recipes in parallel, see Mat's answer.
您确实不应该依赖它们的执行顺序 - 在其他条件相同的情况下,这些先决条件的所有三个配方都可以并行运行。
唯一的硬性规则是在运行目标配方之前必须满足所有先决条件。
如果
x
、y
和z
之间没有依赖关系,并且没有并行执行,GNU make 会按照您指定的顺序运行它们,但这在文档中并没有得到保证。You really shouldn't depend on the order in which they are executed - all else being equal, all three recipes for those prerequisites could run in parallel.
The only hard rule is that all prerequisites must be met before the target recipe is run.
If there are no dependencies between
x
,y
andz
, and no parallel execution, GNU make appears to run them in the order you specified them, but this is not guaranteed in the docs.make
的 POSIX 描述包含一个基本原理其中说:(我相信
$(CC)
行中的t.tab.o
是y.tab.o
的拼写错误,但这就是基本原理实际上所说的。)因此,观察到的从左到右处理先决条件的行为在这里得到了验证,尽管它只在基本原理部分而不是在主要描述中。基本原理还提到了并行
make
等问题。The POSIX description of
make
includes a rationale which says:(I believe the
t.tab.o
in the$(CC)
line is a typo fory.tab.o
, but that is what the rationale actually says.)Thus, the observed behaviour that pre-requisites are processed from left to right has validation here, though it is only in the Rationale section, not in the main description. The Rationale also mentions issues with parallel
make
etc.GNU make 4.4 的新功能是,我们有
.WAIT
先决条件!将其设置为依赖项,它将暂停其右侧的所有依赖项,直到左侧的所有依赖项完成。
请注意,
please_run_me
&and_me
彼此之间没有顺序,但两者都会在before_me
开始之前完成。您可以在一行上抛出多个
.WAIT
。还有另一种方法可以做到这一点 -
.NOTPARALLEL
,您可以阅读它 更改日志中 或 手册虽然它是在 2022 年 10 月 31 日发布的,某些发行版(例如:Ubuntu)可能尚未预装。
如果您想为此类设备安装
make
,则必须从源代码构建。New to GNU make 4.4, we have the
.WAIT
prerequisite!Set it as a dependency, and it will pause all dependencies to the right of it until all the ones to the left are completed.
Note that
please_run_me
&and_me
are not ordered in relation to eachother, but both will finish beforebefore_me
starts.You can throw multiple
.WAIT
s on a line.There was another way added to do this too -
.NOTPARALLEL
, you can read about it in the changelog or in the manualThough it released on the 31st October 2022, some distributions (e.g.: Ubuntu) may not come with it preinstalled yet.
If you want to install
make
for such devices, you'll have to build from source.