简体   繁体   English

如果 Makefile 更改,则自动生成源文件

[英]Automake rebuild source file if Makefile changes

When using an autoconf/automake build system if the compiler flags or other variables in a Makefile.am (or even higher level like configure.ac) change, the C++ source files associated with that Makefile will not be automatically rebuilt.使用 autoconf/automake 构建系统时,如果 Makefile.am(或更高级别,如 configure.ac)中的编译器标志或其他变量发生更改,则与该 ZB67911656EF5D18C4AE36CB6741 关联的源文件不会自动重建。 This becomes especially important as we use automake as part of a continuous build system that only recompiles as needed.这变得尤为重要,因为我们将 automake 用作仅根据需要重新编译的持续构建系统的一部分。

My thought was to include Makefile as a dependency for the.o files which would theoretically solve the above issue.我的想法是包含 Makefile 作为 .o 文件的依赖项,理论上可以解决上述问题。 So a couple of questions:所以有几个问题:

First, is it possible to add a rule like that?首先,是否可以添加这样的规则? I would prefer to not have to add that custom rule to every single Makefile.am, so something that could be placed into a top-level file (like configure.ac) would be great.我宁愿不必将自定义规则添加到每个 Makefile.am 中,因此可以放入顶级文件(如 configure.ac)的东西会很棒。

Second, the downside to this approach is that in some cases the change to the Makefile did not actually affect the compilation so I will end up rebuilding when it is not really needed.其次,这种方法的缺点是在某些情况下,对 Makefile 的更改实际上并没有影响编译,所以我最终会在不需要时重新构建。 I guess I'm willing to live with this (or at least try it to see how painful it is) to have a better guarantee that my builds will be correct, but is there a better way to solve this problem?我想我愿意忍受这个(或者至少尝试一下看看它有多痛苦),以便更好地保证我的构建是正确的,但是有没有更好的方法来解决这个问题? I believe clearmake solves this by saving the actual compiler command (along with other dependencies) then comparing the current command with the previous to determine if a file needs to be regenerated.我相信 clearmake 通过保存实际的编译器命令(以及其他依赖项)然后将当前命令与之前的命令进行比较以确定是否需要重新生成文件来解决这个问题。

If you use ccache ( ./configure CXX='ccache g++' , or just add ccache's g++ to the path), spurious rebuilds should be very cheap and still safe.如果您使用 ccache ( ./configure CXX='ccache g++' ,或者只是将 ccache 的 g++ 添加到路径中),虚假重建应该非常便宜并且仍然安全。 Also make sure never to use the AM_MAINTAINER_MODE autoconf macro, which makes dependency tracking optional (conditional on the --enable-maintainer-mode flag).还要确保永远不要使用AM_MAINTAINER_MODE autoconf 宏,它使依赖项跟踪成为可选(以 --enable-maintainer-mode 标志为条件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM