2242
Comment:
|
2298
Fix typos
|
Deletions are marked like this. | Additions are marked like this. |
Line 2: | Line 2: |
Add the following line to your Makefile | |
Line 3: | Line 4: |
Add the following line to your Makefile | |
Line 5: | Line 5: |
HGVERSION:= $(shell hg parents --template 'hgid: {node|short}' | HGVERSION:= $(shell hg parents --template 'hgid: {node|short}') |
Line 8: | Line 8: |
Line 14: | Line 15: |
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: | 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 rebuilt automatically. To overcome this, add a new dependency in the Makefile to update these files: |
Line 16: | Line 18: |
version.cc: hgstamp hgstamp: update_hgstamp update_hgstamp: [ -f hgstamp ] || touch hgstamp echo $(HGVERSION) | cmp -s hgstamp - || echo $(HGVERSION) > hgstamp |
version.o: hgstamp .PHONY: hgstamp hgstamp: [ -f $@ ] || touch $@ echo $(HGVERSION) | cmp -s $@ - || echo $(HGVERSION) > $@ |
Line 22: | Line 24: |
In this example version.cc 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 ''realy'' changed. | In this example version.o has the extra dependency hgstamp. The hgstamp rule updates hgstamp if and only if the version has ''really'' changed. To make sure the hgstamp rule will be executed every time, hgstamp is a phony target (see [[http://www.gnu.org/software/make/manual/html_node/Phony-Targets.html|make manual]]). |
Line 25: | Line 28: |
If you are using automake add the following lines to your Makefile.am | If you are using automake add the following lines to your Makefile.am: |
Line 27: | Line 31: |
HGVERSION:= $(shell hg -R $(top_builddir) parents --template 'hgid: {node|short}' 2> /dev/null || grep node $(top_builddir)/.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 30: | Line 34: |
version.cc: hgstamp hgstamp: update_hgstamp update_hgstamp: [ -f hgstamp ] || touch hgstamp echo $(HGVERSION) | cmp -s hgstamp - || echo $(HGVERSION) > hgstamp |
version.o: hgstamp .PHONY: hgstamp hgstamp: [ -f $@ ] || touch $@ echo $(HGVERSION) | cmp -s $@ - || echo $(HGVERSION) > $@ |
Line 38: | Line 42: |
* hg parents, the -R optionpw is added to prevent hg to search in lower directories in the case we don't have a repository | * hg parents, the -R option is added to prevent hg from searching in lower directories in case we don't have a repository |
Line 43: | Line 47: |
Just a add the following lines to your Makefile | Just add the following lines to your Makefile |
Line 46: | Line 51: |
hgid.tex: update_hgid update_hgid: [ -f hgid.tex ] || touch hgid.tex echo '$(HGID)' | cmp -s hgid.tex - || echo '$(HGID)' > hgid.tex |
.PHONY: hgstamp hgid.tex: [ -f $@ ] || touch $@ echo '$(HGID)' | cmp -s $@ - || echo '$(HGID)' > $@ |
Line 51: | Line 56: |
and this lines to your main tex file | and this lines to your main tex file: |
Line 56: | Line 62: |
now one can use the command \hgid to get the version everywhere. | Now one can use the command \hgid to get the version everywhere. ---- CategoryHowTo |
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 rebuilt automatically. To overcome this, add a new dependency in the Makefile to update these files:
version.o: hgstamp .PHONY: hgstamp hgstamp: [ -f $@ ] || touch $@ echo $(HGVERSION) | cmp -s $@ - || echo $(HGVERSION) > $@
In this example version.o has the extra dependency hgstamp. The hgstamp rule updates hgstamp if and only if the version has really changed. To make sure the hgstamp rule will be executed every time, hgstamp is a phony target (see make manual).
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 .PHONY: hgstamp hgstamp: [ -f $@ ] || touch $@ echo $(HGVERSION) | cmp -s $@ - || echo $(HGVERSION) > $@
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 from searching in lower directories in 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 add the following lines to your Makefile
HGID:=$(shell hg parents -R . --template "{node|short}" | sed 's/.*/\\renewcommand{\\hgid}{&}/') .PHONY: hgstamp hgid.tex: [ -f $@ ] || touch $@ echo '$(HGID)' | cmp -s $@ - || echo '$(HGID)' > $@
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.