On Thu, Aug 27, 2020 at 05:27:01PM +0200, Olivier Taïbi wrote:
> More is needed, see
> https://www.openbsd.org/faq/ports/specialtopics.html#SharedLibs
> I have a patch for building the shared library (a shared lib is needed
> in order to use gp2c).  I will clean it up, test it and send it here.
> Thanks for looking into porting sage to OpenBSD, I would be interested
> in using it!

Here is the patch to build the shared library in math/pari.  This also
disables gcc over cc preference in the configure script and fixes the
"honor CFLAGS" patch.

I imagine that in order to port sage many dependencies will need to be
ported first.  For gap at least, Kaashif Hymabaccus worked on a port:
https://marc.info/?l=openbsd-ports&m=156200332301577&w=2
but this has not been imported into the tree.  If you need help with
porting SageMath to OpenBSD, I am willing to help.

diff -uNpr /usr/ports/math/pari/Makefile /build/usr/ports/math/pari/Makefile
--- /usr/ports/math/pari/Makefile       Tue Jul 28 23:54:34 2020
+++ /build/usr/ports/math/pari/Makefile Fri Aug 28 08:57:35 2020
@@ -3,6 +3,7 @@
 COMMENT=       number theory-oriented computer algebra system
 
 V=             2.11.4
+REVISION=      0
 DISTNAME=      pari-$V
 CATEGORIES=    math
 
@@ -11,7 +12,7 @@ HOMEPAGE=     https://pari.math.u-bordeaux.fr/
 # GPLv2+
 PERMIT_PACKAGE=        Yes
 
-WANTLIB +=             X11 c gmp m readline
+WANTLIB +=             X11 c curses gmp m readline
 
 MASTER_SITES=          http://pari.math.u-bordeaux.fr/pub/pari/unix/ \
                        http://pari.math.u-bordeaux.fr/pub/pari/OLD/${V:R}/
@@ -19,6 +20,9 @@ MASTER_SITES=         http://pari.math.u-bordeaux.fr/pub/pari
 BUILD_DEPENDS=         print/texlive/base
 LIB_DEPENDS=           devel/gmp
 
+SHARED_LIBS +=         pari-gmp        0.0 \
+                       pari            0.0
+
 USE_GMAKE=             Yes
 
 CONFIGURE_SCRIPT=      Configure
@@ -29,11 +33,18 @@ CONFIGURE_ARGS+=    --datadir=${PREFIX}/share/pari \
                        --prefix=${PREFIX} \
                        --with-gmp=${PREFIX}
 
+LIBpari_MAJOR =        ${LIBpari_VERSION:R}
+LIBpari_MINOR =        ${LIBpari_VERSION:E}
+SUBST_VARS =           LIBpari_MAJOR LIBpari_MINOR
+
 TEST_TARGET=           dobench
 
 .if ${MACHINE_ARCH} == i386
 CFLAGS+=               -Wl,-znotext
 .endif
+
+pre-configure:
+       cd ${WRKSRC}; ${SUBST_CMD} config/get_dlld
 
 post-install:
        mv ${PREFIX}/share/pari/doc ${PREFIX}/share/doc/pari
diff -uNpr /usr/ports/math/pari/patches/patch-Configure 
/build/usr/ports/math/pari/patches/patch-Configure
--- /usr/ports/math/pari/patches/patch-Configure        Thu Jan  1 01:00:00 1970
+++ /build/usr/ports/math/pari/patches/patch-Configure  Fri Aug 28 08:57:35 2020
@@ -0,0 +1,18 @@
+$OpenBSD$
+
+use cc even if gcc is present
+
+Index: Configure
+--- Configure.orig
++++ Configure
+@@ -65,6 +65,10 @@ to aid debugging if Configure makes a mistake. Command
+ 
+ EOT
+ exec 5>> $config_log
++case "$osname" in
++  openbsd) gcc=;;
++esac
++
+ 
+ ####################### CONFIGURE - COMPILATION #############################
+ # $_cc_list (includes 'optimization'), extraflag
diff -uNpr /usr/ports/math/pari/patches/patch-config_Makefile_SH 
/build/usr/ports/math/pari/patches/patch-config_Makefile_SH
--- /usr/ports/math/pari/patches/patch-config_Makefile_SH       Thu Jan  1 
01:00:00 1970
+++ /build/usr/ports/math/pari/patches/patch-config_Makefile_SH Fri Aug 28 
08:57:35 2020
@@ -0,0 +1,30 @@
+$OpenBSD$
+
+Fix libpari*.so.MAJOR.MINOR names:
+LIBPARI_SO will be libpari.so.MAJOR.MINOR
+LIBPARI_DYN will be libpari-gmp.so.MAJOR.MINOR (with current options: gmp, no 
tls)
+
+Index: config/Makefile.SH
+--- config/Makefile.SH.orig
++++ config/Makefile.SH
+@@ -212,7 +212,7 @@ LIBPARI_BASE = $libpari_base
+ LIBPARI      = \$(LIB_PREFIX)pari
+ DLLIBPARI    = \$(DLLIB_PREFIX)pari
+ LIBPARI_STA  = \$(LIBPARI)\$(_A)
+-LIBPARI_SO   = \$(DLLIBPARI).$DLSUFFIX
++LIBPARI_SO   = \$(DLLIBPARI).$DLSUFFIX$sodest
+ SOLIBPARI    = \$(DLLIB_PREFIX)\$(LIBPARI_BASE).$DLSUFFIX
+ LIBPARI_DYN   = \$(SOLIBPARI)$sodest
+ LIBPARI_SONAME= \$(SOLIBPARI)$soname
+@@ -503,10 +503,8 @@ install-lib-dyn-base:
+       $install_implib
+ 
+ install-lib-dyn-link: install-lib-dyn-base
+-      -if test "\$(LIBPARI_DYN)" != "\$(LIBDIR)/\$(LIBPARI_SO)"; then \
++      -if test "\$(LIBPARI_DYN)" != "\$(LIBPARI_SO)"; then \
+           \$(LN) \$(LIBPARI_DYN) \$(LIBDIR)/\$(LIBPARI_SO); fi
+-      -if test "\$(LIBPARI_SONAME)" != "\$(LIBPARI_SO)"; then \
+-        \$(LN) \$(LIBPARI_DYN) \$(LIBDIR)/\$(LIBPARI_SONAME); fi
+ install-lib-dyn: \$(LIBPARI_DYN) install-lib-dyn-link
+ 
+ nsis: gp
diff -uNpr /usr/ports/math/pari/patches/patch-config_get_cc 
/build/usr/ports/math/pari/patches/patch-config_get_cc
--- /usr/ports/math/pari/patches/patch-config_get_cc    Thu Oct 17 03:09:22 2019
+++ /build/usr/ports/math/pari/patches/patch-config_get_cc      Fri Aug 28 
08:57:35 2020
@@ -1,16 +1,24 @@
-$OpenBSD: patch-config_get_cc,v 1.1 2019/10/17 01:09:22 daniel Exp $
+$OpenBSD$
 
 Honor CFLAGS.
 
 Index: config/get_cc
 --- config/get_cc.orig
 +++ config/get_cc
-@@ -89,7 +89,7 @@ if test -n "$__gnuc__"; then
+@@ -87,7 +87,7 @@ ASMINLINE=
+ if test -n "$__gnuc__"; then
+   __GNUC__="-D__GNUC__"
    warn="-Wall"
-   OPTFLAGS=-O3
+-  OPTFLAGS=-O3
++  OPTFLAGS=
    ASMINLINE=yes
--  OPTFLAGS="$OPTFLAGS $warn"
-+  OPTFLAGS="$CFLAGS $warn"
+   OPTFLAGS="$OPTFLAGS $warn"
    cmd="$CC $CFLAGS $extraflag -fno-strict-aliasing -o $exe gnu.c"
