diff options
author | Simon Rettberg | 2017-12-22 11:40:43 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-12-22 11:40:43 +0100 |
commit | 24b5a6bdda8f09593dd908c3fc69315ebb3754e1 (patch) | |
tree | 71b72641416040fe15864f8aeb77377b6ba376c7 /gen-version | |
parent | Fix compile error (diff) | |
download | ldadp-24b5a6bdda8f09593dd908c3fc69315ebb3754e1.tar.gz ldadp-24b5a6bdda8f09593dd908c3fc69315ebb3754e1.tar.xz ldadp-24b5a6bdda8f09593dd908c3fc69315ebb3754e1.zip |
Add version information and --version
Diffstat (limited to 'gen-version')
-rwxr-xr-x | gen-version | 40 |
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" + |