#!/bin/bash
set -ex

# Copy the [de]activate scripts to $PREFIX/etc/conda/[de]activate.d.
# This will allow them to be run on environment activation.
for CHANGE in "activate" "deactivate"
do
   mkdir -p "${PREFIX}/etc/conda/${CHANGE}.d"
   cp "${RECIPE_DIR}/${CHANGE}.sh" "${PREFIX}/etc/conda/${CHANGE}.d/${PKG_NAME}_${CHANGE}.sh"
done

# Intel LLVM must cooperate with compiler and sysroot from conda
echo "--gcc-toolchain=${BUILD_PREFIX} --sysroot=${BUILD_PREFIX}/${HOST}/sysroot -target ${HOST}" > icpx_for_conda.cfg
export ICPXCFG="$(pwd)/icpx_for_conda.cfg"
export ICXCFG="$(pwd)/icpx_for_conda.cfg"

# source ${DPCPPROOT}/env/vars.sh
# echo "DPCPPROOT = ${DPCPPROOT}"
icpx -fsycl --version

export CPATH="${CPATH}:${CONDA_PREFIX}/include"
export XGBOOSTROOT="$(pwd)"

# release build
mkdir _build
cd _build
cmake -DPLUGIN_SYCL=ON ..
make -j$(nproc)
cd ..

ls -l ${CONDA_PREFIX}/lib/
export LD_LIBRARY_PATH=${CONDA_PREFIX}/lib/:$LD_LIBRARY_PATH

cd python-package
$PYTHON -m pip install .
