aboutsummaryrefslogtreecommitdiff
path: root/gen-version.sh
diff refs
from:
to:
flip
diff options
context:
space:
mode:
Diffstat (limited to 'gen-version.sh')
-rwxr-xr-xgen-version.sh38
1 files changed, 34 insertions, 4 deletions
diff --git a/gen-version.sh b/gen-version.sh
index 4c60f60..b493cf5 100755
--- a/gen-version.sh
+++ b/gen-version.sh
@@ -1,4 +1,34 @@
-v=$(git-describe --abbrev=4 HEAD | sed -e 's/-/./g')
-test -z "$v" && exit 1
-echo "CGIT_VERSION = $v"
-echo "CGIT_VERSION = $v" > VERSION
+#!/bin/sh
+
+# Get version-info specified in Makefile
+V=$1
+
+# When building from a git repository, derive the version from the most recent
+# release tag instead. The result follows Semantic Versioning 2.0.0, using the
+# number of commits made since that tag as build metadata, so seven commits
+# after the v1.3.1 tag gives "v1.3.1+7", while a build of the tag itself gives
+# plain "v1.3.1". Release tags are expected to be named vMAJOR.MINOR.PATCH.
+if test "$(git rev-parse --git-dir 2>/dev/null)" = '.git'
+then
+ tag=$(git describe --abbrev=0 --match 'v[0-9]*' HEAD 2>/dev/null)
+ if test -n "$tag"
+ then
+ ahead=$(git rev-list --count "$tag..HEAD" 2>/dev/null)
+ if test -n "$ahead" && test "$ahead" -gt 0
+ then
+ V="$tag+$ahead"
+ else
+ V="$tag"
+ fi
+ fi
+fi
+
+new="CGIT_VERSION = $V"
+old=$(cat VERSION 2>/dev/null)
+
+# Exit if VERSION is uptodate
+test "$old" = "$new" && exit 0
+
+# Update VERSION with new version-info
+echo "$new" > VERSION
+cat VERSION