if [ "$SAGE64" = yes ]; then
    if [ -z $CFLAG64 ]; then
        CFLAG64=-m64
    fi
    CFLAGS="$CFLAGS $CFLAG64"
    CXXFLAGS="$CXXFLAGS $CFLAG64"
    echo "Building a 64-bit version of GAP (with '$CFLAG64')."
fi

if [ "$SAGE_DEBUG" == "yes" ] ; then
    # Note that -g3 allows you to use preprocessor macros in gdb which are widely used
    CFLAGS="$CFLAGS -O0 -g3 -DDEBUG_MASTERPOINTERS -DDEBUG_GLOBAL_BAGS -DDEBUG_FUNCTIONS_BAGS"
    #  -DDEBUG_HANDLER_REGISTRATION is broken
fi

source "$SAGE_LOCAL/gap/latest/sysinfo.gap"
echo "GAP was configured with $GAParch_system"

cd src

sdh_configure --disable-static \
              CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" CPPFLAGS="$CPPFLAGS" \
              --with-gap_system_arch="$GAParch_system" \
              --with-sage="$SAGE_LOCAL" --with-gmp="$SAGE_LOCAL"
sdh_make
sdh_make_install
