if [[ -z "$SAGE_LOCAL" ]]; then
    echo >&2 "Error: SAGE_LOCAL undefined - exiting..."
    echo >&2 "Maybe run 'sage -sh'?"
    exit 1
fi

#################################
# Set up environment variables: #
#################################

if [[ -z $CFLAG64 ]]; then
    CFLAG64=-m64
fi
if [[ -z $CXXFLAG64 ]]; then
    CXXFLAG64="$CFLAG64"
fi
if [[ "$SAGE64" = yes ]]; then
    echo "Building a 64-bit version of Givaro's test suite."
    CFLAGS="$CFLAGS $CFLAG64"
    CPPFLAGS="$CPPFLAGS $CFLAG64"
    CXXFLAGS="$CXXFLAGS $CXXFLAG64"
    LDFLAGS="$LDFLAGS $CFLAG64"
fi

# It shouldn't be necessary to add Sage's include directory here,
# since we configure with '--with-gmp=...'.
# Also, '-I...' should normally be added to (just) CPPFLAGS.
CFLAGS="$CFLAGS -fPIC -I\"$SAGE_LOCAL/include\""
CXXFLAGS="$CXXFLAGS -fPIC -I\"$SAGE_LOCAL/include\""

export CFLAGS CPPFLAGS CXXFLAGS LDFLAGS


cd src/

echo "Building and running Givaro's test suite..."
$MAKE check
if [[ $? -ne 0 ]]; then
    echo >&2 "Error while building or running Givaro's test suite."
    exit 1
fi
echo "Givaro's test suite passed."
