Reputation: 6312
How can I assign a dynamic, git-based version number to an autoconf project? Autoconf requires a static string argument to
AC_INIT([Title],[version],[name])
AC_INIT documentation says that one can use M4 to supply a shell-based version. M4 is beyond my ken. I'd like to version my software according to the results of this command
version=`git describe --abbrev=7 --dirty --always --tags`
This produces something like 4.6.6-alpha07-9-ga3e01a8
.
I may not understand high level answers. I need a solution like "cut and paste this into your autoconf.ac and/or acinclude.m4".
Any help appreciated.
Upvotes: 7
Views: 1019
Reputation: 37767
Just running git describe
in m4_esyscmd
for the AC_INIT
version still leaves a few things to be desired:
What version to use if you build a dist tarball?
There is no git describe
useful output to be had here at all.
What version to use if you have just committed a change?
Do you update the configure
version from git describe
,
or just continue to build with the existing version?
For my own packages (such as ndim-utils), I have solved these issues (and a few more) by
Having a special build-helpers/package-version
script which determines the version to use from a version-stamp
file if found, or git describe
. configure.ac
AC_INIT
will m4_esyscmd
that script.
Having a special build-helpers/package-version.mk
to include from the top-level Makefile.am
which generates a version-stamp
file for dist tarballs, checks whether the current git describe
output differs from what configure
has stored, and a few other things.
Having a GNUmakefile.in
which updates the version stored in configure
internals from git describe
when necessary.
And I probably have forgotten a few issues addressed in that solution.
I am not certain that those scripts are ready to just copy over to your project, but I wanted to mention here that there are a few more things to consider.
Upvotes: 7
Reputation: 16305
How about:
AC_INIT([Title], [m4_esyscmd_s([git describe --abbrev=7 --dirty --always --tags])])
should work for you.
Upvotes: 9