autotools - 在 AC_INIT 中使用变量

标签 autotools

有什么方法可以将变量传递给AC_INIT吗? 例如

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

最佳答案

来自手册:

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]),
    [bug-autoconf@gnu.org])

如果您不需要从外部源读取版本,则 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 结构而不是 shell,例如 m4_if()m4_eval() 等。

关于autotools - 在 AC_INIT 中使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22871340/

相关文章:

autotools - autoreconf 出现错误 : required file './test-driver' not found

c++ - 在 AC_CHECK_HEADER 不改变预处理器之前改变编译器

Autotools:top_srcdir 和 abs_top_srcdir 为空

gcc - 如何使用用于 armv5tel 的 GNU 自动工具进行交叉编译?

autotools - libtool automake:用静态链接破坏LIBADD吗?

c++11 - 打包C++11程序源码的可移植方法

autotools - 如何在子包设置中传播 automake 变量?

autotools - 如何使用autoconf创建安装目录变量?

environment-variables - 将环境变量传递给 autoconf 的 `./configure`

ios - 如何为基于 autotool 的项目启用特定于 Xcode 的构建标志