#!/bin/bash # set -x #enable debug SCRIPTPATH=$(readlink -f $0) SCRIPTNAME=$(basename $SCRIPTPATH) SCRIPTDIR=$(dirname $SCRIPTPATH) git="git" HAS_GIT=true HEADER_DIR="$SCRIPTDIR/header" DOCU_DIR="$SCRIPTDIR/doc" INC_MAJOR=false INC_MINOR=false INC_BUGFIX=false ALLZIPDIR="$SCRIPTDIR/TextSuite-all" if [ -z "$FIRST_VERSION" ]; then FIRST_VERSION="0.0.0.0" fi function log() { echo "$@" >&2 } function cleaupAndExit() { if $HAS_GIT && [[ -n "$TAGNAME" ]] && [[ $1 -ne 0 ]]; then log "remove git tag $TAGNAME" $git tag -d $TAGNAME fi exit $1 } function printHelp() { printf "script to build libShaderFile release Usage: $SCRIPTNAME [parameter] [] optional parameters () required parameters Parameter: --major | -m increment major version and reset the minor version before creating git tag --minor | -n increment major version and reset the bugfix version before creating git tag --bufgix | -b increment bugfix version before creating git tag --help | -h | -? print this help " } function getLastVersion() { POS="HEAD" TAG=$($git describe --tags --abbrev=0 $POS 2>/dev/null) RET=$? while [[ $RET -eq 0 ]]; do if [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then echo $(echo $TAG | egrep -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+") return 0 fi POS=$TAG"^" TAG=$($git describe --tags --abbrev=0 $POS 2>/dev/null) RET=$? done return 1 } function incVersion() { read -r -a PARTS <<< $(echo "$1" | tr "." " ") if $INC_MAJOR; then ((PARTS[0]++)) PARTS[1]=0 fi if $INC_MINOR; then ((PARTS[1]++)) PARTS[2]=0 fi if $INC_BUGFIX; then ((PARTS[2]++)) fi ((PARTS[3]++)) local tmp="${PARTS[@]}" echo "${tmp// /.}" } function addGitTag() { local INC_VERSION=true log "create git version tag" CURRENT=$(getLastVersion) if [ $? -ne 0 ]; then CURRENT="$FIRST_VERSION" INC_VERSION=false fi local tmp="v$CURRENT" LINES=$($git log --pretty=oneline $tmp..HEAD) if [ $? -eq 0 ]; then DIFF=$(echo $LINES | wc -l) if [ $DIFF -eq 0 ] || [ -z "$LINES" ]; then log "current commit already has a version tag: $tmp" TAGNAME=$tmp return 0 fi fi if $INC_VERSION; then NEWVERSION=$(incVersion $CURRENT) else NEWVERSION="$CURRENT" fi log "current version: $CURRENT" log "new version: $NEWVERSION" local tmp="v$NEWVERSION" $git tag $tmp if [[ $? -ne 0 ]]; then log "unable to create version tag: exit" cleaupAndExit 100 fi TAGNAME=$tmp HASH="$(git rev-parse HEAD)" printf "const Version = 'v$NEWVERSION $HASH';" > inc/utsTextSuiteVersion.inc return 0 } function BuildConfig() { CONFIG=$1 TARGET=$2 FILEEXT=$3 DBGEXT=".dbg" printf "\n== build project $CONFIG ==\n" lazbuild --build-mode=$CONFIG --build-all --verbose $SCRIPTDIR/libTextSuite.lpi if [ $? -ne 0 ]; then echo "build failed! exit." cleaupAndExit 1 fi BINDIR="$SCRIPTDIR/bin" ZIPDIR="$SCRIPTDIR/TextSuite-$TARGET" ZIPPATH="$SCRIPTDIR/TextSuite-$TARGET.zip" if [ -n "$TAGNAME" ]; then mkdir -p "$SCRIPTDIR/$TAGNAME/" ZIPPATH="$SCRIPTDIR/$TAGNAME/TextSuite-$TARGET.zip" fi TARGETDIR="$BINDIR/$TARGET" BINNAME="$TARGETDIR/libtextsuite$FILEEXT" DBGNAME="$TARGETDIR/libtextsuite$DBGEXT" if [ ! -f $BINNAME ]; then echo "file not found: $BINNAME" cleaupAndExit 2 fi # extract debug infos cp "$BINNAME" "$DBGNAME" || { log "unable to copy binary to *.dbg"; cleaupAndExit 3; } objcopy --only-keep-debug "$DBGNAME" || { log "unable to strip $DBGNAME"; cleaupAndExit 3; } objcopy --strip-debug --strip-unneeded "$BINNAME" || { log "unable to copy binary to $BINNAME"; cleaupAndExit 3; } objcopy --add-gnu-debuglink "$DBGNAME" "$BINNAME" || { log "unable to create debug link"; cleaupAndExit 3; } if [ ! -f $DBGNAME ]; then echo "file not found: $DBGNAME" cleaupAndExit 2 fi # copy header and docu mkdir -p "$ZIPDIR/bin" cp -r "$TARGETDIR" "$ZIPDIR/bin" || { log "unable to copy binaries"; cleaupAndExit 3; } cp -r "$HEADER_DIR" "$ZIPDIR" || { log "unable to copy header files"; cleaupAndExit 4; } cp -r "$DOCU_DIR" "$ZIPDIR/docu" || { log "unable to copy documentation files"; cleaupAndExit 5; } pushd "$ZIPDIR" rm -rf "$ZIPPATH" zip -r "$ZIPPATH" "." || { log "unable to create zip archive"; cleaupAndExit 6; } popd mkdir -p "$ALLZIPDIR" echo "mv $ZIPDIR/* $ALLZIPDIR/" cp -rf $ZIPDIR/* $ALLZIPDIR/ || { log "unable to copy binaries to all directory"; cleaupAndExit 3; } rm -rf "$ZIPDIR" } while [[ $# -gt 0 ]]; do case $1 in "--major" | "-m") INC_MAJOR=true ;; "--minor" | "-n") INC_MINOR=true ;; "--bufgix" | "-b") INC_BUGFIX=true ;; "--help" | "-h" | "-?") printHelp cleaupAndExit 0 ;; *) echo "invalid parameter: $1" echo "use --help to get further information" ;; esac shift done if $HAS_GIT; then GIT_CHANGED=$($git status --untracked-files=all --verbose --porcelain) if [[ -n "$GIT_CHANGED" ]]; then log "git has uncommited changes. please commit before building a release" cleaupAndExit 101 fi addGitTag fi BuildConfig "Win32Release" "i386-win32" ".dll" BuildConfig "Win64Release" "x86_64-win64" ".dll" BuildConfig "Linux32Release" "i386-linux" ".so" BuildConfig "Linux64Release" "x86_64-linux" ".so" ALLZIPPATH="$SCRIPTDIR/TextSuite-all.zip" if [ -n "$TAGNAME" ]; then mkdir -p "$SCRIPTDIR/$TAGNAME/" ALLZIPPATH="$SCRIPTDIR/$TAGNAME/TextSuite-all.zip" fi pushd "$ALLZIPDIR" rm -rf "$ALLZIPPATH" zip -r "$ALLZIPPATH" "." || { log "unable to create zip archive"; cleaupAndExit 6; } popd rm -rf "$ALLZIPDIR" cleaupAndExit 0