-   . log_cmd
-   if test -s $exe; then
+@@ -137,6 +137,7 @@ else
+                   sparc*) OPTFLAGS="$OPTFLAGS -xalias_level=any";;
+                 esac;;
+     concentrix-*) OPTFLAGS=-Ogi;;
++    openbsd-*)    OPTFLAGS=;;
+     *)            OPTFLAGS=-O;;
+   esac
+   PRFFLAGS="$PRFFLAGS $OPTFLAGS"
diff -uNpr /usr/ports/math/pari/patches/patch-config_get_dlcflags 
/build/usr/ports/math/pari/patches/patch-config_get_dlcflags
--- /usr/ports/math/pari/patches/patch-config_get_dlcflags      Thu Jan  1 
01:00:00 1970
+++ /build/usr/ports/math/pari/patches/patch-config_get_dlcflags        Fri Aug 
28 08:57:35 2020
@@ -0,0 +1,13 @@
+$OpenBSD$
+
+Index: config/get_dlcflags
+--- config/get_dlcflags.orig
++++ config/get_dlcflags
+@@ -12,6 +12,7 @@ else #assume native compiler
+   case "$osname" in
+     hpux) DLCFLAGS=+z;;
+     solaris) DLCFLAGS=-KPIC;;
++    openbsd) DLCFLAGS=-fPIC;;
+   esac
+ fi
+ 
diff -uNpr /usr/ports/math/pari/patches/patch-config_get_dlld 
/build/usr/ports/math/pari/patches/patch-config_get_dlld
--- /usr/ports/math/pari/patches/patch-config_get_dlld  Thu Jan  1 01:00:00 1970
+++ /build/usr/ports/math/pari/patches/patch-config_get_dlld    Fri Aug 28 
08:59:39 2020
@@ -0,0 +1,32 @@
+$OpenBSD$
+
+Fix shlib major.minor
+Avoid DT_SONAME hardcoding
+
+Index: config/get_dlld
+--- config/get_dlld.orig
++++ config/get_dlld
+@@ -14,6 +14,8 @@ case "$osname" in
+       *STABLE*)      sodest=.$version.$patch;; # released version
+       *DEVELOPMENT*) sodest=.$patch.0.0;;      # unstable version
+     esac ;;
++  openbsd) sodest=.${LIBpari_MAJOR}.${LIBpari_MINOR}
++           soname=$sodest;;
+   sunos) sodest=.$VersionMajor$VersionMinor.$patch
+          soname=$sodest;;
+   hpux) soname= ; sodest= ; DLSUFFIX=sl;;
+@@ -71,12 +73,13 @@ if test -n "$DLLD"; then
+   dlldflags="$DLLDFLAGS"
+   DLLDFLAGS=
+   if test -n "$GNUdlld"; then
+-    DLLDFLAGS="-shared -soname=\$(LIBPARI_SONAME)"
++    DLLDFLAGS="-shared"
+   else # DLLD != GNU ld
+     case "$osname" in
+       aix)     DLLDFLAGS='-r' ;;
+       darwin)  DLLDFLAGS="-compatibility_version $compat_ver -current_version 
$num_ver" ;;
+       freebsd) DLLDFLAGS='-Bshareable -x' ;;
++      openbsd) DLLDFLAGS='-shared' ;;
+       hpux)    DLLDFLAGS='-b' ;;
+       irix)    DLLDFLAGS='-shared -elf -no_unresolved -all' ;;
+       osf1)    DLLDFLAGS='-shared' ;;
diff -uNpr /usr/ports/math/pari/pkg/PLIST /build/usr/ports/math/pari/pkg/PLIST
--- /usr/ports/math/pari/pkg/PLIST      Thu Oct 17 08:35:06 2019
+++ /build/usr/ports/math/pari/pkg/PLIST        Fri Aug 28 08:57:35 2020
@@ -1,4 +1,4 @@
-@comment $OpenBSD: PLIST,v 1.3 2019/10/17 01:09:22 daniel Exp $
+@comment $OpenBSD: PLIST,v$
 bin/gp
 @bin bin/gp-2.11
 bin/gphelp
@@ -21,7 +21,8 @@ include/pari/paripriv.h
 include/pari/paristio.h
 include/pari/parisys.h
 include/pari/paritune.h
-@comment lib/libpari.a
+@lib lib/libpari-gmp.so.${LIBpari-gmp_VERSION}
+@lib lib/libpari.so.${LIBpari_VERSION}
 lib/pari/
 lib/pari/pari.cfg
 @man man/man1/gp-2.11.1

Reply via email to