if [ "$SAGE_DEBUG" = yes ]; then
    echo >&2 "Warning: Setting SAGE_DEBUG=yes completely disables optimization."
    CFLAGS="$CFLAGS -g -O0"
    CXXFLAGS="$CXXFLAGS -g -O0"
else
    # Add debug symbols by default, enable optimization, but let the user
    # still override these settings:
    CFLAGS="-g -O3 $CFLAGS"
    CXXFLAGS="-g -O3 $CXXFLAGS"
fi

export CFLAGS CPPFLAGS CXXFLAGS LDFLAGS


echo "Deleting old versions of eclib libraries, which"
echo "would interfere with new builds..."
# Delete any pre-autotools libraries:
rm -f "$SAGE_LOCAL"/lib/lib{curvesntl,g0nntl,jcntl,rankntl,mwrank}.*
# Delete autotools libraries:
rm -f "$SAGE_LOCAL"/lib/lib{e,j}c.*
if [ "$UNAME" = "CYGWIN" ]; then
    rm -f "$SAGE_LOCAL"/lib/cyg{e,j}c-*.dll
fi
echo "Deleting old include directory..."
rm -rf "$SAGE_LOCAL"/include/eclib/


cd src/


sdh_configure --with-ntl="$SAGE_LOCAL" \
              --with-pari="$SAGE_LOCAL" \
              --with-flint="$SAGE_LOCAL" \
              --with-boost="no" \
              --disable-allprogs
sdh_make
sdh_make_install
