[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: revision control info in generated files

From: Jef Driesen
Subject: Re: revision control info in generated files
Date: Mon, 12 Apr 2010 14:39:59 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20100217 Lightning/1.0pre Shredder/3.0.3pre

On 02/04/10 14:37, Peter Johansson wrote:
On 4/2/10 7:04 AM, Jef Driesen wrote:

The problem I'm trying to solve is that I already have a version.h
that is generated from a template that contains:


I would extend to also have a line


and use sed to generate version.h from where you replace
@MYLIB_VERSION@ with values you already have AC_SUBSTed into Makefile
and MYLIB_SVN_REVISION is replaced with content of
$(top_srcdir)/.svn_revision. It might help to look at how Autoconf
creates autoheader et al. from *.in files using edit.

I now have

version.h: $(srcdir)/version
   $(AM_V_GEN) sed \
      -e 's/address@hidden@/@MYLIB_VERSION_MAJOR@/' \
      -e 's/address@hidden@/@MYLIB_VERSION_MINOR@/' \
      -e 's/address@hidden@/@MYLIB_VERSION_MICRO@/' \
      -e 's/address@hidden@/'`cat $(srcdir)/version`'/' \
      $(srcdir)/ > $@

mylib_la_SOURCES += version.c
mylib_HEADERS += version.h

BUILT_SOURCES = version.h
EXTRA_DIST += $(srcdir)/version
CLEANFILES += version-t

Took me a while to figure out the escaping of the @ symbol. It seems to work fine, except that I would like to add "$(srcdir)/" as a dependency for "version.h". But when I add that, make distcheck fails and I don't know why.

The error I get is:

make[3]: *** No rule to make target `../../src/', needed by `version.h'. Stop.

I also have a corresponding version.c file that has the same info, but
for use at runtime:

#include "version.h
const int mylib_version_major = MYLIB_VERSION_MAJOR;
const int mylib_version_minor = MYLIB_VERSION_MINOR;
const int mylib_version_micro = MYLIB_VERSION_MICRO;

This should not be a problem when you have the generated version.h. You
can just use the defines from version.h. The tricky thing is that will not compile if version.h is not present (not generated
yet), so you need to have a dependency that version.h needs to be
generated before version.o is created.
Read the section 9.4 in Automake manual that explains the details clearly

The line

BUILT_SOURCES = version.h

should take care of that, not?

(Or with functions to avoid the problem of exporting variables from
Windows DLL, but that's not relevant here.)

It would be nice if I could get the revision info into the same file,
so related stuff is not spread over different files. No big deal if
that is not possible, but I also have other files where I could use
the revision info. For instance on windows I have a resource file
(*.rc) with version info. I can probably solve that by generating a
short version-revision.h file and include that.

It is a good idea to store the revision in a separate file, e.g.,

It makes it easy to parse out that info and propagate to other places,
and if you use the rule described by Ralf the time-stamp of this file
will only change when the content needs to be changed, so you can have
files depending on that time-stamp.

I now have a slightly modified version of Ralf' rule:

$(srcdir)/version: FORCE
   @if (test -d $(top_srcdir)/.git && cd $(srcdir) \
        && git rev-parse --verify HEAD ) > version-t 2>/dev/null \
     && ! cmp -s version-t $@; then \
     mv -f version-t $@; \
   else \
     rm -f version-t; \
     if ! test -f $@; then touch $@; fi; \

reply via email to

[Prev in Thread] Current Thread [Next in Thread]