mcu_base/git-version-gen

51 lines
915 B
Bash
Executable File

#!/bin/sh
GVF=$1
APP=$2
DEF_VER=UNKNOWN
# First see if there is a version file (included in release tarballs),
# then try git-describe, then default.
if test -f version
then
VN=$(cat version)
elif test -d .git
then
VN=$(git describe 2>/dev/null) && git update-index -q --refresh
HEAD=$(git rev-parse --verify --short HEAD 2>/dev/null)
if [ -n "$VN" ] ; then
VN="$VN-$HEAD"
else
VN="none-$HEAD"
fi
test -z "$(git diff-index --name-only HEAD --)" || VN="$VN-dirty"
else
VN="$DEF_VER"
fi
#VN=$(expr "$VN" : v*'\(.*\)')
echo "$VN"
if test -r $GVF
then
VC=$(grep SYSTEM_VERSION $GVF | sed -e 's/^#define SYSTEM_VERSION //')
VM=$(grep SYSTEM_APP $GVF | sed -e 's/^#define SYSTEM_APP //')
else
VC=unset
fi
if [ -n "$APP" ] ; then
APP="-$APP"
fi
test "\"$VN\"" = "$VC" -a "\"$APP\"" = "$VM" || {
echo "#define SYSTEM_VERSION \"$VN\"" >$GVF
echo "#define SYSTEM_APP \"$APP\"" >>$GVF
}