set -ex

# load Intel compilers
set +x
source /theoryfs2/common/software/intel2018/bin/compilervars.sh intel64
set -x

# link against conda GCC
#ALLOPTS="-gnu-prefix=${HOST}- ${OPTS}"

export FC=ifort
export CC=icc

meson_options=(
   "--prefix=${PREFIX}"
   "--libdir=lib"
   "--buildtype=release"
   "--warnlevel=0"
   "-Dpython=true"
   "-Dc_args=-qopenmp"
   "-Dfortran_args=-qopenmp"
   "-Dlapack=mkl-rt"
   "-Dfortran_link_args=-liomp5 -Wl,-Bstatic -lifport -lifcoremt_pic -limf -lsvml -lirc -lsvml -lirc_s -Wl,-Bdynamic"
   "-Dc_link_args=-liomp5 -static-intel"
   ".."
)

mkdir -p _build
pushd _build

# Build and test
if [[ "$(uname)" = Darwin ]]; then
    # Hack around issue, see contents of fake-bin/cc1 for an explanation
    PATH=${PATH}:${RECIPE_DIR}/fake-bin meson "${meson_options[@]}"
else
    meson "${meson_options[@]}"
fi

# Linux install
ninja test install

# Python install
cp python/dftd4/_libdftd4.*${SHLIB_EXT} ../python/dftd4
popd
cp assets/parameters.toml python/dftd4/
pushd python
"$PYTHON" -m pip install . --no-deps -vvv
popd
