#!/bin/bash
# This code is part of CMPL
#
# Copyright (C) 2007 - 2016 Thomas Schleiff - Halle(Saale), 
# Germany and Mike Steglich - Technical University of Applied Sciences
# Wildau, Germany 
#
# Coliop3 and CMPL are projects of the Technical University of 
# Applied Sciences Wildau and the Institute for Operations Research 
# and Business Management at the Martin Luther University 
# Halle-Wittenberg.
# Please visit the project homepage <www.coliop.org>
# 
# CMPL is free software; you can redistribute it and/or modify it 
# under the terms of the GNU General Public License as published by 
# the Free Software Foundation; either version 3 of the License, or 
# (at your option) any later version.
# 
# CMPL is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 
# License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
# @author  Mike Steglich - March 2016


# copy the CMPL binary out of the cmpl.app
function copyCMPLOsx () {
	if  ( test -d bin/cmpl.app )  ; then 
		cp bin/cmpl.app/Contents/MacOS/Coliop4 bin/Coliop4
	fi 
}



# test of the OS
oSystem="";
if [[ $OSTYPE == *darwin* ]] ; then 
	oSystem="osx"
elif  [[ $OSTYPE == *linux* ]] ; then
	oSystem="linux"
elif  [[ $OSTYPE == *msys* ]] ; then
	oSystem="win"
fi

if [ $oSystem == "" ] ; then
	echo "cmplMake error: Can not recognize your OS"
	exit 1
fi

if [ $# == 0 ] ; then 
    if [ $oSystem == "win" ] ; then
        qmake Coliop4.pro -r -spec win32-g++ CONFIG+=release
        mingw32-make -w
        cd bin
        windeployqt --no-translations --no-system-d3d-compiler  --release Coliop4.exe
        cd ..
    elif [ $oSystem == "osx" ] ; then
        qmake Coliop4.pro -r -spec macx-clang CONFIG+=x86_64 CONFIG+=release
        make -w
        cd bin
        macdeployqt Coliop4.app  
        #copyCMPLOsx
        cd ..
    elif [ $oSystem == "linux" ] ; then
        qmake Coliop4.pro -r -spec linux-g++  CONFIG+=release
		make -w
    else
        usage   
    fi
fi

if [ $# == 1 ] ; then
	if  [ $1 == "clean" ]; then
		if [ $oSystem == "win" ]; then 
			mingw32-make clean
		else
          	        make clean
                fi
	fi
fi



exit 0
