2014-06-10 58 views
0

我需要聲明一個變量作爲命令的輸出。 我試着用:在configure.ac中定義一個變量作爲命令的輸出

AC_DEFINE_UNQUOTED([SVN_REV], ["$(shell svnversion -n .)"], [Define svn revision number]) 

和config.h中我發現:

#define SVN_REV "" 

如果我嘗試:

AC_DEFINE([SVN_REV], ["$(shell svnversion -n .)"], [Define svn revision number]) 

config.h中有:

#define SVN_REV "$(shell svnversion -n .)" 

如何讓SVN_REV定義爲在config.h中正確的值?

問候

回答

1

我不認爲你可以做你彷彿獨自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_PROGsvnversion二進制文件(或類似的東西):

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`\" ... 
+0

我如何可以移動的版本東西在Makefile.am?我嘗試沒有成功。 – mastupristi

相關問題