#!/bin/sh

#------------#------------------------------------------------------------
# Parameters #
#------------#

#
# Modular build parameters
#
BUILD_TESTS=yes
BUILD_EXAMPLES=yes
BUILD_LIB=yes
DEPENDENCIES_LINK_TYPE=shared # shared/static

# Build type (Release/Debug)
BUILD_TYPE=Debug

# C++ compiler
CXX_COMPILER=g++
C_COMPILER=gcc

if [ -z "$BUILD_TYPE" ] || [ -z "$CXX_COMPILER" ]; then
    (>&2 echo "Set, please, both BUILD_TYPE and CXX_COMPILER variables in the 'build.sh' script.")
    exit 2
fi

$(pwd)/clean.sh

#
# For ExprTk download
#
git submodule init
git submodule update --remote

cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_CXX_COMPILER=${CXX_COMPILER} -DCMAKE_C_COMPILER=${C_COMPILER} -DBUILD_TESTS=${BUILD_TESTS} -DBUILD_EXAMPLES=${BUILD_EXAMPLES} -DBUILD_LIB=${BUILD_LIB} -DLIB4NEURO_DIR=$(pwd)/build/lib -DDEPENDENCIES_LINK_TYPE=${DEPENDENCIES_LINK_TYPE} .
cmake --build . --config ${BUILD_TYPE} -- -j${N_CORES} && (tput setaf 2; echo "Build complete."; echo "For examples have a look at the folder build/bin/examples."; tput sgr 0; ) || (tput setaf 1; echo "Build finished with errors!"; tput sgr 0; exit 1;)
