XTL_VERSION=0.7.5
XSIMD_VERSION=10.0.0
XTENSOR_VERSION=0.24.5
XTENSOR_R_VERSION=0.14.2

# xtl
if [ -d "./inst/include/xtl" ]
then
    echo "xtl headers already vendored in source package"
else
    git clone https://github.com/xtensor-stack/xtl --branch ${XTL_VERSION}
    cp -r xtl/include/xtl ./inst/include
    rm -rf xtl
    # Add newline in the end of xhalf_float_impl.hpp for R CRAN checks
    echo "" >> ./inst/include/xtl/xhalf_float_impl.hpp
fi

# xsimd
if [ -d "./inst/include/xsimd" ]
then
    echo "xsimd headers already vendored in source package"
else
    git clone https://github.com/xtensor-stack/xsimd --branch ${XSIMD_VERSION}
    cp -r xsimd/include/xsimd ./inst/include
    rm -rf xsimd
fi

# xtensor
if [ -d "./inst/include/xtensor" ]
then
    echo "xtensor headers already vendored in source package"
else
    git clone https://github.com/xtensor-stack/xtensor --branch ${XTENSOR_VERSION}
    DIRECTORY=$(cd `dirname $0` && pwd)
    git -C xtensor apply $DIRECTORY/0001-Remove-pragmas.patch
    cp -r xtensor/include/xtensor ./inst/include
    rm -rf xtensor
fi

# xtensor-r
if [ -d "./inst/include/xtensor-r" ]
then
    echo "xtensor-r headers already vendored in source package"
else
    git clone https://github.com/xtensor-stack/xtensor-r --branch ${XTENSOR_R_VERSION}
    cp -r xtensor-r/include/xtensor-r ./inst/include
    rm -rf xtensor-r
fi

