Files
Certyflie/scripts/update_version.sh
Alexander Holler 4b362e529a Make the version-scripts git-aware
Some people prefer to use git (easy possible by using git-hg) therefor
make the version-scripts git-aware.

To not change the view of the version string(s), the version when using
git still looks the same as if mercury is used (and not like a
standard git-version).
2014-03-05 13:38:07 +01:00

45 lines
956 B
Bash

#!/usr/bin/env bash
FILE=utils/src/version.c
MODIFIED=0
#Get the relevant informations
if test -d .git ; then
# git
ID=$(git describe --tags --abbrev=12 HEAD)
REV=${ID##*-}
REV=${REV:1}
LOCAL=${ID#*-*-}
TAG=${ID%-$LOCAL}
LOCAL=${LOCAL%-*}
git update-index -q --refresh
if ! test -z "$(git diff-index --name-only HEAD --)" ; then
MODIFIED=1
fi
else
# mercury
ID=$(hg identify -nit)
REV=$(echo -n $ID | cut -d' ' -f1)
LOCAL=$(echo -n $ID | cut -d' ' -f2)
TAG=$(echo -n $ID | cut -d' ' -f3)
#LOCAL=$(hg identify -n)
#REV=$(hg identify -i)
#TAG=$(hg identify -t)
#BRANCH=$(hg identify -b)
if echo -n $REV | grep +\$>/dev/null; then
MODIFIED=1
fi
fi
#Patch version.c
sed -i "s/SLOCAL_REVISION=\".*\";\$/SLOCAL_REVISION=\"$LOCAL\";/" $FILE
sed -i "s/STAG=\".*\";\$/STAG=\"$TAG\";/" $FILE
sed -i "s/SREVISION=\".*\";\$/SREVISION=\"$REV\";/" $FILE
sed -i "s/MODIFIED=.*;\$/MODIFIED=$MODIFIED;/" $FILE
true