cd src

if [ "$LINBOX_BLAS" != "" ]; then
    echo "Using environment variable LINBOX_BLAS=$LINBOX_BLAS"
else
    LINBOX_BLAS="$(pkg-config --libs cblas)"
    BLAS_CFLAGS="$(pkg-config --cflags cblas)"
    if [ "$BLAS_CFLAGS" != "" ]; then
        LINBOX_BLAS_CFLAGS="--with-blas-cflags=$BLAS_CFLAGS"
    else
        LINBOX_BLAS_CFLAGS=""
    fi
fi

echo "*************************************************"
echo "Using --with-blas-libs='$LINBOX_BLAS' '$LINBOX_BLAS_CFLAGS'"
echo "*************************************************"

# If SAGE_FAT_BINARY is set, disable all processor-specific optimizations
if [ "$SAGE_FAT_BINARY" = yes ]; then
    FFLAS_FFPACK_CONFIGURE="--disable-sse --disable-sse2 --disable-sse3 --disable-ssse3 --disable-sse41 --disable-sse42 --disable-fma --disable-fma4 --disable-avx --disable-avx2 $FFLAS_FFPACK_CONFIGURE"
fi

# Need to use 'bash' for configure, see
# https://trac.sagemath.org/ticket/23451
if [ -z "$CONFIG_SHELL" ]; then
    export CONFIG_SHELL=`command -v bash`
fi

# We disable openmp because of build failures, see
# http://trac.sagemath.org/ticket/17635#comment:67
sdh_configure --with-default="$SAGE_LOCAL" --with-blas-libs="$LINBOX_BLAS" \
              "$LINBOX_BLAS_CFLAGS" --disable-static \
              --enable-precompilation --disable-openmp $FFLAS_FFPACK_CONFIGURE
sdh_make

$MAKE autotune
if [ $? -ne 0 ]; then
    echo >&2 "Error tuning fflas-ffpack"
    exit 1
fi

sdh_make_install
