xref: /kvmtool/util/KVMTOOLS-VERSION-GEN (revision eb41dfc9d8e5a27e09bfbec9c01aab7f33033f3f)
116b2bb87SSasha Levin#!/bin/sh
216b2bb87SSasha Levin
316b2bb87SSasha Levinif [ $# -eq 1 ]  ; then
416b2bb87SSasha Levin	OUTPUT=$1
516b2bb87SSasha Levinfi
616b2bb87SSasha Levin
716b2bb87SSasha LevinGVF=${OUTPUT}KVMTOOLS-VERSION-FILE
816b2bb87SSasha Levin
916b2bb87SSasha LevinLF='
1016b2bb87SSasha Levin'
1116b2bb87SSasha Levin
1216b2bb87SSasha Levin# First check if there is a .git to get the version from git describe
1316b2bb87SSasha Levin# otherwise try to get the version from the kernel makefile
14*17725a8dSAndre Przywaraif test -d .git -o -f .git &&
1516b2bb87SSasha Levin	VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
1616b2bb87SSasha Levin	case "$VN" in
1716b2bb87SSasha Levin	*$LF*) (exit 1) ;;
1816b2bb87SSasha Levin	v[0-9]*)
1916b2bb87SSasha Levin		git update-index -q --refresh
2016b2bb87SSasha Levin		test -z "$(git diff-index --name-only HEAD --)" ||
2116b2bb87SSasha Levin		VN="$VN-dirty" ;;
2216b2bb87SSasha Levin	esac
2316b2bb87SSasha Levinthen
2416b2bb87SSasha Levin	VN=$(echo "$VN" | sed -e 's/-/./g');
2516b2bb87SSasha Levinelse
26*17725a8dSAndre Przywara	VN=3.18.0
2716b2bb87SSasha Levinfi
2816b2bb87SSasha Levin
2916b2bb87SSasha LevinVN=$(expr "$VN" : v*'\(.*\)')
3016b2bb87SSasha Levin
3116b2bb87SSasha Levinif test -r $GVF
3216b2bb87SSasha Levinthen
3316b2bb87SSasha Levin	VC=$(sed -e 's/^KVMTOOLS_VERSION = //' <$GVF)
3416b2bb87SSasha Levinelse
3516b2bb87SSasha Levin	VC=unset
3616b2bb87SSasha Levinfi
3716b2bb87SSasha Levintest "$VN" = "$VC" || {
3816b2bb87SSasha Levin	echo "KVMTOOLS_VERSION = $VN" >$GVF
3916b2bb87SSasha Levin}
40