###########################################
## Singular
###########################################

SRC=`pwd`/src
cd "$SRC"

if [ "x$SAGE_DEBUG" = "xyes" ]; then
    # This used to disable omalloc but that is not really supported
    # by upstream
    SINGULAR_CONFIGURE="$SINGULAR_CONFIGURE --enable-debug --disable-optimizationflags"
fi

config()
{
    # configure notes (dates from Singular 3.x, maybe outdated for 4.x):
    # 1) We really need to add --exec-prefix and --bindir as Singular
    #    uses some weird defaults.
    # 2) configure calls other configure scripts (for example
    #    omalloc/configure).  Not all of these configure scripts
    #    support all options given here, leading to warnings which
    #    may be ignored.
    sdh_configure --exec-prefix="$SAGE_LOCAL" \
                  --bindir="$SAGE_LOCAL/bin" \
                  $SAGE_CONFIGURE_GMP \
                  $SAGE_CONFIGURE_NTL \
                  $SAGE_CONFIGURE_FLINT \
                  --enable-gfanlib \
                  --enable-Singular \
                  --enable-factory \
                  --disable-doc \
                  --disable-polymake \
                  --without-python \
                  --without-pythonmodule \
                  --disable-python \
                  --disable-python_module \
                  --disable-python-module \
                  --disable-static \
                  --with-libparse \
                  $SINGULAR_CONFIGURE
}


build_singular()
{
    sdh_make
    sdh_make_install

    # Singular tarballs made using "make dist" (without --enable-doc-build) do not contain built documentation.
    if [ ! -e doc/doc.tbz2 ]; then
        (cd doc && make singular.info && sdh_install singular.info "$SAGE_SHARE/info/") || sdh_die "Building documentation failed"
    fi
}


# Actually run all the functions defined above
for i in config build_singular; do
    echo "############### Singular stage $i ###############"
    cd "$SRC" && $i
done
