From ff070aea45acef923759634abbfdbad85632e80f Mon Sep 17 00:00:00 2001 From: bergmann89 Date: Sat, 19 Sep 2015 13:37:41 +0200 Subject: [PATCH] * added script to build library release --- .gitignore | 6 +- library/build_release.sh | 203 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+), 1 deletion(-) create mode 100755 library/build_release.sh diff --git a/.gitignore b/.gitignore index 13a06e0..28f6a20 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,11 @@ lib/ +bin/ debug/ +*.so *.lps *.exe *.res *.ico -*.dll \ No newline at end of file +*.dll +*.zip + diff --git a/library/build_release.sh b/library/build_release.sh new file mode 100755 index 0000000..7be72ba --- /dev/null +++ b/library/build_release.sh @@ -0,0 +1,203 @@ +#!/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" +INC_MAJOR=false +INC_MINOR=false +INC_BUGFIX=false + +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="0.0.0.0" + 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 + return 0 +} + +function BuildConfig() +{ + CONFIG=$1 + POSTFIX=$2 + FILEEXT=$3 + + printf "\n== build project $CONFIG ==\n" + lazbuild --build-mode=$CONFIG --build-all --verbose $SCRIPTDIR/libShaderFile.lpi + if [ $? -ne 0 ]; then + echo "build failed! exit." + cleaupAndExit 1 + fi + + ZIPDIR="bin/$POSTFIX" + BINDIR="$ZIPDIR" + ZIPPATH="$SCRIPTDIR/libShaderFile-$POSTFIX.zip" + if [ -n "$TAGNAME" ]; then + mkdir -p "$SCRIPTDIR/$TAGNAME/" + ZIPPATH="$SCRIPTDIR/$TAGNAME/libShaderFile-$POSTFIX.zip" + fi + BINNAME="libShaderFile-$POSTFIX$FILEEXT" + if [ ! -f $BINNAME ]; then + echo "file not found: $EXENAME" + cleaupAndExit 2 + fi + + mkdir -p $BINDIR + mv "$BINNAME" "$BINDIR/" || { log "unable to copy linked binary"; cleaupAndExit 3; } + # use this to copy data folder instead of data archive: cp -R --preserve=links data $BINDIR || { log "unable to copy data folder"; cleaupAndExit 4; } + cp -r "$HEADER_DIR" "$BINDIR" || { log "unable to copy header files"; cleaupAndExit 4; } + pushd $ZIPDIR + rm -rf $ZIPPATH + zip -r $ZIPPATH ./* || { log "unable to create zip archive"; cleaupAndExit 5; } + popd +} + +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" + +cleaupAndExit 0 +