Skip to content

GAP libsing in Sage with patches

mohamed-barakat edited this page Aug 28, 2012 · 2 revisions

How to install libsing in GAP in Sage

  • Install gap-4.5.5 in Sage, if needed (see Sage trac #13211). That just amounts to

    sage -i http://www.stp.dias.ie/~vbraun/Sage/spkg/gap-4.5.5.spkg
    sage -i http://www.stp.dias.ie/~vbraun/Sage/spkg/gap_packages-4.5.5.spkg
    sage -i http://www.stp.dias.ie/~vbraun/Sage/spkg/database_gap-4.5.5.spkg
    
  • Install a modified version of the Singular-3-1-5 spkg from Sage trac #13237. Here, you have to apply two patches to the Sage library. Then download the spkg, and open it:

    tar -xjf singular-3-1-5.p0.spkg
    

    Then, create a new file singular-3-1-5.p0/patches/install_table.patch with the following content:

    --- src/Singular/Makefile.in    2012-07-11 11:00:13.000000000 +0100
    +++ src/Singular/Makefile.in    2012-08-27 16:22:26.013159361 +0100
    @@ -599,7 +599,7 @@
              ${INSTALL_PROGRAM}  $$file ${libdir}; \
            done
            ${INSTALL_PROGRAM} libsingular.h ${includedir}
    -       for file in subexpr.h tok.h grammar.h ipid.h lists.h ipshell.h attrib.h; do \
    +       for file in subexpr.h tok.h grammar.h ipid.h lists.h ipshell.h attrib.h table.h; do \
            sed -e "s:<kernel/:<singular/:" < $$file |sed -e "s:<Singular/:<singular/:"|sed -e "s:<omalloc/:<:"|sed -e "s:<factory/:<:" >${includedir}/singular/$$file ;\
            done
    

    Pack the package again:

    tar -cjf singular-3-1-5.p1.spkg singular-3-1-5.p0
    

    Install it and rebuild Sage:

    sage -i singular-3-1-5.p1.spkg
    sage -b
    
  • Open a Sage shell (sage -sh)

  • Issue the commands

    cd $SAGE_LOCAL/gap-newest/pkg
    hg clone ssh://hg@hg.gap-system.org/libsingular
    cd libsingular
    
  • Issue the commands

    export LDFLAGS="-L$SAGE_LOCAL/lib -ldl -lpthread"
    export CFLAGS="-I$SAGE_LOCAL/include"
    export CPPFLAGS="-I$SAGE_LOCAL/include"
    
  • Edit $SAGE_LOCAL/gap-newest/src/gmpints.h, comment out the lines 54-58:

    #ifndef __GNU_MP_RELEASE
     #if __GMP_MP_RELEASE < 50002
     #error Aborting compile: GAP requires GMP 5.0.2 or newer
     #endif
    #endif
    
  • Modify the sources according to the following diff:

    diff --git a/SINGULARVERSION b/SINGULARVERSION
    deleted file mode 100644
    --- a/SINGULARVERSION
    +++ /dev/null
    @@ -1,1 +0,0 @@
    -3-1-5
    diff --git a/src/Makefile.am b/src/Makefile.am
    --- a/src/Makefile.am
    +++ b/src/Makefile.am
    @@ -1,19 +1,17 @@
     BINARCHDIR = bin/$(GAPARCH)
     GAPINSTALLLIB = $(abs_top_srcdir)/$(BINARCHDIR)/libsing.so
    -SINGULARNAME = Singular-`cat ../SINGULARVERSION`
    -SINGARCHNAME = `cat ../SINGARCHNAME`
    
     lib_LTLIBRARIES = libsing.la
     bin_PROGRAMS = gentableforGAP
    
     gentableforGAP_SOURCES = gentableforGAP.cc
    -gentableforGAP_CPPFLAGS = -I../${SINGULARNAME} -I../${SINGULARNAME}/Singular
    -gentableforGAP_LDFLAGS = -R${abs_top_srcdir}/${SINGULARNAME}/Singular -L${abs_top_srcdir}/${SINGULARNAME}/Singular -R${abs_top_srcdir}/${SINGULARNAME}/${SINGARCHNAME}/lib -lsingular -lpthread
    +gentableforGAP_CPPFLAGS =
    +gentableforGAP_LDFLAGS = -lsingular -lpthread
    
     libsing_la_SOURCES = libsing.c libsing.h cxxfuncs.cc
    -libsing_la_LDFLAGS = -module -avoid-version -R${abs_top_srcdir}/${SINGULARNAME}/Singular -L${abs_top_srcdir}/${SINGULARNAME}/Singular -R${abs_top_srcdir}/${SINGULARNAME}/${SINGARCHNAME}/lib -lsingular -lpthread
    +libsing_la_LDFLAGS = -module -avoid-version -lsingular -lpthread
     libsing_la_LIBADD =
    -libsing_la_CPPFLAGS = $(GAP_CPPFLAGS) -I../${SINGULARNAME}/${SINGARCHNAME}/include
    +libsing_la_CPPFLAGS = $(GAP_CPPFLAGS)
    
     # Change it so that make all also does a make install (to build the .so)
     # and then copies it to the correct bin directory
    diff --git a/src/Makefile.in b/src/Makefile.in
    --- a/src/Makefile.in
    +++ b/src/Makefile.in
    @@ -251,16 +251,14 @@
     top_srcdir = @top_srcdir@
     BINARCHDIR = bin/$(GAPARCH)
     GAPINSTALLLIB = $(abs_top_srcdir)/$(BINARCHDIR)/libsing.so
    -SINGULARNAME = Singular-`cat ../SINGULARVERSION`
    -SINGARCHNAME = `cat ../SINGARCHNAME`
     lib_LTLIBRARIES = libsing.la
     gentableforGAP_SOURCES = gentableforGAP.cc
    -gentableforGAP_CPPFLAGS = -I../${SINGULARNAME} -I../${SINGULARNAME}/Singular
    -gentableforGAP_LDFLAGS = -R${abs_top_srcdir}/${SINGULARNAME}/Singular -L${abs_top_srcdir}/${SINGULARNAME}/Singular -R${abs_top_srcdir}/${SINGULARNAME}/${SINGARCHNAME}/lib -lsingular -lpthread
    +gentableforGAP_CPPFLAGS =
    +gentableforGAP_LDFLAGS = -lsingular -lpthread
     libsing_la_SOURCES = libsing.c libsing.h cxxfuncs.cc
    -libsing_la_LDFLAGS = -module -avoid-version -R${abs_top_srcdir}/${SINGULARNAME}/Singular -L${abs_top_srcdir}/${SINGULARNAME}/Singular -R${abs_top_srcdir}/${SINGULARNAME}/${SINGARCHNAME}/lib -lsingular -lpthread
    +libsing_la_LDFLAGS = -module -avoid-version -lsingular -lpthread
     libsing_la_LIBADD =
    -libsing_la_CPPFLAGS = $(GAP_CPPFLAGS) -I../${SINGULARNAME}/${SINGARCHNAME}/include
    +libsing_la_CPPFLAGS = $(GAP_CPPFLAGS)
     all: pkgconfig.h
            $(MAKE) $(AM_MAKEFLAGS) all-am
    
    diff --git a/src/gentableforGAP.cc b/src/gentableforGAP.cc
    --- a/src/gentableforGAP.cc
    +++ b/src/gentableforGAP.cc
    @@ -14,9 +14,9 @@
     #include <time.h>
     #include <unistd.h>
    
    -#include <Singular/mod2.h>
    -#include <Singular/tok.h>
    -#include <Singular/grammar.h>
    +#include <singular/mod2.h>
    +#include <singular/tok.h>
    +#include <singular/grammar.h>
    
     // to produce convert_table.texi for doc:
     //#define CONVERT_TABLE 1
    @@ -112,7 +112,7 @@
     #define IPCONV
     #define IPASSIGN
    
    -#include "table.h"
    +#include "singular/table.h"
    
     const char * Tok2Cmdname(int tok)
     {
    
  • Issue the commands

    autoreconf -v
    ./configure --with-gaproot=$SAGE_LOCAL/gap-newest
    make
    
  • Run some example, such as the one in $SAGE_LOCAL/gap-newest/pkg/libsingular/example.