#!/bin/bash

function error_quit {
    echo -e "$@"
    echo
    echo -e 'Usage:'
    echo -e './compile.sh --clean'
    echo -e '   To clean build directory. Makenek will ask for cleaning 3rd-party libraries.'
    echo
    echo -e './compile.sh --all'
    echo -e '   To compile the code.'
    exit 1
}

#parameters
export CASE="{{ CASE }}"
export NEK_SOURCE_ROOT=${NEK_SOURCE_ROOT:"../../Nek5000"}
export FC="{{ MPIFC }}"
export CC="{{ MPICC }}"
export CFLAGS="{{ CFLAGS }}"
export FFLAGS="{{ FFLAGS }} {{ INC }}"
export PPLIST=""
export USR="{{ USR }}"
export USR_LFLAGS=""

# arguments
args=("$@")
argsnr=$#

# check arguments
# parameters number check
if [ $[argsnr] -ne 1 ]; then
    error_quit 'Wrong arguments number!'
fi

for il in "$@"
do
case $il in
    --clean)
        ${NEK_SOURCE_ROOT}/bin/makenek clean
        shift
        ;;
    --all)
        ${NEK_SOURCE_ROOT}/bin/makenek ${CASE}
        shift
        ;;
    *)
        error_quit 'Wrong argument.'
        ;;
esac
done
