A corrected wiki example for use of HGVERSION with `make`.

follower follower at rancidbacon.com
Mon Aug 10 07:20:37 UTC 2015


Hi,

It seems for the past three years the wiki example for how to include
the current Mercurial repository revision number into software built
via make has been incorrect due to misuse of the ".PHONY" target
causing a rebuild every time. (See:
<https://mercurial.selenic.com/wiki/VersioningWithMake>)

The breaking change was made in Revision 14
(<https://mercurial.selenic.com/wiki/VersioningWithMake?action=diff&rev2=14&rev1=13>)
and my correction is Revision 18
(<https://mercurial.selenic.com/wiki/VersioningWithMake?action=diff&rev1=17&rev2=18>).
(Revision 13 is worth looking at for some historical context:
<https://mercurial.selenic.com/wiki/VersioningWithMake?action=diff&rev1=12&rev2=13>.)

I have also added further explanation of how the process works to
assist with understanding the correct operation. In addition, I
created a working demonstration here:
<https://bitbucket.org/follower/hgversion-handling> not least because
`make` is non-trivial to understand at the best of times, let alone in
this situation. :)

Verifying the correct initial operation can be achieved by:

  $ hg clone https://bitbucket.org/follower/hgversion-handling
  # [snip]
  $ cd hgversion-handling/
  $ make --debug
  GNU Make 3.81
  # [snip]
  Reading makefiles...
  Updating goal targets....
   File `version_example' does not exist.
     File `version_example.o' does not exist.
       File `hgstamp' does not exist.
         File `update_hgstamp' does not exist.
        Must remake target `update_hgstamp'.
        Successfully remade target file `update_hgstamp'.
      Must remake target `hgstamp'.
      Successfully remade target file `hgstamp'.
    Must remake target `version_example.o'.
  gcc -DHGVERSION="\"hgid: 51c22e5cef6d\""   -c -o version_example.o
version_example.c
    Successfully remade target file `version_example.o'.
  Must remake target `version_example'.
  gcc   version_example.o   -o version_example
  Successfully remade target file `version_example'.

  $ ./version_example
  My version is (hgid: 51c22e5cef6d) today.

Note the `version_example` binary was rebuilt as expected.

Now, verify correct operation with no change in revision:

  $ make --debug
  # [snip]
  Reading makefiles...
  Updating goal targets....
         File `update_hgstamp' does not exist.
        Must remake target `update_hgstamp'.
        Successfully remade target file `update_hgstamp'.
       Prerequisite `update_hgstamp' of target `hgstamp' does not exist.
      Must remake target `hgstamp'.
      Successfully remade target file `hgstamp'.

Note that `version_example` was not rebuilt.

Now, verify correct operation with a change in revision:

  $ hg tag -u me at example.com some-revision # Causes new revision
  $ make --debug
  # [snip]
  Reading makefiles...
  Updating goal targets....
         File `update_hgstamp' does not exist.
        Must remake target `update_hgstamp'.
        Successfully remade target file `update_hgstamp'.
       Prerequisite `update_hgstamp' of target `hgstamp' does not exist.
      Must remake target `hgstamp'.
      Successfully remade target file `hgstamp'.
     Prerequisite `hgstamp' is newer than target `version_example.o'.
    Must remake target `version_example.o'.
  gcc -DHGVERSION="\"hgid: e945c0a33221\""   -c -o version_example.o
version_example.c
    Successfully remade target file `version_example.o'.
   Prerequisite `version_example.o' is newer than target `version_example'.
   Prerequisite `version_example.o' is newer than target `version_example'.
  Must remake target `version_example'.
  gcc   version_example.o   -o version_example
  Successfully remade target file `version_example'.

  $ ./version_example
  My version is (hgid: e945c0a33221) today.

Note the `version_example` binary was rebuilt as expected.

I couldn't work out a way to have `make` treat `update_hgstamp` as
up-to-date when the revision had not changed so we never get the "X is
up to date" message but this is consistent with earlier working
examples AFAICT.

I discussed this on IRC and the recommendation was to make the change
on the wiki but also mention it on the mailing list so more eyes could
verify the change.

Given I'm not a `make` expert I'd appreciate confirmation that my wiki
changes have indeed improved the situation rather than breaking it in
a new and different way. :) (Also, I updated the `automake` and LaTeX
examples but have not tested them.)

--Philip;


More information about the Mercurial mailing list