[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: Wed, 31 Mar 2010 14:49:48 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20100217 Lightning/1.0pre Shredder/3.0.3pre

On 30/03/10 20:57, Ralf Wildenhues wrote:
* 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

Is FORCE some special built-in name (like .PHONY)? Or is just a random name for an "empty" target (e.g. one that depends on nothing and does nothing).

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

Sure. I use both git and subversion, and this are the commands I would use to retrieve the revision info:

git rev-parse --quiet --verify HEAD

The svnversion command is a little tricky because it does not fail when run outside a subversion tree.

$(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

I think I understand what's going on, except for a few little things:

Why the depencency on I assume it has something to do with that FORCE target?

Why do you add the .git-version-t file to CLEANFILES if it gets removed in the script?

And last but not least I'm using VPATH builds to build my code for multiple platforms from the same source directory. Shouldn't the .git-version file be created inside the build directory, rather than the source directory?

reply via email to

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