automake
[Top][All Lists]
Advanced

[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:1.9.1.9pre) 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 version.h.in template that contains:

#define MYLIB_VERSION_MAJOR @MYLIB_VERSION_MAJOR@
#define MYLIB_VERSION_MINOR @MYLIB_VERSION_MINOR@
#define MYLIB_VERSION_MICRO @MYLIB_VERSION_MICRO@

I would extend version.h.in to also have a line

#define MYLIB_SVN_REVISION @MYLIB_SVN_REVISION@

and use sed to generate version.h from version.h.in 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.

http://www.gnu.org/software/autoconf/manual/autoconf.html#Installation-Directory-Variables

I now have

version.h: $(srcdir)/version Makefile.am
   $(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)/version.h.in > $@

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)/version.h.in" 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/version.h.in', 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
version.cc 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

http://sources.redhat.com/automake/automake.html#Sources

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.,
$(top_srcdir)/.svn_revision

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:

FORCE:
$(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; \
   fi





reply via email to

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