#! /bin/bash

#DEF
export QT_VERSION=5
export COMPILER=GCC
export BIT=64

POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
  case $1 in
    -q|--qt)
      export QT_VERSION="$2"
      shift # past argument
      shift # past value
      ;;
    -c|--compiler)
      export COMPILER="$2"
      shift # past argument
      shift # past value
      ;;
    -b|--bit)
      export BIT="$2"
      shift # past argument
      shift # past value
      ;;
    -*|--*)
      echo "Unknown option $1"
      exit 1
      ;;
    *)
      POSITIONAL_ARGS+=("$1") # save positional arg
      shift # past argument
      ;;
  esac
done

set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters

export PATH_DEVELOP=/c/Develop

$(sed -e 's/SET/export/g' $PATH_DEVELOP/Qt/install.bat | grep "export")

export CQTDEPLOYER_PATH=$PATH_DEVELOP/Qt/CQtDeployer-$CQTDEPLOYER

if [[ "$COMPILER" = "CLANG" ]]
then
export PREFIX_COMPILER=clang
export CMD_BUILD_WIN="-makefile -o Makefile -r -spec win32-clang-g++"
else
export PREFIX_COMPILER=mingw
export CMD_BUILD_WIN="-makefile -o Makefile -r -spec win32-g++"
fi

if [[ "$QT_VERSION" = "6" ]]
then
export PREFIX_QT=$QT6_VERSION-shared
else
export PREFIX_QT=$QT5_VERSION-shared
fi

if [[ "$BIT" = "32" ]]
then
export PREFIX_BIT=32
else
export PREFIX_BIT=64
fi

export COMPILER_VERSION=$PREFIX_COMPILER$PREFIX_BIT
export QMAKE_PATH=$PATH_DEVELOP/Qt/$PREFIX_QT/$COMPILER_VERSION/bin/qmake.exe
export OTHER_LIBS=$(dirname $QMAKE_PATH)
export MAKE=$PATH_DEVELOP/$COMPILER_VERSION/bin/mingw32-make.exe
export OTHER_LIBS=$(dirname $QMAKE_PATH),$(dirname $MAKE),/c/shared_libs/$PREFIX_BIT
export PATH=$(dirname $QMAKE_PATH):$(dirname $MAKE):$PATH
export CQTDEPLOYER="$PATH_DEVELOP/Qt/CQtDeployer-$CQTDEPLOYER/cqtdeployer.bat"
export CMAKE=/c/Develop/CMake-3.27.2/bin/cmake
export CC=$PATH_DEVELOP/$COMPILER_VERSION/bin/gcc.exe
export CXX=$PATH_DEVELOP/$COMPILER_VERSION/bin/g++.exe
export PATH=/c/Develop/ninja-1.11.1:${PATH}


echo "###########################################################################"
echo "CQTDEPLOYER_VER: $($CQTDEPLOYER version | grep "CQtDeployer")"
echo QT_VERSION: $QT_VERSION
echo COMPILER: $COMPILER
echo BIT: $BIT
echo QMAKE_PATH: $QMAKE_PATH
echo CMD_BUILD_WIN: $CMD_BUILD_WIN
echo MAKE: $MAKE
echo OTHER_LIBS: $OTHER_LIBS
echo PATH: $PATH
echo CQTDEPLOYER: $CQTDEPLOYER
echo CC: $CC
echo CXX: $CXX
echo "###########################################################################"
