[Top][All Lists]

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

revision control info in generated files (was: Public header files)

From: Ralf Wildenhues
Subject: revision control info in generated files (was: Public header files)
Date: Tue, 30 Mar 2010 20:57:03 +0200
User-agent: Mutt/1.5.20 (2009-10-28)

* Jef Driesen wrote on Wed, Mar 17, 2010 at 01:23:09PM CET:
> On 16/03/2010 14:22, Peter Johansson wrote:
> >Which method to use depends on where you want the MY_REVISION_VERSION to
> >propagate. Do you need it in any Makefiles, e.g., or do you only need it
> >compiled into your program.
> I only need it compiled into my library. The goal is that an
> application using my library can report the exact revision of the
> library (for diagnostic purpose).
> With the solution I outlined in my previous posts, I can already get
> the "normal" version info (e.g. the major.minor.micro numbers) into
> a public header file to allow for compile time version checking.
> Runtime version checking can easily be achieved by adding a
> mylib_get_version() function to the library. But when building not
> yet released code, it's more useful to know the exact SCM revision,
> rather than the version numbers.

FWIW, below is what I use in my own projects.  I use git exclusively as
SCM, and I am fine with VERSION being stable for a long time, and I
don't care about finer version information in configure.

There is a point to using FORCE over .PHONY: were you to mark
$(srcdir)/.git-version as phony, then the compilation of version.c would
always be emitted by 'make', even if the .git-version fils is up to

Older git versions don't support 'describe --dirty', thus the fallback
without --dirty.

Hope that helps.  I'm sure you can easily adapt this to the SCM of your


$(srcdir)/.git-version: FORCE
        @if (test -d $(top_srcdir)/.git && cd $(srcdir) \
             && { git describe --dirty || git describe; } ) > .git-version-t 
2>/dev/null \
          && ! diff .git-version-t $@ >/dev/null 2>&1; then \
          mv -f .git-version-t $@; \
        else \
          rm -f .git-version-t; \
          if test -f $@; then :; else touch $@; fi; \

EXTRA_DIST = $(srcdir)/.git-version
CLEANFILES = .git-version-t

version.c: $(srcdir)/.git-version
        echo "const char foo_version[] = \""`cat $(srcdir)/.git-version`"\";" > 

foo_SOURCES += version.c

reply via email to

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