2019-08-18 08:10:54 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-08-18 11:10:01 +08:00
|
|
|
VERSION_H=include/version.h
|
|
|
|
TEMPLATE_FILE=include/version.h.template
|
2019-08-18 08:37:18 +08:00
|
|
|
GIT_BRANCH=master
|
|
|
|
|
|
|
|
rm -f $VERSION_H
|
2019-08-18 08:10:54 +08:00
|
|
|
|
|
|
|
git rev-list HEAD | sort > config.git-hash
|
|
|
|
|
2020-03-21 00:05:54 +08:00
|
|
|
LOCALVER="$(wc -l config.git-hash | awk '{print $1}')"
|
|
|
|
TAG="$(git describe --tags "$(git rev-list --tags --max-count=1)")"
|
2019-08-18 08:10:54 +08:00
|
|
|
|
2020-03-21 00:05:54 +08:00
|
|
|
if [ "$LOCALVER" -gt "1" ] ; then
|
|
|
|
VER=$(git rev-list origin/$GIT_BRANCH | sort | join config.git-hash - | wc -l | awk '{print $1}')
|
|
|
|
if [ "$VER" != "$LOCALVER" ] ; then
|
|
|
|
VER="$VER+$((LOCALVER-VER))"
|
2019-08-18 08:10:54 +08:00
|
|
|
fi
|
|
|
|
if git status | grep -q "modified:" ; then
|
|
|
|
VER="${VER}M"
|
|
|
|
fi
|
2019-08-18 08:37:18 +08:00
|
|
|
VER="$VER g$(git rev-list HEAD -n 1 | cut -c 1-7)"
|
2019-08-23 00:34:51 +08:00
|
|
|
GIT_VERSION="$TAG r$VER"
|
2019-08-18 08:10:54 +08:00
|
|
|
else
|
|
|
|
GIT_VERSION=
|
|
|
|
VER="x"
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -f config.git-hash
|
|
|
|
|
2020-03-21 00:05:54 +08:00
|
|
|
sed "s/\$FULL_VERSION/$GIT_VERSION/g" < $TEMPLATE_FILE > $VERSION_H
|
2019-08-18 08:37:18 +08:00
|
|
|
|
2019-08-18 11:10:01 +08:00
|
|
|
git update-index --assume-unchanged $VERSION_H
|
|
|
|
|
2019-08-18 08:37:18 +08:00
|
|
|
echo "Generated $VERSION_H"
|
|
|
|
echo
|
|
|
|
cat $VERSION_H
|
|
|
|
|
2019-08-18 08:10:54 +08:00
|
|
|
|