#!/bin/bash

MAKE_THREADS="8"
GLOBAL_LIBS="libncurses-dev  libboost-dev  nlohmann-json3-dev swig libinsighttoolkit5-dev"

DIR_PARALLELPROJ="parallelproj"
DIR_STIR="STIR"

if [ -z ${VIRTUAL_ENV} ]; then
    echo "ERROR:"
    echo "  Please make sure to activate your Python virtual environment is active."
    echo "  Otherwise, libraries are not installed to their appropriate location."
    exit 1
fi
PYTHON_DEST="${VIRTUAL_ENV}/lib/python$(python --version | cut -d " " -f2 | cut -d "." -f1,2)/site-packages"

echo "WARNING:"
echo "  Currently, this script is not able to install the libraries locally."
echo "  Thus, you will be asked for sudo permission in the following."
echo


##################### GLOBAL DEPENDENCIES ###########################################
echo "Install transitive dependencies [${GLOBAL_LIBS}] globally ..."
sudo apt-get install -y ${GLOBAL_LIBS}


##################### PARALLELPROJ ###########################################
echo "Install ${DIR_PARALLELPROJ} ..."
mkdir -p ${DIR_PARALLELPROJ}/build && \
cd ${DIR_PARALLELPROJ}/build && \
cmake .. && \
nice make -j ${MAKE_THREADS} && \
sudo make install && \
cd ../../


##################### STIR ###########################################
echo "Install ${DIR_STIR} ..."
mkdir -p ${DIR_STIR}/build && \
cd ${DIR_STIR}/build && \
cmake .. -DPYTHON_DEST=${PYTHON_DEST} -DBUILD_SWIG_PYTHON=ON -DSTIR_MPI=ON -DCMAKE_INSTALL_PREFIX=${VIRTUAL_ENV} && \
nice make -j ${MAKE_THREADS} && \
make install && \
cd ../../

