From f6dbed1fc6c71251e1937cb1b63e96ff7a8251c3 Mon Sep 17 00:00:00 2001
From: "Lubomir I. Ivanov" <neolit123@gmail.com>
Date: Fri, 30 Jan 2015 18:56:12 +0200
Subject: 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>
---
 scripts/write-version | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 scripts/write-version

(limited to 'scripts')

diff --git a/scripts/write-version b/scripts/write-version
new file mode 100644
index 000000000..81562fbb8
--- /dev/null
+++ b/scripts/write-version
@@ -0,0 +1,49 @@
+#!/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`
-- 
cgit v1.2.3-70-g09d2