有什么方法可以将变量传递给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/