Differences between revisions 10 and 12 (spanning 2 versions)
Revision 10 as of 2010-01-26 13:06:58
Size: 2270
Comment:
Revision 12 as of 2010-01-28 13:01:59
Size: 2268
Comment:
Deletions are marked like this. Additions are marked like this.
Line 18: Line 18:
version.c: hgstamp version.o: hgstamp
Line 30: Line 30:
HGVERSION:= $(shell hg -R $(top_builddir) parents --template 'hgid: {node|short}' 2> /dev/null || grep node $(top_srcdir)/.hg_archival.txt 2> /dev/null || true ) HGVERSION:= $(shell hg -R $(top_srcdir) parents --template 'hgid: {node|short}' 2> /dev/null || grep node $(top_srcdir)/.hg_archival.txt 2> /dev/null || true )
Line 33: Line 33:
version.c: hgstamp version.o: hgstamp

Simple

Add the following line to your Makefile

HGVERSION:= $(shell hg parents --template 'hgid: {node|short}')

and

-DHGVERSION="\"${HGVERSION}\""

to your CPPFLAGS. Now one can use the define HGVERSION inside the code.

Rebuild files using HGVERSION

Make rebuilds targets only if one of the dependencies is newer. That means even if the version has changed, due to a change somewhere, files using HGVERSION will not be rebuild automatically. To overcome this add new dependency in the Makefile to updated these files:

version.o: hgstamp
hgstamp: update_hgstamp
update_hgstamp:
        [ -f hgstamp ] || touch hgstamp
        echo $(HGVERSION) | cmp -s hgstamp - || echo $(HGVERSION) > hgstamp

In this example version.c depend has the extra dependency hgstamp, which is generated by the rule 'update_hgstamp'. This rule updates hgstamp if and only if the version has really changed.

Autotools

If you are using automake add the following lines to your Makefile.am

HGVERSION:= $(shell hg -R $(top_srcdir) parents --template 'hgid: {node|short}' 2> /dev/null || grep node $(top_srcdir)/.hg_archival.txt 2> /dev/null || true )
AM_CPPFLAGS = -DHGVERSION="\"${HGVERSION}\""

version.o: hgstamp
hgstamp: update_hgstamp
update_hgstamp:
        [ -f hgstamp ] || touch hgstamp
        echo $(HGVERSION) | cmp -s hgstamp - || echo $(HGVERSION) > hgstamp

The definition of HGVERSION is more robust here. It tries to get the version in the following order

  • hg parents, the -R option is added to prevent hg to search in lower directories in the case we don't have a repository
  • grabbing it from .hg_archival.txt, in case we are using a tarball made by hg archive
  • undefined

LaTeX

Just a add the following lines to your Makefile

HGID:=$(shell hg parents -R . --template "{node|short}" | sed 's/.*/\\renewcommand{\\hgid}{&}/')
hgid.tex: update_hgid
update_hgid:
        [ -f hgid.tex ] || touch hgid.tex
        echo '$(HGID)' | cmp -s hgid.tex - || echo '$(HGID)' > hgid.tex

and this lines to your main tex file

\newcommand{\hgid}{null}
\input{hgid}

now one can use the command \hgid to get the version everywhere.


CategoryHowTo

VersioningWithMake (last edited 2015-08-10 06:26:49 by follower)