#!/bin/bash

mkdir -p build
cd build
mkdir -p Plugin/GAConnector/32
mkdir -p Plugin/GAConnector/64
rm -f CMakeCache.txt

case $1 in
  "mac")
    cmake -DDEBUG=$DEBUG -DCMAKE_TOOLCHAIN_FILE=../toolchain-mac.cmake ..
  ;;
  "lin32")
    cmake -DDEBUG=$DEBUG -DBIT=32 -DCMAKE_TOOLCHAIN_FILE=../toolchain-lin-32.cmake ..
  ;;
  "lin64")
    cmake -DDEBUG=$DEBUG -DBIT=64 -DCMAKE_TOOLCHAIN_FILE=../toolchain-lin-64.cmake ..
  ;;
  "win32")
    cmake -DDEBUG=$DEBUG -DBIT=32 -DCMAKE_TOOLCHAIN_FILE=../toolchain-win-32.cmake ..
    \cp -rf ../openSSL/win32/*.dll Plugin/GAConnector/32/
  ;;
  "win64")
    cmake -DDEBUG=$DEBUG -DBIT=64 -DCMAKE_TOOLCHAIN_FILE=../toolchain-win-64.cmake ..
    \cp -rf ../openSSL/win64/*.dll Plugin/GAConnector/64/
  ;;
esac

make -j
code=$?
if [ "$code" -ne 0 ]
then
    exit $code
fi

if [ "$1" = "mac" ] && [ "$DEBUG" = "1" ]
then
    /opt/osxcross/target/bin/osxcross-llvm-dsymutil Plugin/GAConnector/mac.xpl
fi


