summaryrefslogtreecommitdiffstats
path: root/gen-version
diff options
context:
space:
mode:
Diffstat (limited to 'gen-version')
-rwxr-xr-xgen-version40
1 files changed, 40 insertions, 0 deletions
diff --git a/gen-version b/gen-version
new file mode 100755
index 0000000..eccc47c
--- /dev/null
+++ b/gen-version
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+export LANG=C
+
+# Always create version string for repository this script lies in,
+# not the cwd... Makes usage easier in cmake/out of source builds
+ARG0="$0"
+SELF="$(readlink -f "${ARG0}")"
+if [ -n "$SELF" ]; then
+ ROOT_DIR="$(dirname "${SELF}")"
+ cd "$ROOT_DIR"
+fi
+
+MODDED=
+[ -n "$(git diff)" ] && MODDED='+LOCALMOD'
+
+VERSION=$(git describe || git rev-parse --short HEAD)
+
+BUILDTIME=$(date -R)
+
+COMMIT=$(git rev-parse HEAD)
+
+COMMITTIME=$(git log -1 --date=short --pretty=format:%cD)
+
+if [ -s ".localversion" ]; then
+ . .localversion
+fi
+
+VERSION="$VERSION$MODDED"
+
+# replace
+ssed() {
+ local fnd rep
+ fnd="%${1}%"
+ eval rep='"'\$$1'"'
+ sed "s/$fnd/$(echo "$rep" | sed 's,\\,\\\\,g;s,/,\\/,g')/g"
+}
+
+< "version.in" ssed "VERSION" | ssed "BUILDTIME" | ssed "COMMIT" | ssed "COMMITTIME" > "version.in.h"
+