cd src

# OpenBlas has no proper configure script
# Options are directly passed to make
# And the name static library archive produced depends on them
# And the tests directly link to that archive rather than through a symlink
# Therefore the following is copied from spkg-install
# We could also patch the Makefile to use a generic symlink pointing
# to the archive with a specific name

if [ `python -c "from __future__ import print_function; import platform; print(platform.architecture()[0])"` = "32bit" ]; then
    OPENBLAS_CONFIGURE="$OPENBLAS_CONFIGURE BINARY=32"
fi

if [ "x$SAGE_FAT_BINARY" = "xyes" ]; then
    # See https://github.com/xianyi/OpenBLAS/issues/510
    OPENBLAS_CONFIGURE="$OPENBLAS_CONFIGURE TARGET=PRESCOTT"
fi

echo "Running OpenBLAS testsuite"

sdh_make tests $OPENBLAS_CONFIGURE
if [ $? -ne 0 ]; then
    # First make sure we already didn't set a target
    if [[ $OPENBLAS_CONFIGURE == *"TARGET"* ]]; then
        sdh_die "Error while running the OpenBlas testsuite ... exiting"
    else
        # The recommended TARGET is ATOM if CPU fails
        # See https://github.com/xianyi/OpenBLAS/issues/1204
        OPENBLAS_CONFIGURE="$OPENBLAS_CONFIGURE TARGET=ATOM"
        echo "Error while testing the OpenBLAS testsuite"
        echo "Retrying the OpenBAS testsuit with TARGET=ATOM"
        sdh_make tests $OPENBLAS_CONFIGURE
        if [ $? -ne 0 ]; then
            sdh_die "Error while running the OpenBLAS testsuite ... exiting"
        fi
    fi
fi
