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` diff --git a/subsurface-gen-version.pri b/subsurface-gen-version.pri index 7d4cda513..8e3f06a7e 100644 --- a/subsurface-gen-version.pri +++ b/subsurface-gen-version.pri @@ -1,40 +1,16 @@ # Generate the ssrf-version.h file -VERSION_FILE = ssrf-version.h macx: VER_OS = darwin unix: !macx: VER_OS = linux win32: VER_OS = win -exists(.git/HEAD): { - win32: SET_GIT_DIR = set GIT_DIR - else: SET_GIT_DIR = GIT_DIR - GIT_HEAD = .git/HEAD - VERSION_SCRIPT = $$PWD/scripts/get-version - # always use linux here -------------------vvv so we get the true full version - FULL_VERSION = "`$$VERSION_SCRIPT linux`" - VERSION = $$system("sh scripts/get-version full || echo $${VERSION}") - PRODVERSION_STRING = $$system("sh scripts/get-version win $$FULL_VERSION || echo $${VERSION}.0.0-git") - VERSION_STRING = $$system("sh scripts/get-version linux $$FULL_VERSION || echo $${VERSION}-git") - version_h.depends = $$VERSION_SCRIPT $$PWD/.git/$$system("$$SET_GIT_DIR=$$PWD/.git git rev-parse --symbolic-full-name HEAD") - version_h.commands = echo \\$${LITERAL_HASH}define VERSION_STRING \\\"`GIT_DIR=$$PWD/.git $$VERSION_SCRIPT $$VER_OS || echo $$VERSION-git`\\\" > ${QMAKE_FILE_OUT} - version_h.commands += $$escape_expand(\\n)$$escape_expand(\\t) - version_h.commands += echo \\$${LITERAL_HASH}define GIT_VERSION_STRING \\\"`GIT_DIR=$$PWD/.git $$VERSION_SCRIPT linux || echo $$VERSION-git`\\\" >> ${QMAKE_FILE_OUT} - version_h.commands += $$escape_expand(\\n)$$escape_expand(\\t) - version_h.commands += echo \\$${LITERAL_HASH}define CANONICAL_VERSION_STRING \\\"`GIT_DIR=$$PWD/.git $$VERSION_SCRIPT full || echo $$VERSION-git`\\\" >> ${QMAKE_FILE_OUT} - version_h.input = GIT_HEAD - version_h.output = $$VERSION_FILE - version_h.variable_out = GENERATED_FILES - version_h.CONFIG = ignore_no_exist - QMAKE_EXTRA_COMPILERS += version_h -} else { - # This is probably a package - exists(.gitversion): { - FULL_VERSION = $$system("cat .gitversion") - } else { - FULL_VERSION = $$VERSION - } - CANONICAL_VERSION = $$system("sh scripts/get-version full $$FULL_VERSION") - OS_USABLE_VERSION = $$system("sh scripts/get-version $$VER_OS $$FULL_VERSION") - system(echo \\$${LITERAL_HASH}define VERSION_STRING \\\"$$OS_USABLE_VERSION\\\" > $$VERSION_FILE) - system(echo \\$${LITERAL_HASH}define GIT_VERSION_STRING \\\"$$FULL_VERSION\\\" >> $$VERSION_FILE) - system(echo \\$${LITERAL_HASH}define CANONICAL_VERSION_STRING \\\"$$CANONICAL_VERSION\\\" >> $$VERSION_FILE) - QMAKE_CLEAN += $$VERSION_FILE -} + +# use a compiler target that has a phony input and is forced on each `make` invocation +# the resulted file is not a link target and is cleared with `make clean` +PHONY_DEPS = . +version_h.input = PHONY_DEPS +version_h.depends = FORCE +version_h.output = $$VERSION_FILE +version_h.commands = cd $$PWD && sh $$PWD/scripts/write-version $$VERSION_FILE $$VERSION $$VER_OS +silent: version_h.commands = @echo Checking $$VERSION_FILE && $$version_h.commads +version_h.CONFIG += no_link +QMAKE_EXTRA_COMPILERS += version_h +QMAKE_CLEAN += $$VERSION_FILE diff --git a/subsurface.pro b/subsurface.pro index 7a00d7492..a34bc091a 100644 --- a/subsurface.pro +++ b/subsurface.pro @@ -20,8 +20,12 @@ else: TARGET = subsurface QMAKE_CLEAN += $$TARGET VERSION = 4.4 +VERSION_FILE = $$OUT_PWD/ssrf-version.h +# create a blank VERSION_FILE if missing +system(cat $$VERSION_FILE > /dev/null 2>&1 || touch $$VERSION_FILE) HEADERS = \ + $$VERSION_FILE \ cochran.h \ color.h \ deco.h \