make 如何决定构建目标

发布于 2024-08-30 21:27:59 字数 107 浏览 5 评论 0原文

一个迹象是目标不存在,请理解这一点。

另一种方法是比较目标和先决条件的修改时间戳。更详细地讲它是如何工作的?比较目标时间戳和先决条件时间戳的逻辑是什么?当存在多个先决条件时它如何工作?

One sign is that target does not exist, understand this.

Another is by comparing modification timestamp of target and prerequisites. How it works in more details? What is the logic of comparing target and prerequisite timestamps and how it works when there are multiple prerequisites?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

对你而言 2024-09-06 21:27:59

make 首先获取目标的修改时间,然后将该值与每个 prereq 的修改时间进行比较,按照从左到右的顺序,一旦发现任何比目标更新的 prereq 就停止(因为单个较新的先决条件足以要求重建目标)。

例如,假设您有这样的规则:

foo: bar baz boo

此外,假设这些文件的修改时间如下:

foo: 4
bar: 3
baz: 6
boo: 2

在这种情况下,make将比较foo (4) 到bar (3)的修改时间;由于 bar 较旧,make 将继续并将 foo (4) 的修改时间与 baz< 的修改时间进行比较/代码> (6)。由于 baz 较新,make 将决定必须重建 foo,并将停止检查 foo 的先决条件(所以 boo 永远不会被检查)。

如果输出目标有多个依赖行,如下所示:

foo: bar baz
foo: boo

第二个和后续依赖行中的先决条件只是附加到输出目标的先决条件列表的末尾 - 也就是说,此示例完全等同于上面的第一个例子。

一般来说,所有 make 变体都以这种方式运行,尽管某些变体具有修改此行为的扩展(例如,GNU make 包括仅订单先决条件;Sun make 具有“保持状态”功能;等等)。

make first gets the modification time of the target, then compares that value to the modification time of each prereq, in order from left to right, stopping as soon as it finds any prereq that is newer than the target (since a single newer prereq is sufficient to require the target be rebuilt).

For example, suppose you have a rule like this:

foo: bar baz boo

Further, suppose that the modification times on these files are as follows:

foo: 4
bar: 3
baz: 6
boo: 2

In this case, make will compare the modification time of foo (4) to the modification time of bar (3); since bar is older, make will move on and compare the modification time of foo (4) to the modification time of baz (6). Since baz is newer, make will decide that foo must be rebuilt, and will stop checking the prereqs of foo (so boo will never be checked).

If you have multiple dependency lines for the output target, as in:

foo: bar baz
foo: boo

The prereqs in the second and subsequent dependency lines are simply appended to the end of the list of prereqs for the output target -- that is, this example is exactly equivalent to the first example above.

In general, all make variants behave this way, although some variants have extensions that modify this behavior (for example, GNU make includes order-only prerequisites; Sun make has "keep state" features; etc).

你与昨日 2024-09-06 21:27:59

Unix make 有相当复杂的推理规则来确定目标是否需要重建。对于 GNU make,您可以通过在没有 Makefile 的目录中运行“make -p”来转储它们。

规则也可以链接起来,更多解释是 这里

标准 Unix make 和 Microsoft nmake 的工作方式类似

Unix make has pretty complicated inference rules to determine if the target needs to be rebuilt. For GNU make you can dump them by running 'make -p' in a directory that doesn't have a Makefile.

Also the rules could be chained, more explanation about it is here

Standard Unix make and Microsoft nmake work in similar fashion

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文