我不認爲你可以做你彷彿獨自configure.ac
想。此代碼:
$(shell svnversion -n .)
似乎是在make
實際運行時。當configure
調用AC_OUTPUT
時,您所有AC_DEFINE
s被寫入config.h
。這是之前make
,所以當時寫入的任何內容都不會在make
環境中。您可以在configure
環境中運行以下命令:
SVNVERSION_REV=`svnversion -n .`
AC_DEFINE_UNQUOTED([SVN_REV],
["$SVNVERSION_REV"],
[Define svn revision number])
具有幾乎相同的效果。雖然版本號會很容易過時(例如修改文件並在configure
之後提交)。解決方案是從Makefile.am
驅動所有版本的東西,而不是configure.ac
。
將該版本信息獲取到自動工具中有點棘手。以下是我用來將一個Subversion版本插入到.spec文件中的一些內容。
首先我抓住使用AX_WITH_PROG的svnversion
二進制文件(或類似的東西):
configure.ac
# check for svnversion (not required, except for the maintainer)
AX_WITH_PROG([SVNVERSION], [svnversion])
Makefile.am
# copy svnstamp to svn-revision
# if svn-revision non-existent or svnstamp is newer
svn-revision : $(top_builddir)/svnstamp
if test ! -f [email protected] -o $< -nt [email protected]; then \
cp $< [email protected]; \
fi
# always do this check to avoid staleness
.PHONY : svnstamp_
# This is supposed to do nothing
# all the work to create this file is in svnstamp_
$(top_builddir)/svnstamp : svnstamp_
@/bin/true
# run the command only if the codebase is a svn working copy
# I've taken out the RPM related strings so you might be able
# to plug it into your code more easily
svnstamp_ :
if test -d $(top_srcdir)/.svn ; then \
SVN_VERSION_STAMP=`$(SVNVERSION) $(top_srcdir) -n`; \
NEW_STAMP=`echo -n "$$SVN_VERSION_STAMP"`; \
if test ! -f $(top_builddir)/svnstamp; then \
echo "$$NEW_STAMP" > $(top_builddir)/svnstamp; \
else \
OLD_STAMP=`cat $(top_builddir)/svnstamp`; \
if test "$$OLD_STAMP" != "$$NEW_STAMP" ; then \
echo "$$NEW_STAMP" > $(top_builddir)/svnstamp; \
fi \
fi \
else \
if test ! -f $(top_builddir)/svnstamp \
-o $(top_srcdir)/svn-revision \
-nt $(top_builddir)/svnstamp; then \
cp $(top_srcdir)/svn-revision $(top_builddir)/svnstamp; \
fi \
fi; \
NEW_STAMP=`cat $(top_builddir)/svnstamp`; \
if test "x$$NEW_STAMP" = "x"; then \
echo " Failed to make svnstamp"; \
exit 1; \
fi
爲了爲需要該版本的翻譯單位執行此操作郵票,你需要讓他們的svn-revision
依賴和做類似的構建步驟如下:
... -DSVN_REV=\"`cat svn-revision`\" ...
我如何可以移動的版本東西在Makefile.am?我嘗試沒有成功。 – mastupristi