auto-version.in: Prefix Git version with mangled `x.y.z~' Debian version.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 1 Oct 2019 11:01:27 +0000 (12:01 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 8 May 2020 11:29:43 +0000 (12:29 +0100)
The mangling is necessary to placate `pkg-config', which doesn't
implement `rpmvercmp' properly.

auto-version.in

index d229a29..5e0e59d 100755 (executable)
@@ -71,13 +71,15 @@ fi
 ### Main program.
 
 ## If this is a Git checkout then Git should be able to identify the version.
-if [ -e .git ] && version=$(git describe --abbrev=4 2>/dev/null); then
-
-  ## If the working tree is dirty, indicate with a `+'.
-  case "$(git diff-index --name-only HEAD)" in
-    "") ;;
-    *) version="$version+" ;;
-  esac
+## If there's also a Debian version, and that ends in a `~', then prefix the
+## Git version with this.  Note that `pkg-config' is not very good, and, in
+## particular, doesn't support the convention that `~' sorts before anything
+## else, even the empty string, despite claiming to implement the RPM
+## version-comparison algorithm which specifies this behaviour, so one must
+## be careful when choosing `~' prefixes.
+if [ -e .git ] && version=$(git describe --abbrev=4 --dirty=+ 2>/dev/null); then
+  debver=$(sed -n '/^.*(\(.*\)).*$/ { s::\1:p; q; }' debian/changelog)
+  case $debver in *~) version=$debver$version ;; esac
   echo "$version"
   exit 0
 fi