#!/bin/bash
export TBBROOT=$PREFIX

if [ `uname` == Darwin ]; then
    MACOSX_DEPLOYMENT_TARGET=10.9 $PYTHON setup.py build install --single-version-externally-managed --record=record.txt
else
    if [ -z "${WHEELS_OUTPUT_FOLDER}" ]; then
        export WHEELS_OUTPUT_FOLDER=../../
    fi

    $PYTHON setup.py build install --single-version-externally-managed --record=record.txt bdist_wheel -p manylinux1_x86_64
    cp dist/numba*.whl $WHEELS_OUTPUT_FOLDER
fi

if [ "$(uname)" == "Darwin" ]; then
    exit 0
fi

if [ ! -z "${ONEAPI_ROOT}" ]; then
    # Suppress error b/c it could fail on Ubuntu 18.04
    source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh || true
    export CC=clang
    export CXX=clang++
else
    echo "DPCPP is needed to build OpenCL kernel. Abort!"
fi

$CC -flto -target spir64-unknown-unknown -c -x cl -emit-llvm -cl-std=CL2.0 -Xclang -finclude-default-header numba/dppl/ocl/atomics/atomic_ops.cl -o numba/dppl/ocl/atomics/atomic_ops.bc
llvm-spirv -o numba/dppl/ocl/atomics/atomic_ops.spir numba/dppl/ocl/atomics/atomic_ops.bc
cp numba/dppl/ocl/atomics/atomic_ops.spir ${SP_DIR}/numba/dppl/ocl/atomics/
