subsurface/scripts/write-version
Lubomir I. Ivanov f6dbed1fc6 qmake: use a dedicated build script to generate ssrf-version.h
- added ./scripts/write-version
- subsurface-gen-version.pri is much simpler now
- .git/HEAD is no longer used explicitly in .pro/.pri files
- the version_h rule is called on each 'make' invocation
but recompilation will occur only if ssrf-version.h
is updated by ./scripts/write-version
- qmake now depends on the existence of ssrf-version.h
so it creates an empty one on Makefile generation so
that a warning is not shown

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-15 06:19:33 -08:00

49 lines
1.3 KiB
Bash

#!/bin/sh
#
# arguments:
# $1 - target H file
# $2 - fallback version string
# $3 - os name {linux|darwin|win}
#
# doesn't have much error checking!
# should be started from where .git is!
#
if [ "$#" -lt 3 ]; then
echo "ERROR: missing arguments";
exit 1;
fi
# set OS and TARGET
TARGET=$1
TARGET_TEMP=$TARGET.tmp
VERSION=$2
OS=$3
# get the full version: git based or hardcoded from .gitversion or the fallback version string
if gitpwd=`git rev-parse --show-toplevel 2> /dev/null`; then
FULL_VER=`sh "$gitpwd/scripts/get-version" linux`
else
FULL_VER=`cat .gitversion 2> /dev/null || echo $VERSION`
fi
# grab some strings from get-version
CANONICAL_VER=`sh ./scripts/get-version full $FULL_VER`
OS_USABLE_VER=`sh ./scripts/get-version $OS $FULL_VER`
# write to a temp file
echo "#define VERSION_STRING \"$OS_USABLE_VER\"" > $TARGET_TEMP
echo "#define GIT_VERSION_STRING \"$FULL_VER\"" >> $TARGET_TEMP
echo "#define CANONICAL_VERSION_STRING \"$CANONICAL_VER\"" >> $TARGET_TEMP
# if the target file is missing create it
if [ ! -f $TARGET ]; then
CMD=`touch $TARGET`
fi
# if the temp file and the target file differ, replace the target file with the temp file
CMD=`diff -q $TARGET $TARGET_TEMP || cp $TARGET_TEMP $TARGET`
# remove the temp file
CMD=`rm -f $TARGET_TEMP`