* 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 date. 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 choice. Cheers, Ralf FORCE: $(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; \ fi EXTRA_DIST = $(srcdir)/.git-version CLEANFILES = .git-version-t version.c: $(srcdir)/.git-version Makefile.am echo "const char foo_version[] = \""`cat $(srcdir)/.git-version`"\";" > $@ foo_SOURCES += version.c