#!/bin/sh

# Parse command-line arguments
for i in "$@"
do
case $i in
    # Option with value
    # =================

    #-e=*|--extension=*)
    #EXTENSION="${i#*=}"
    #shift # past argument=value
    #;;

    # Option without a value
    # ======================
    --novendor)
    NO_VENDOR_XTENSOR=YES
    shift # pass argument with no value
    ;;

    # Unknown option
    # ==============
    *)
          # unknown option
    ;;
esac
done

# Call vendor script to fetch dependencies
if [ "${NO_VENDOR_XTENSOR}" = "YES" ]
then
    echo "Vendoring of xtensor headers is disabled."
    # Delete vendored xtl xsimd xtensor xtensor-r
    # if it is included in the built package.
    rm -rf ./inst/include/xtl
    rm -rf ./inst/include/xsimd
    rm -rf ./inst/include/xtensor
    rm -rf ./inst/include/xtensor-r
else
    echo "Vendoring of xtensor headers is enabled."
    # Fetch xtl xsimd xtensor xtensor-r
    # if it is not included in the build package.
    sh ./tools/vendor
fi

# Run Rcpp compiler Attributes
${R_HOME}/bin${R_ARCH_BIN}/R -q -e "library('Rcpp');Rcpp::compileAttributes();"
