summaryrefslogblamecommitdiffstats
path: root/gen-version
blob: 569e98c1ab208633278b08981bf90e430b0ccb52 (plain) (tree)
























                                                                  
                                       













                                                                                                     
#!/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 # super dash!
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"