[bug#66606,v2] gnu: Add reduce-csl.

Message ID fc6503960756bec07de7ba4af161278cfe3147da.1738860011.git.nigko.yerden@gmail.com
State New
Headers
Series [bug#66606,v2] gnu: Add reduce-csl. |

Commit Message

Nigko Yerden Feb. 6, 2025, 4:40 p.m. UTC
  * gnu/packages/math.scm (reduce-csl): New variable.
* gnu/packages/patches/reduce-csl.patch: New patch which unbundles libffi.

Change-Id: Ic85be7dc490f005f7ba65c418250cc9681fbb3a8
---
Hello,

Andreas Enge wrote:
>sorry for overlooking this patch for so long!
>
>The commit currently does not apply with "git am"; would you be able to
>provide a v2 that applies?
>I also wonder if you could already unbundle libffi.
>
>> +     (list #:tests? #f
>
>Are there no tests? If this is the case, please add a comment.
>Otherwise it would be good to enable the tests.
>
I rewrote this old patch. New patch provides
1. Updated package revision number 6860 (was 6547).
2. Apparent reproducibility of the package.
3. 'check' build phase for running tests.
4. Unbundled libffi.

>> +                        (add-after 'install 'fix-install
>> +                          (lambda _
>> +                            (delete-file-recursively (string-append #$output
>> +                                                                    "/man"))
>
>Why is this needed?
This was the wrong location for the man pages coming from upstream rev. 6547.
(it should be "share/man/man.1"). The current upstream version is
free from this bug and these lines were removed in consequence.

Regards,
Nigko

 gnu/packages/maths.scm                | 103 +++++++++++++++++++++
 gnu/packages/patches/reduce-csl.patch | 125 ++++++++++++++++++++++++++
 2 files changed, 228 insertions(+)
 create mode 100644 gnu/packages/patches/reduce-csl.patch


base-commit: 5c5f72cac9c49db918eba158d0c751ab1be1e95a
  

Patch

diff --git a/gnu/packages/maths.scm b/gnu/packages/maths.scm
index c3017976f6..33fc692375 100644
--- a/gnu/packages/maths.scm
+++ b/gnu/packages/maths.scm
@@ -67,6 +67,7 @@ 
 ;;; Copyright © 2024 Foundation Devices, Inc. <hello@foundation.xyz>
 ;;; Copyright © 2024, 2025 Artyom V. Poptsov <poptsov.artyom@gmail.com>
 ;;; Copyright © 2024 Zheng Junjie <873216071@qq.com>
+;;; Copyright © 2025 Nigko Yerden <nigko.yerden@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -197,6 +198,7 @@  (define-module (gnu packages maths)
   #:use-module (gnu packages wxwidgets)
   #:use-module (gnu packages xdisorg)
   #:use-module (gnu packages xml)
+  #:use-module (gnu packages libffi)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-26))
 
@@ -5398,6 +5400,107 @@  (define-public maxima
     ;; GPLv2 only is therefore the smallest subset.
     (license license:gpl2)))
 
+(define-public reduce-csl
+  (package
+    (name "reduce-csl")
+    (version "6860")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append
+                    "mirror://sourceforge/reduce-algebra/snapshot_"
+                    "2024-08-12" "/Reduce-svn" version "-src.tar.gz"))
+              (sha256
+               (base32
+                "13bij9d4dj96vd5di59skz77s2fihj7awmkx403fvh9rd04ly25z"))
+              (modules '((guix build utils)))
+              ;; unbundle libffi
+              (patches (search-patches "reduce-csl.patch"))
+              ;; remove binaries and unnecessary parts
+              ;; to ensure we build from source files only
+              (snippet '(map delete-file-recursively
+                         (append (find-files "csl/generated-c" "\\.img$")
+                          '("psl" "vsl"
+                            "jlisp"
+                            "jslisp"
+                            "libedit"
+                            "macbuild"
+                            "MacPorts"
+                            "mac-universal"
+                            "reduce2"
+                            "winbuild64"
+                            "common-lisp"
+                            "contrib"
+                            "generic/qreduce"
+                            "web/htdocs/images/Thumbs.db")
+                          (find-files "csl"
+                           "^(embedded|new-embedded|winbuild|support-packages)$"
+                           #:directories? #t)
+                          (find-files "libraries"
+                           "^(original|wineditline|libffi|libffi-for-mac)$"
+                           #:directories? #t))))))
+    (build-system gnu-build-system)
+    (arguments
+     (list #:configure-flags
+           #~(list "--without-autogen"
+                   ;; fix conflict with internal build name determination
+                   "--build="
+                   "--with-csl"
+                   (string-append "CPPFLAGS=-I"
+                                  #$freetype
+                                  "/include/freetype2"))
+           #:make-flags #~(list "csl")
+           #:phases
+           #~(modify-phases %standard-phases
+               (replace 'check
+                 (lambda* (#:key tests? #:allow-other-keys)
+                   (when tests?
+                     (invoke "scripts/testall.sh" "--csl" "--noregressions"))))
+               (add-before 'patch-source-shebangs 'autogen
+                 (lambda _
+                   (invoke "sh" "autogen.sh")))
+               (add-after 'install 'fix-install
+                 (lambda _
+                   (copy-file "bin/rfcsl"
+                              (string-append #$output "/bin/rfcsl"))
+                   (copy-file "generic/newfront/redfront.1"
+                              (string-append #$output
+                                             "/share/man/man1/rfcsl.1"))
+                   (let ((.desktop-file
+                          "debianbuild/reduce/debian/redcsl.desktop")
+                         (icon "debianbuild/reduce/debian/reduce.png"))
+                     (install-file .desktop-file
+                                   (string-append #$output
+                                                  "/share/applications"))
+                     (install-file icon
+                                   (string-append
+                                    #$output
+                                    "/share/icons/hicolor/32x32/apps")))
+                   (with-directory-excursion #$output
+                     (map (lambda (dir)
+                            (map (lambda (file)
+                                   (chmod file #o444))
+                                 (find-files dir)))
+                          '("share/man/man1" "share/reduce/fonts"))))))))
+    (native-inputs (list which autoconf automake libtool))
+    (inputs
+     ;; bundled libraries: fox (adjusted) editline (adjusted)
+     ;; libffi (unbundled, see patch) crlibm softfloat
+     (list ncurses freetype libxft libx11 libxext libffi))
+    (synopsis "Portable general-purpose computer algebra system")
+    (description
+     "REDUCE is a portable general-purpose computer algebra system.  It is a
+system for doing scalar, vector and matrix algebra by computer, which also
+supports arbitrary precision numerical approximation and interfaces to gnuplot
+to provide graphics.  It can be used interactively for simple calculations but
+also provides a full programming language, with a syntax similar to other
+modern programming languages.  REDUCE supports alternative user interfaces
+including Run-REDUCE, TeXmacs and GNU Emacs.  This package provides Codemist
+Standard Lisp (CSL) version of REDUCE.  It uses gnuplot program, if installed,
+to make figures.")
+    (home-page "https://reduce-algebra.sourceforge.io/")
+    (license (license:non-copyleft "file://README"
+                                   "See README in the deistribution."))))
+
 (define-public wxmaxima
   (package
     (name "wxmaxima")
diff --git a/gnu/packages/patches/reduce-csl.patch b/gnu/packages/patches/reduce-csl.patch
new file mode 100644
index 0000000000..21529840b6
--- /dev/null
+++ b/gnu/packages/patches/reduce-csl.patch
@@ -0,0 +1,125 @@ 
+This patch unbundles libffi.
+
+Index: autogen.sh
+===================================================================
+diff --git a/autogen.sh b/autogen.sh
+--- a/autogen.sh	(revision 6860)
++++ b/autogen.sh	(working copy)
+@@ -142,18 +142,6 @@
+   ;;
+ *--with-csl* | *--with-both*)
+   L="$L ./csl ./csl/cslbase ./csl/cslbase-nothrow ./libraries/SoftFloat-3a/source"
+-# On Apple m1 (ie arm64) I will want to build a universal version of the
+-# libffi library and that is done in a way that differs from standrad builds.
+-  case "`uname -s` `uname -m`" in
+-  *Darwin*arm64*)
+-    L="$L ./libraries/libffi-for-mac/libffi-3.3-arm64"
+-    L="$L ./libraries/libffi-for-mac/libffi-3.3-x86_64"
+-    L="$L ./libraries/libffi"
+-    ;;
+-  *)
+-    L="$L ./libraries/libffi"
+-    ;;
+-  esac
+   case $a in
+   *--without-fox* | *with-fox=no* | \
+   *--without-gui* | *with-gui=no*)
+Index: configure.ac
+===================================================================
+diff --git a/configure.ac b/configure.ac
+--- a/configure.ac	(revision 6860)
++++ b/configure.ac	(working copy)
+@@ -1389,37 +1389,6 @@
+   cd "$builddir"
+ fi
+ 
+-AC_MSG_NOTICE([About to configure libffi])
+-mkdir -p libffi
+-if test `uname` = "Darwin" && test "$enable_universal" != "no"
+-then
+-# This is a messy script that arranges to build a universal version of
+-# the library on MacOS. It does this by building arm64 and an x86_64
+-# separately and then merging the resulting libraries.
+-  sed "s+@srcdir@+$abssrcdir+" \
+-     < $abssrcdir/libraries/libffi-for-mac/Makefile \
+-     > libffi/Makefile
+-else
+-  cd libffi
+-  setpasscc
+-  doconfig="$SHELL $abssrcdir/libraries/libffi/configure -C $filtered \
+-          $pass_host \
+-          CPPFLAGS=\"$CPPFLAGS\" \
+-          CFLAGS=\"$CFLAGS\" \
+-          CXXFLAGS=\"$CXXFLAGS\" \
+-          LDFLAGS=\"$LDFLAGS\" \
+-          $passcc \
+-          --disable-multi-os-directory \
+-          --disable-docs \
+-          --prefix=\"$builddir\" \
+-          --libdir=\"$builddir/lib\" \
+-          --includedir=\"$builddir/include\""
+-  AC_MSG_NOTICE([doconfig = $doconfig])
+-  printf "\n\n+++ About to configure libffi +++\n\n"
+-  eval "$doconfig"
+-  cd "$builddir"
+-fi
+-
+ AC_MSG_NOTICE([About to configure libsoftfloat])
+ mkdir -p softfloat
+ cd softfloat
+Index: csl/cslbase/Makefile.am
+===================================================================
+diff --git a/csl/cslbase/Makefile.am b/csl/cslbase/Makefile.am
+--- a/csl/cslbase/Makefile.am	(revision 6860)
++++ b/csl/cslbase/Makefile.am	(working copy)
+@@ -807,35 +807,6 @@
+ 
+ endif !crlibm
+ 
+-LIBFFIDEPS=../lib/libffi.a ../include/ffi.h
+-
+-FFIDEP = ../include/ffi.h
+-FFIINC = -I../include
+-AM_CPPFLAGS     += $(FFINC)
+-reduce_CPPFLAGS += $(FFINC)
+-bootstrapreduce_CPPFLAGS += $(FFINC)
+-csl_CPPFLAGS    += $(FFINC)
+-flatcsl_CPPFLAGS    += $(FFINC)
+-
+-# The following ugly dependencies are here so that one can go, for
+-# instance, "make csl.o" in a clean tree and libffi building will get
+-# triggered.
+-
+-
+-csl_LDADD += ../lib/libffi.a
+-flatcsl_LDADD += ../lib/libffi.a
+-bootstrapreduce_LDADD += ../lib/libffi.a
+-reduce_LDADD += ../lib/libffi.a
+-
+-csl_DEPENDENCIES += $(LIBFFIDEPS)
+-flatcsl_DEPENDENCIES += $(LIBFFIDEPS)
+-bootstrapreduce_DEPENDENCIES += $(LIBFFIDEPS)
+-reduce_DEPENDENCIES += $(LIBFFIDEPS)
+-
+-$(LIBFFIDEPS):
+-	@printf "About to build libffi for %s ($@)\n" `pwd`
+-	-$(TRACE)@$(MAKE) -C ../libffi install
+-
+ SOFTFLOATDEPS=../lib/libsoftfloat.a ../include/softfloat.h
+ 
+ SOFTFLOATDEP = ../include/softfloat.h
+Index: csl/cslbase/configure.ac
+===================================================================
+diff --git a/csl/cslbase/configure.ac b/csl/cslbase/configure.ac
+--- a/csl/cslbase/configure.ac	(revision 6860)
++++ b/csl/cslbase/configure.ac	(working copy)
+@@ -146,8 +146,8 @@
+   AC_DEFINE(WITHOUT_FFI, [1], [remove the foreign function support])
+ fi
+ 
++AC_SEARCH_LIBS([ffi_call], [ffi])
+ 
+-
+ # What host am I on?
+ AC_CANONICAL_HOST()
+