The following series of commits provides some cleanups and enhancements to how the build process generates detailed version strings for builds done from a VCS. I initially did this looking to add support for builds from a git repository, but I believe that the first two commits in the series are useful even for the official mercurial repositories.
[PATCH 1/4] version.sh: cd to script's directory [PATCH 2/4] Generate version string during make not configure [PATCH 3/4] version.sh: Move mercurial code into if block [PATCH 4/4] version.sh: Get detailed version info from git