问题描述
我试图将我的Subversion版本号嵌入C ++项目中,并且在设置GNU make这样做时遇到问题.我的makefile当前看起来像这样:
I'm trying to embed my Subversion revision number in a C++ project and am having problems setting up GNU make to do so. My makefile currently looks something like this:
check-svnversion:
../shared/update-svnversion-h.pl
../shared/svnversion.h: check-svnversion
shared/svnversion.o: ../shared/svnversion.h
.PHONY: check-svnversion
svnversion.o
取决于 svnversion.cpp
(通过模式规则)和 svnversion.h
(明确列出,因为依赖项检查不是)t由于某种原因将其捡起). svnversion.h
是由 update-svnversion-h.pl
脚本创建和维护的(该脚本基本上只运行 svnversion
并将其输出为C ++文件).
svnversion.o
depends on svnversion.cpp
(via a pattern rule) and svnversion.h
(listed explicitly because dependency checking isn't picking it up for some reason). svnversion.h
is created and maintained by the update-svnversion-h.pl
script (which basically just runs svnversion
and munges the output into a C++ file).
当前,我必须运行两次 make
才能使文件保持最新状态.第一次, make
运行 update-svnversion-h.pl
(因为它已被列为先决条件),但不检查 svnversion.h的时间戳之后查看code> update-svnversion-h.pl
对其进行了更改,因此它不会重新制作 svnversion.o
.第二次,它确实检查时间戳,无论如何都运行 update-svnversion-h.pl
(由于 svnversion.h
日期),然后重新编译 svnversion.cpp
以创建 svnversion.o
.
Currently, I have to run make
twice to get the file up to date. The first time, make
runs update-svnversion-h.pl
(since it's listed as a prerequisite) but does not check the timestamp of svnversion.h
afterwards to see that it was changed by update-svnversion-h.pl
, so it does not remake svnversion.o
. The second time, it does check the timestamp, runs update-svnversion-h.pl
anyway (which doesn't do anything this time, since svnversion.h
is up to date), then recompiles svnversion.cpp
to make svnversion.o
.
是否有一种方法可以告诉GNU make对一个必备组件进行两次评估,或者延迟检查必备组件的时间戳,直到该必备组件的命令执行完毕?
Is there a way to tell GNU make to evaluate a single prerequisite twice or to delay checking the timestamp on a prerequisite until after that prerequisite's commands are finished?
或者,是否有更好的方法在我的源代码中嵌入修订号?(为了提高速度,我正在尝试避免在每次构建时都需要重新编译的解决方案.)
Alternatively, is there a better way to embed a revision number in my source code? (For the sake of speed, I'm trying to avoid solutions that would require recompilation on every build.)
推荐答案
我通过使我的check-svnversion规则删除svnversion.o来解决此问题,以便在需要时强制对其进行重新编译.这并不完全优雅,但可以正常工作.它看起来与 CesarB的答案.
I solved this by having my check-svnversion rule delete svnversion.o to force it to be recompiled if needed. This isn't exactly elegant, but it works; it looks similar to the autotools solution described in CesarB's answer.
../shared/svnversion.h: check-svnversion
check-svnversion:
../shared/update-svnversion-h.pl
@#Force recreation of svnversion.o. Otherwise, make won't notice that
@#svnversion.h has changed until the next time it's invoked.
@if [ ../shared/svnversion.h -nt shared/svnversion.o ] ; then rm shared/svnversion.o ; fi
shared/svnversion.o: ../shared/svnversion.h
.PHONY: check-svnversion
这篇关于延迟或重复GNU make中的先决条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!