Auto-compiling in the bzr and git version info:
It's nice to know what version of the repository (and cflags etc.) a library and program were compiled with, perticularly when recording this info in a log file for data provenance. Unfortunately, $Id$ doesn't work in much outside of CVS (and perhaps SVN?).
The following Makefile.am/make snippets will make this possible. They assume GNU make, but are likely transferable. This may easily be extended for other DVCSes. Please note that line wrapping has been enabled here!
Makefile.am
CLEANFILES += program_version.c program_version_core.c FORCE: program_version.c: program_version_core.c FORCE /bin/echo '#define PREFIXED_SYMBOL(a) program_ ## a' > program_version.c /bin/echo '#define SECTION "program"' >> program_version.c /bin/cat program_version_core.c >> program_version.c program_version_core.c: FORCE /bin/echo '#include <stdio.h>' > program_version_core.c /bin/echo '#define str(s) #s' >> program_version_core.c /bin/echo '#define xstr(s) str(s)' >> program_version_core.c /bin/echo -n 'char *PREFIXED_SYMBOL(version_info) = "' >> program_version_core.c if [ -d ".bzr" ]; then bzr version-info; elif [ -d ".git" ]; then git rev-parse HEAD; else echo 'Unable to get repository version information; unknown {D,}VCS.'; fi | perl -ne 'comp; chomp; print; print "\\n";' >> program_version_core.c echo '";' >> program_version_core.c /bin/echo 'char* PREFIXED_SYMBOL(cflags)="'$(CFLAGS)'";' >> program_version_core.c /bin/echo 'char* PREFIXED_SYMBOL(cxxflags)="'$(CXXFLAGS)'";' >> program_version_core.c /bin/echo 'char* PREFIXED_SYMBOL(fflags)="'$(FFLAGS)'";' >> program_version_core.c /bin/echo 'char* PREFIXED_SYMBOL(ldflags)="'$(LDFLAGS)'";' >> program_version_core.c /bin/echo 'char* PREFIXED_SYMBOL(buildscript_host)="'"$(BUILDSCRIPT_HOST)"'";' >> program_version_core.c /bin/echo 'char* PREFIXED_SYMBOL(buildscript_target)="'"$(BUILDSCRIPT_TARGET)"'";' >> program_version_core.c /bin/echo 'char* PREFIXED_SYMBOL(buildscript_buildtype)="'"$(BUILDSCRIPT_BUILDTYPE)"'";' >> program_version_core.c /bin/echo 'char* PREFIXED_SYMBOL(buildscript_configargs)="'"$(BUILDSCRIPT_CONFIGARGS)"'";' >> program_version_core.c /bin/echo 'char* PREFIXED_SYMBOL(buildscript_installdir)="'"$(BUILDSCRIPT_INSTALLDIR)"'";' >> program_version_core.c /bin/echo 'void PREFIXED_SYMBOL(print_version)(FILE* f) {' >> program_version_core.c /bin/echo 'fprintf(f, "***BEGIN %s VERSION INFORMATION***\n", SECTION);' >> program_version_core.c for item in version_info cflags cxxflags fflags ldflags buildscript_host buildscript_target buildscript_buildtype buildscript_configargs buildscript_installdir; do /bin/echo 'fprintf(f, "\t%s_'$$item'))=%s\n", SECTION, PREFIXED_SYMBOL('$$item'));' >> program_version_core.c; done /bin/echo 'fprintf(f, "***END %s VERSION INFORMATION***\n", SECTION);' >> program_version_core.c /bin/echo '}' >> program_version_core.c
Template for a library:
CLEANFILES += $(libname)_program_version $(libname)_version.c: program_version_core.c FORCE /bin/echo '#define PREFIXED_SYMBOL(a) $(libname)_ ## a' > $(libname)_version.c /bin/echo '#define SECTION "$(libname)"' >> $(libname)_version.c /bin/cat program_version_core.c >> $(libname)_version.c
Page last modified Thursday, 18-Feb-2010 16:22:16 EST