Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a variable in AC_INIT

Tags:

autotools

Is there any way to pass in a variable to AC_INIT? eg

VERSION = 0.1
AC_INIT([my_package],$VERSION)
like image 850
Mouse.The.Lucky.Dog Avatar asked Apr 04 '14 19:04

Mouse.The.Lucky.Dog


1 Answers

From the manual:

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).

This is what autoconf (currently) uses:

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

If you don't need to read the version from an outside source, here's what GLIB uses:

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], ...)

Of course, you will have to use M4 constructs instead of shell, like m4_if(), m4_eval(), etc.

like image 161
DanielKO Avatar answered Sep 30 '22 04:09

DanielKO