为什么`make`的结果不能在多台计算机之间共享?

huangapple go评论62阅读模式
英文:

Why can't the result of make be shared across computers

问题

第一个问题是:为什么第二次运行时速度更快?

第二个问题是:为什么在将整个目录传输到另一台计算机之后(在已构建 make 后),make 命令仍然需要 4 小时才能完成,而不是 5-10 分钟?

英文:

I have a legacy work project which consists of 8000+ files. It includes the source code but also libraries so it can run independently.

However, when I run the make command the first time it takes roughly 4 hours, as opposed to executing the command the second time, after code additions, which is a lot faster and usually takes 5-10 minutes.
My first question is why is it faster the second time around?

Secondly, how come when the entire directory is transferred (after make has been built) to a different computer that the make command still takes 4 hours to complete and not 5-10 minutes?

答案1

得分: 5

GNU make的主要目的是编译代码,而且在没有更改代码的情况下进行编译。事实上,man make在描述的第一句话中就明确说明了:

make实用程序的目的是自动确定需要重新编译大型程序的哪些部分,并发出重新编译它们的命令。

再往下一点:

如果目标依赖于自上次修改目标以来已被修改的先决文件,或者如果目标不存在,make会更新目标。

这基本上解释了第二次以及后续编译的加速。不是一切都重新编译,而只有受代码更改影响的项目部分。

当你将源代码(和构建生成物)复制到另一台计算机时,修改时间很可能会不同。这会导致make重新编译所有内容。为防止这种情况发生,需要在复制时保留时间戳。

英文:

The main purpose of GNU make is to compile code and do so without recompiling code without changes. In fact, man make states right in the first sentence of the description:

> The purpose of the make utility is to determine automatically which pieces of a large program need to be recompiled, and issue the commands to recompile them.

and a little bit further down:

> make updates a target if it depends on prerequisite files that have been modified since the target was last modified, or if the target does not exist.

This pretty much explains the speedup on second and following compilations. Not everything is compiled but only the parts of the project affected by the code changes.

When you copy your source code (and build artifacts) to another computer, the modification times will most likely be off. This will cause make to recompile everything. To prevent this from happening, preserve the time stamps when copying.

huangapple
  • 本文由 发表于 2023年3月15日 19:47:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75744284.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定