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

export CFLAGS="-O2 -g $CFLAGS -fPIC -DFAST -DALLTRUE"


cd src


# Patching the upstream makefile doesn't make sense,
# as it has (syntactically) nothing in common with ours.
cp -f ../patches/makefile makefile
if [ $? -ne 0 ]; then
    echo >&2 "Error copying over patched Makefile."
    exit 1
fi

$MAKE
if [ $? -ne 0 ]; then
    echo >&2 "Error building Symmetrica."
    exit 1
fi

cp -f libsymmetrica.a "$SAGE_LOCAL"/lib/
if [ $? -ne 0 ]; then
    echo >&2 "Error installing the Symmetrica library."
    exit 1
fi

mkdir -p "$SAGE_LOCAL"/include/symmetrica &&
cp -f *.h "$SAGE_LOCAL"/include/symmetrica/
if [ $? -ne 0 ]; then
    echo >&2 "Error installing Symmetrica's header files."
    exit 1
fi
