mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-27 20:58:47 +00:00
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>
This commit is contained in:
parent
27b4d10f91
commit
f6dbed1fc6
3 changed files with 65 additions and 36 deletions
49
scripts/write-version
Normal file
49
scripts/write-version
Normal file
|
@ -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`
|
|
@ -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
|
||||
|
|
|
@ -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 \
|
||||
|
|
Loading…
Reference in a new issue