-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