summaryrefslogtreecommitdiffstats
path: root/scripts/get-version
diff options
context:
space:
mode:
authorGravatar Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>2013-02-16 23:54:17 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-16 15:41:58 -0800
commit727ee3aa980d505b0381ab3a0e574ca5d7094451 (patch)
tree031af62c0cf3e4596ba4cff1d6ed7298191d3398 /scripts/get-version
parent2d8a203026b47877320104e9f7597b462c016081 (diff)
downloadsubsurface-727ee3aa980d505b0381ab3a0e574ca5d7094451.tar.gz
Unified handling of version extraction.
Removed oddly named and ridiculously outdated documentation text (scripts). Created new directory 'scripts'. Added unified version extraction script (scripts/get-version). Yes, it's more shell script code but faster and more maintainable than the sed commands and the swearwords/regexps repeated over and over again. Makefile and packaging/macosx/make-package.sh modified accordingly. I don't do windos neither macos but, AFAICS my tests show, it should be safe. Signed-off-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'scripts/get-version')
-rwxr-xr-xscripts/get-version56
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/get-version b/scripts/get-version
new file mode 100755
index 000000000..c59e2000b
--- /dev/null
+++ b/scripts/get-version
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+# $1 - os name {linux|darwin|win}
+# $2 - [optional] raw version string "vX.Y-patchN-sha1". as from `git describe'
+# (see below)
+
+set -eu
+#set -x
+
+croak() {
+ echo "$0: $*" >&2
+ exit 1
+}
+
+[ $# -ge 1 ] || croak "missing OS argument"
+os=$1
+
+if [ $# -eq 2 ] && [ "$2" ]; then
+ v0=$2
+else
+ cmd="git describe --tags --abbrev=12"
+ v0=$($cmd) || croak "odd; command '$cmd' failed"
+fi
+
+# strip off the 'v' prefix, if any
+v0=${v0#v}
+
+case $os in
+ linux)
+ v=$v0
+ ;;
+ darwin|win)
+ # split version string using a '-' separator
+ IFS='-'
+ set -- $v0
+ v1=$1
+ if [ $# -gt 1 ]; then
+ v1=$v1.$2
+ else
+ v1=$v1.0
+ fi
+ case $os in
+ darwin)
+ v=$v1
+ ;;
+ win)
+ # always add '0' as the 4:th digit
+ v=$v1.0
+ ;;
+ esac
+ ;;
+ *)
+ v='git.missing.please.hardcode.version'
+ ;;
+esac
+printf '%s' $v