2014-04-04 27 views
1

是否有任何方法将变量传递给AC_INIT? 如在AC_INIT中使用变量

VERSION = 0.1 
AC_INIT([my_package],$VERSION) 
+0

可能重复(http://stackoverflow.com/questions/8559456/read-a-version-number-from-a-file-in-configure-ac) – ldav1s

回答

6

从手册:

The arguments of 'AC_INIT' must be static, i.e., there should not be any shell computation, quotes, or newlines, but they can be computed by M4. This is because the package information strings are expanded at M4 time into several contexts, and must give the same text at shell time whether used in single-quoted strings, double-quoted strings, quoted here-documents, or unquoted here-documents. It is permissible to use 'm4_esyscmd' or 'm4_esyscmd_s' for computing a version string that changes with every commit to a version control system (in fact, Autoconf does just that, for all builds of the development tree made between releases).

这是autoconf的(目前)使用:

AC_INIT([GNU Autoconf], 
    m4_esyscmd([build-aux/git-version-gen .tarball-version]), 
    [[email protected]]) 

如果你不需要从外部来源读取的版本,这里是GLIB使用的:

m4_define([glib_major_version], [2]) 
m4_define([glib_minor_version], [41]) 
m4_define([glib_micro_version], [0]) 
... 
m4_define([glib_version], 
     [glib_major_version.glib_minor_version.glib_micro_version]) 

... 
AC_INIT(glib, [glib_version], ...) 

当然,你将不得不使用M4构建,而不是外壳,像m4_if()m4_eval()

的[在configure.ac文件中读到的版本号]
+0

对于任何获得“错误:应该使用包和版本参数调用AC_INIT”的人,我能够使其工作通过将m4_esyscmd放在方括号中。 另外,如果您碰巧在最后使用“回显”脚本获取版本号,请务必使用“-ne”。我的配置脚本对版本字符串中的换行符不满意! – jonthalpy