make 如何决定构建目标
一个迹象是目标不存在,请理解这一点。
另一种方法是比较目标和先决条件的修改时间戳。更详细地讲它是如何工作的?比较目标时间戳和先决条件时间戳的逻辑是什么?当存在多个先决条件时它如何工作?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
make
首先获取目标的修改时间,然后将该值与每个 prereq 的修改时间进行比较,按照从左到右的顺序,一旦发现任何比目标更新的 prereq 就停止(因为单个较新的先决条件足以要求重建目标)。例如,假设您有这样的规则:
此外,假设这些文件的修改时间如下:
在这种情况下,
make
将比较foo (4) 到
bar
(3)的修改时间;由于bar
较旧,make
将继续并将foo
(4) 的修改时间与baz< 的修改时间进行比较/代码> (6)。由于
baz
较新,make
将决定必须重建foo
,并将停止检查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:
Further, suppose that the modification times on these files are as follows:
In this case,
make
will compare the modification time offoo
(4) to the modification time ofbar
(3); sincebar
is older,make
will move on and compare the modification time offoo
(4) to the modification time ofbaz
(6). Sincebaz
is newer,make
will decide thatfoo
must be rebuilt, and will stop checking the prereqs offoo
(soboo
will never be checked).If you have multiple dependency lines for the output target, as in:
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).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