auto-version.in: Factor out Debian version checking.
[cfd] / auto-version.in
index d229a29..59c75c0 100755 (executable)
@@ -70,14 +70,22 @@ 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
+## Get the Debian version, if there is one.
+if [ -f debian/changelog ]; then
+  debver=$(sed -n '/^.*(\(.*\)).*$/ { s::\1:p; q; }' debian/changelog)
+else
+  unset debver
+fi
 
-  ## If the working tree is dirty, indicate with a `+'.
-  case "$(git diff-index --name-only HEAD)" in
-    "") ;;
-    *) version="$version+" ;;
-  esac
+## If this is a Git checkout then Git should be able to identify the version.
+## 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
+  case ${debver+t} in t) version=$debver$version ;; esac
   echo "$version"
   exit 0
 fi
@@ -90,10 +98,9 @@ if [ -f RELEASE ]; then
 fi
 
 ## If we're Debianized, then the Debian changelog ought to know.
-if [ -f debian/changelog ]; then
-  sed -n '/^.*(\(.*\)).*$/ { s::\1:p; q; }' debian/changelog
-  exit 0
-fi
+case ${debver+t} in
+  t) echo "$debver"; exit 0 ;;
+esac
 
 ## Otherwise we're screwed.
 echo UNKNOWN