Github messages for voidlinux
 help / color / mirror / Atom feed
* [PR PATCH] [RFC] maxima: add a subpkg maxima-ecl needed for sagemath
@ 2021-11-27 23:25 tornaria
  2021-11-28 12:51 ` tornaria
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: tornaria @ 2021-11-27 23:25 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1831 bytes --]

There is a new pull request by tornaria against master on the void-packages repository

https://github.com/tornaria/void-packages maxima
https://github.com/void-linux/void-packages/pull/34273

[RFC] maxima: add a subpkg maxima-ecl needed for sagemath
 - Added a build option 'ecl' (enabled by default)
 - The ecl binary and library will be in a subpkg maxima-ecl so this
   should not affect current users of maxima
 - new patches:
   - a0d7a43...: build a FASL library for ECL (this is merged upstream)
   - handle-multiple-ldflags.patch: otherwise compilation with multiple options in LDFLAGS fails (taken from debian)
   - matrixexp.patch: fixes an error in matrix exponentiation (taken from debian, this originates in sagemath)

A weak point is that the library maxima.fas is installed in
/usr/lib/ecl-${ecl_version} which is where ecl looks for them, but this
doesn't seem right.

Maybe an alternative would be to have the ecl package ship a symlink at
/usr/lib/ecl pointing to the versioned directory, then have the
maxima-ecl package place its library in the non-versioned directory.

#### Testing the changes
- I tested the changes in this PR: **briefly**

To compile sagemath using system maxima, two things are necessary:
 - the maxima-ecl package that this PR introduces
 - the (yet unmerged) changes for sagemath in https://trac.sagemath.org/ticket/32867
Using both I compiled and doctested sagemath, and it seems to be working ok.

#### RFC
My doubts are:
- where to place the library `maxima.fas` as discussed above
- whether to have a build_option for ecl or just hardcode it as enabled
- whether to split the `maxima-ecl` package or place the two files it contains in the package `maxima` itself

A patch file from https://github.com/void-linux/void-packages/pull/34273.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-maxima-34273.patch --]
[-- Type: text/x-diff, Size: 8240 bytes --]

From 0e548f6e328e538757467d2b98ca65614537cca4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= <tornaria@cmat.edu.uy>
Date: Sat, 27 Nov 2021 19:38:48 -0300
Subject: [PATCH] maxima: add a subpkg maxima-ecl needed for sagemath

 - Added a build option 'ecl' (enabled by default)
 - The ecl binary and library will be in a subpkg maxima-ecl so this
   should not affect current users of maxima
 - new patches:
   - a0d7a43...: build a FASL library for ECL (this is merged upstream)
   - handle-multiple-ldflags.patch: otherwise compilation with multiple
     options in LDFLAGS fails (taken from debian)
   - matrixexp.patch: fixes an error in matrix exponentiation (taken
     from debian, this originates in sagemath)

A weak point is that the library maxima.fas is installed in
/usr/lib/ecl-${ecl_version} which is where ecl looks for them, but this
doesn't seem right.

Maybe an alternative would be to have the ecl package ship a symlink at
/usr/lib/ecl pointing to the versioned directory, then have the
maxima-ecl package place its library in the non-versioned directory.
---
 srcpkgs/maxima-ecl                            |  1 +
 ...a43e5234305bd6f1de5909d4ce5d7e1ea864.patch | 24 +++++++++++
 .../patches/handle-multiple-ldflags.patch     | 43 +++++++++++++++++++
 srcpkgs/maxima/patches/matrixexp.patch        | 23 ++++++++++
 srcpkgs/maxima/template                       | 34 ++++++++++++---
 5 files changed, 120 insertions(+), 5 deletions(-)
 create mode 120000 srcpkgs/maxima-ecl
 create mode 100644 srcpkgs/maxima/patches/a0d7a43e5234305bd6f1de5909d4ce5d7e1ea864.patch
 create mode 100644 srcpkgs/maxima/patches/handle-multiple-ldflags.patch
 create mode 100644 srcpkgs/maxima/patches/matrixexp.patch

diff --git a/srcpkgs/maxima-ecl b/srcpkgs/maxima-ecl
new file mode 120000
index 000000000000..b8b0e8240fa4
--- /dev/null
+++ b/srcpkgs/maxima-ecl
@@ -0,0 +1 @@
+maxima
\ No newline at end of file
diff --git a/srcpkgs/maxima/patches/a0d7a43e5234305bd6f1de5909d4ce5d7e1ea864.patch b/srcpkgs/maxima/patches/a0d7a43e5234305bd6f1de5909d4ce5d7e1ea864.patch
new file mode 100644
index 000000000000..e1ac1e5f6086
--- /dev/null
+++ b/srcpkgs/maxima/patches/a0d7a43e5234305bd6f1de5909d4ce5d7e1ea864.patch
@@ -0,0 +1,24 @@
+commit a0d7a43e5234305bd6f1de5909d4ce5d7e1ea864
+Author: Robert Dodier <robert_dodier@users.sourceforge.net>
+Date:   Mon Oct 11 22:40:13 2021 -0700
+
+    Apply patch #80: "Build a FASL library, needed by SageMath"
+    
+    This modifies maxima.system for ECL only.
+
+diff --git a/src/maxima.system b/src/maxima.system
+index d954bc2b9..525fb778e 100644
+--- a/src/maxima.system
++++ b/src/maxima.system
+@@ -75,6 +75,11 @@
+ 			     ;; Convert dir/foo.fas to dir/foo.o
+ 			     (make-pathname :type "o" :defaults p))
+ 			 files)))
++	(c::build-fasl "binary-ecl/maxima" :lisp-files obj
++			  :ld-flags
++			  (let ((x (symbol-value (find-symbol "*AUTOCONF-LD-FLAGS*"
++							      (find-package "MAXIMA")))))
++			    (if (and x (not (string= x ""))) (list x))))
+ 	(c::build-program "binary-ecl/maxima" :lisp-files obj
+ 			  :ld-flags
+ 			  (let ((x (symbol-value (find-symbol "*AUTOCONF-LD-FLAGS*"
diff --git a/srcpkgs/maxima/patches/handle-multiple-ldflags.patch b/srcpkgs/maxima/patches/handle-multiple-ldflags.patch
new file mode 100644
index 000000000000..799fc15f9185
--- /dev/null
+++ b/srcpkgs/maxima/patches/handle-multiple-ldflags.patch
@@ -0,0 +1,43 @@
+Description: Handle multiple LDFLAGS
+ Without this patch, building with LDFLAGS containing more than one flag results 
+ in flags being dropped.
+Author: Graham Inggs <ginggs@debian.org>
+Bug-Debian: http://bugs.debian.org/847925
+
+--- a/src/maxima.system
++++ b/src/maxima.system
+@@ -58,6 +58,19 @@
+     (and (apply #'compile-file file :output-file object-output args)
+ 	 (c:build-fasl output :lisp-files (list object-output)))))
+ 
++(defun split-string (string &key (item #\space) (test #'char=))
++  ;; Splits the string into substrings at spaces.
++  (let ((len (length string))
++	(index 0) result)
++    (dotimes (i len
++		(progn (unless (= index len)
++			 (push (subseq string index) result))
++		       (reverse result)))
++      (when (funcall test (char string i) item)
++	(unless (= index i);; two spaces in a row
++	  (push (subseq string index i) result))
++	(setf index (1+ i))))))
++
+ #+ecl
+ (defun build-maxima-lib ()
+   (labels ((list-all-objects (module)
+@@ -79,12 +92,12 @@
+ 			  :ld-flags
+ 			  (let ((x (symbol-value (find-symbol "*AUTOCONF-LD-FLAGS*"
+ 							      (find-package "MAXIMA")))))
+-			    (if (and x (not (string= x ""))) (list x))))
++			    (if (and x (not (string= x ""))) (split-string x))))
+ 	(c::build-program "binary-ecl/maxima" :lisp-files obj
+ 			  :ld-flags
+ 			  (let ((x (symbol-value (find-symbol "*AUTOCONF-LD-FLAGS*"
+ 							      (find-package "MAXIMA")))))
+-			    (if (and x (not (string= x ""))) (list x)))
++			    (if (and x (not (string= x ""))) (split-string x)))
+ 			  :epilogue-code '(progn (cl-user::run)))))))
+ 
+ (defun maxima-binary-pathname ()
diff --git a/srcpkgs/maxima/patches/matrixexp.patch b/srcpkgs/maxima/patches/matrixexp.patch
new file mode 100644
index 000000000000..7cbd9ccac089
--- /dev/null
+++ b/srcpkgs/maxima/patches/matrixexp.patch
@@ -0,0 +1,23 @@
+Description: Fix error in matrix exponentiation
+ This patch was written by SageMath but not yet committed into Maxima releases.
+ However, it is needed for SageMath to work correctly:
+ .
+ https://git.sagemath.org/sage.git/tree/build/pkgs/maxima/patches/matrixexp.patch
+Author: Peter Bruin <P.J.Bruin@math.leidenuniv.nl>
+Bug-Sage: http://trac.sagemath.org/ticket/13973
+Bug: https://sourceforge.net/p/maxima/bugs/2596/
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+--- a/share/linearalgebra/matrixexp.lisp
++++ b/share/linearalgebra/matrixexp.lisp
+@@ -138,8 +138,8 @@
+ 	   (print `(ratvars = ,$ratvars gcd = '$gcd algebraic = ,$algebraic))
+ 	   (print `(ratfac = ,$ratfac))
+ 	   (merror "Unable to find the spectrum")))
+-   
+-    (setq res ($fullratsimp (ncpower (sub (mult z ($ident n)) mat) -1) z))
++
++    (setq res ($fullratsimp ($invert_by_lu (sub (mult z ($ident n)) mat) '$crering) z))
+     (setq m (length sp))
+     (dotimes (i m)
+       (setq zi (nth i sp))
diff --git a/srcpkgs/maxima/template b/srcpkgs/maxima/template
index 3a95e3706447..798b4f9f00de 100644
--- a/srcpkgs/maxima/template
+++ b/srcpkgs/maxima/template
@@ -1,11 +1,11 @@
 # Template file for 'maxima'
 pkgname=maxima
 version=5.45.1
-revision=1
+revision=2
 build_style=gnu-configure
-configure_args="$(vopt_enable clisp) $(vopt_enable sbcl sbcl-exec)"
+configure_args="$(vopt_enable clisp) $(vopt_enable sbcl sbcl-exec) $(vopt_enable ecl)"
 hostmakedepends="python3 perl emacs texinfo"
-makedepends="$(vopt_if clisp clisp) $(vopt_if sbcl sbcl)"
+makedepends="$(vopt_if clisp clisp) $(vopt_if sbcl sbcl) $(vopt_if ecl ecl)"
 depends="$(vopt_if clisp clisp) rlwrap"
 checkdepends="gnuplot"
 short_desc="Computer Algebra System"
@@ -17,10 +17,11 @@ checksum=fe9016276970bef214a1a244348558644514d7fdfaa4fc8b9d0e87afcbb4e7dc
 
 nostrip=yes
 nopie=yes
-build_options="clisp sbcl"
+build_options="clisp sbcl ecl"
 desc_option_clisp="Build with CLISP"
 desc_option_sbcl="Build with SBCL"
-build_options_default="sbcl"
+desc_option_ecl="Build with ECL"
+build_options_default="sbcl ecl"
 vopt_conflict clisp sbcl
 
 post_install() {
@@ -66,3 +67,26 @@ xmaxima_package() {
 			${PKGDESTDIR}/usr/share/pixmaps/maxima
 	}
 }
+
+subpackages="maxima-src maxima-emacs xmaxima"
+
+if [ "$build_option_ecl" ]; then
+	subpackages+=" maxima-ecl"
+fi
+
+maxima-ecl_package() {
+	short_desc+=" - compiled with ECL"
+	depends="${sourcepkg}-${version}_${revision}"
+	pkg_install() {
+		# this is /usr/lib/ecl-${ecl_version}
+		# ideally we would just place it in /usr/lib/ecl but this
+		# doesn't just work
+		# Maybe we can have the ecl package ship a symlink:
+		#     /usr/lib/ecl -> /usr/lib/ecl-${ecl_version}
+		# and have this package just install in /usr/lib/ecl
+		ECLDIR=$(ecl -eval "(princ (SI:GET-LIBRARY-PATHNAME))" -eval "(quit)")
+		vmkdir $ECLDIR
+		vinstall src/binary-ecl/maxima.fas 755 $ECLDIR
+		vmove usr/lib/maxima/${version}/binary-ecl
+	}
+}

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC] maxima: add a subpkg maxima-ecl needed for sagemath
  2021-11-27 23:25 [PR PATCH] [RFC] maxima: add a subpkg maxima-ecl needed for sagemath tornaria
@ 2021-11-28 12:51 ` tornaria
  2021-11-28 13:01 ` tornaria
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tornaria @ 2021-11-28 12:51 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1617 bytes --]

New comment by tornaria on void-packages repository

https://github.com/void-linux/void-packages/pull/34273#issuecomment-981080349

Comment:
A few more comments:

a. this package is not marked nocross, but there's no way to build on cross since sbcl, clisp, emacs are nocross. OTOH emacs is not really required: I tried having emacs as a build option (disabled on cross) and using ecl to build maxima cross aarch64. However, this results in x86_64 binaries rather than aarch64 binaries. Ofc if we use target ecl it doesn't run and if I use host ecl it builds for host. We'd need a cross-ecl which we don't have, so we should flag the package as nocross, right?

b. there is a lline `vopt_conflict clisp sbcl`, but I don't think there's any conflict on those. In fact, I compiled maxima with the three backends (sbcl, clisp, ecl) and it builds and runs ok. You can run `maxima -l clisp` to use the clisp backend, etc. Note that when you compile with multiple backends sbcl is the default, that's why the default I set (sbcl + ecl) doesn't affect current users.

Note that sbcl is much more efficient by far. Running the testsuite with `echo 'run_testsuite();' | maxima` (and same with -l ecl, -l clisp) takes me:
 - sbcl: real	1m35.744s
 - ecl: real	8m54.797s
 - clisp: real	18m14.480s

This justifies the default choice of compiling with sbcl in the main package (maxima) and moving the ecl backend into a split subpkg which is used for sagemath (ofc it would be nice if sagemath was able to use maxima compiled with sbcl, but at this time it can't). I'm not sure what advantage clisp brings to the table.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC] maxima: add a subpkg maxima-ecl needed for sagemath
  2021-11-27 23:25 [PR PATCH] [RFC] maxima: add a subpkg maxima-ecl needed for sagemath tornaria
  2021-11-28 12:51 ` tornaria
@ 2021-11-28 13:01 ` tornaria
  2021-11-28 20:28 ` dkwo
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tornaria @ 2021-11-28 13:01 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 671 bytes --]

New comment by tornaria on void-packages repository

https://github.com/void-linux/void-packages/pull/34273#issuecomment-981081779

Comment:
@jbgg @knusbaum: I'd appreciate if you have any comments about this PR which relates maxima and ecl.

TL;DR: we need maxima compiled with ecl as a dependency of sagemath, and that I'm not sure about where to place the library `maxima.fas` so that ecl can pick it up with `(require 'maxima)`. So far I placed it into `/usr/lib/ecl-21.2.1/` but that ties maxima pkg to the precise version of ecl it was compiled with. I'd rather place it in `/usr/lib/ecl/` but I don't know how to configure ecl so it looks in that directory too.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC] maxima: add a subpkg maxima-ecl needed for sagemath
  2021-11-27 23:25 [PR PATCH] [RFC] maxima: add a subpkg maxima-ecl needed for sagemath tornaria
  2021-11-28 12:51 ` tornaria
  2021-11-28 13:01 ` tornaria
@ 2021-11-28 20:28 ` dkwo
  2021-12-01 21:24 ` knusbaum
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: dkwo @ 2021-11-28 20:28 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 219 bytes --]

New comment by dkwo on void-packages repository

https://github.com/void-linux/void-packages/pull/34273#issuecomment-981146702

Comment:
If it does not affect maxima users and works with sage, then it looks good to me.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC] maxima: add a subpkg maxima-ecl needed for sagemath
  2021-11-27 23:25 [PR PATCH] [RFC] maxima: add a subpkg maxima-ecl needed for sagemath tornaria
                   ` (2 preceding siblings ...)
  2021-11-28 20:28 ` dkwo
@ 2021-12-01 21:24 ` knusbaum
  2021-12-01 23:02 ` tornaria
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: knusbaum @ 2021-12-01 21:24 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 881 bytes --]

New comment by knusbaum on void-packages repository

https://github.com/void-linux/void-packages/pull/34273#issuecomment-984067175

Comment:
@tornaria 
I don't recall how xbps handles packages that require specific versions of another package.
As long as maxima-ecl gets rebuilt whenever ecl gets updated, it should be fine to include in `/usr/lib/ecl-21.2.1/`. I spent a little time in the ECL manual and on web search looking for a formal description of ecl's `require` implementation, but didn't find much. 

I *did* find that ecl fasls are basically shared objects, so they may need to be recompiled when ecl is updated anyway. I'm not sure and can't find any good info.

It's a shame, based on the [sagemath changes](https://trac.sagemath.org/ticket/32867) it looks like maxima needs to be `require`able rather than using any other package solution (`asdf` or somesuch)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC] maxima: add a subpkg maxima-ecl needed for sagemath
  2021-11-27 23:25 [PR PATCH] [RFC] maxima: add a subpkg maxima-ecl needed for sagemath tornaria
                   ` (3 preceding siblings ...)
  2021-12-01 21:24 ` knusbaum
@ 2021-12-01 23:02 ` tornaria
  2021-12-11 18:38 ` [PR PATCH] [Updated] " tornaria
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tornaria @ 2021-12-01 23:02 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1729 bytes --]

New comment by tornaria on void-packages repository

https://github.com/void-linux/void-packages/pull/34273#issuecomment-984136989

Comment:
> @tornaria I don't recall how xbps handles packages that require specific versions of another package. As long as maxima-ecl gets rebuilt whenever ecl gets updated, it should be fine to include in `/usr/lib/ecl-21.2.1/`. I spent a little time in the ECL manual and on web search looking for a formal description of ecl's `require` implementation, but didn't find much.
> 
> I _did_ find that ecl fasls are basically shared objects, so they may need to be recompiled when ecl is updated anyway. I'm not sure and can't find any good info.

I was hoping that it doesn't need to be recompiled for minor version changes to ecl. In fact the binary which gets compiled in `/usr/lib/maxima/5.45.1/binary-ecl/maxima` requires `libecl.so.21.2` so I guess maxima will need recompilling (and xbps will enforce it) when the soname for libecl.so changes.

 > It's a shame, based on the [sagemath changes](https://trac.sagemath.org/ticket/32867) it looks like maxima needs to be `require`able rather than using any other package solution (`asdf` or somesuch)

This is where sagemath loads ecl and maxima.fas: [src/sage/interfaces/maxima_lib.py](https://github.com/sagemath/sage/blob/develop/src/sage/interfaces/maxima_lib.py#L99). As you can see, sagemath embeds ecl and runs lisp code to load maxima, etc.

I don't know much about common lisp. What would be a better (standard, portable) way to load `maxima.fas` using `asdf` instead of `require`? We could presumably try to change the initialization in sagemath. What would be the portable location for `maxima.fas` making this possible?


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PR PATCH] [Updated] [RFC] maxima: add a subpkg maxima-ecl needed for sagemath
  2021-11-27 23:25 [PR PATCH] [RFC] maxima: add a subpkg maxima-ecl needed for sagemath tornaria
                   ` (4 preceding siblings ...)
  2021-12-01 23:02 ` tornaria
@ 2021-12-11 18:38 ` tornaria
  2021-12-11 18:56 ` tornaria
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tornaria @ 2021-12-11 18:38 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1836 bytes --]

There is an updated pull request by tornaria against master on the void-packages repository

https://github.com/tornaria/void-packages maxima
https://github.com/void-linux/void-packages/pull/34273

[RFC] maxima: add a subpkg maxima-ecl needed for sagemath
 - Added a build option 'ecl' (enabled by default)
 - The ecl binary and library will be in a subpkg maxima-ecl so this
   should not affect current users of maxima
 - new patches:
   - a0d7a43...: build a FASL library for ECL (this is merged upstream)
   - handle-multiple-ldflags.patch: otherwise compilation with multiple options in LDFLAGS fails (taken from debian)
   - matrixexp.patch: fixes an error in matrix exponentiation (taken from debian, this originates in sagemath)

A weak point is that the library maxima.fas is installed in
/usr/lib/ecl-${ecl_version} which is where ecl looks for them, but this
doesn't seem right.

Maybe an alternative would be to have the ecl package ship a symlink at
/usr/lib/ecl pointing to the versioned directory, then have the
maxima-ecl package place its library in the non-versioned directory.

#### Testing the changes
- I tested the changes in this PR: **briefly**

To compile sagemath using system maxima, two things are necessary:
 - the maxima-ecl package that this PR introduces
 - the (yet unmerged) changes for sagemath in https://trac.sagemath.org/ticket/32867
Using both I compiled and doctested sagemath, and it seems to be working ok.

#### RFC
My doubts are:
- where to place the library `maxima.fas` as discussed above
- whether to have a build_option for ecl or just hardcode it as enabled
- whether to split the `maxima-ecl` package or place the two files it contains in the package `maxima` itself

A patch file from https://github.com/void-linux/void-packages/pull/34273.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-maxima-34273.patch --]
[-- Type: text/x-diff, Size: 12508 bytes --]

From f45b1624e717809af92e50bcf099d1ef63b4ce5a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= <tornaria@cmat.edu.uy>
Date: Sat, 27 Nov 2021 19:38:48 -0300
Subject: [PATCH 1/2] maxima: add a subpkg maxima-ecl needed for sagemath

 - Added a build option 'ecl' (enabled by default)
 - The ecl binary and library will be in a subpkg maxima-ecl so this
   should not affect current users of maxima
 - new patches:
   - a0d7a43...: build a FASL library for ECL (this is merged upstream)
   - handle-multiple-ldflags.patch: otherwise compilation with multiple
     options in LDFLAGS fails (taken from debian)
   - matrixexp.patch: fixes an error in matrix exponentiation (taken
     from debian, this originates in sagemath)

A weak point is that the library maxima.fas is installed in
/usr/lib/ecl-${ecl_version} which is where ecl looks for them, but this
doesn't seem right.

Maybe an alternative would be to have the ecl package ship a symlink at
/usr/lib/ecl pointing to the versioned directory, then have the
maxima-ecl package place its library in the non-versioned directory.
---
 srcpkgs/maxima-ecl                            |  1 +
 ...a43e5234305bd6f1de5909d4ce5d7e1ea864.patch | 24 +++++++++++
 .../patches/handle-multiple-ldflags.patch     | 43 +++++++++++++++++++
 srcpkgs/maxima/patches/matrixexp.patch        | 23 ++++++++++
 srcpkgs/maxima/template                       | 34 ++++++++++++---
 5 files changed, 120 insertions(+), 5 deletions(-)
 create mode 120000 srcpkgs/maxima-ecl
 create mode 100644 srcpkgs/maxima/patches/a0d7a43e5234305bd6f1de5909d4ce5d7e1ea864.patch
 create mode 100644 srcpkgs/maxima/patches/handle-multiple-ldflags.patch
 create mode 100644 srcpkgs/maxima/patches/matrixexp.patch

diff --git a/srcpkgs/maxima-ecl b/srcpkgs/maxima-ecl
new file mode 120000
index 000000000000..b8b0e8240fa4
--- /dev/null
+++ b/srcpkgs/maxima-ecl
@@ -0,0 +1 @@
+maxima
\ No newline at end of file
diff --git a/srcpkgs/maxima/patches/a0d7a43e5234305bd6f1de5909d4ce5d7e1ea864.patch b/srcpkgs/maxima/patches/a0d7a43e5234305bd6f1de5909d4ce5d7e1ea864.patch
new file mode 100644
index 000000000000..e1ac1e5f6086
--- /dev/null
+++ b/srcpkgs/maxima/patches/a0d7a43e5234305bd6f1de5909d4ce5d7e1ea864.patch
@@ -0,0 +1,24 @@
+commit a0d7a43e5234305bd6f1de5909d4ce5d7e1ea864
+Author: Robert Dodier <robert_dodier@users.sourceforge.net>
+Date:   Mon Oct 11 22:40:13 2021 -0700
+
+    Apply patch #80: "Build a FASL library, needed by SageMath"
+    
+    This modifies maxima.system for ECL only.
+
+diff --git a/src/maxima.system b/src/maxima.system
+index d954bc2b9..525fb778e 100644
+--- a/src/maxima.system
++++ b/src/maxima.system
+@@ -75,6 +75,11 @@
+ 			     ;; Convert dir/foo.fas to dir/foo.o
+ 			     (make-pathname :type "o" :defaults p))
+ 			 files)))
++	(c::build-fasl "binary-ecl/maxima" :lisp-files obj
++			  :ld-flags
++			  (let ((x (symbol-value (find-symbol "*AUTOCONF-LD-FLAGS*"
++							      (find-package "MAXIMA")))))
++			    (if (and x (not (string= x ""))) (list x))))
+ 	(c::build-program "binary-ecl/maxima" :lisp-files obj
+ 			  :ld-flags
+ 			  (let ((x (symbol-value (find-symbol "*AUTOCONF-LD-FLAGS*"
diff --git a/srcpkgs/maxima/patches/handle-multiple-ldflags.patch b/srcpkgs/maxima/patches/handle-multiple-ldflags.patch
new file mode 100644
index 000000000000..799fc15f9185
--- /dev/null
+++ b/srcpkgs/maxima/patches/handle-multiple-ldflags.patch
@@ -0,0 +1,43 @@
+Description: Handle multiple LDFLAGS
+ Without this patch, building with LDFLAGS containing more than one flag results 
+ in flags being dropped.
+Author: Graham Inggs <ginggs@debian.org>
+Bug-Debian: http://bugs.debian.org/847925
+
+--- a/src/maxima.system
++++ b/src/maxima.system
+@@ -58,6 +58,19 @@
+     (and (apply #'compile-file file :output-file object-output args)
+ 	 (c:build-fasl output :lisp-files (list object-output)))))
+ 
++(defun split-string (string &key (item #\space) (test #'char=))
++  ;; Splits the string into substrings at spaces.
++  (let ((len (length string))
++	(index 0) result)
++    (dotimes (i len
++		(progn (unless (= index len)
++			 (push (subseq string index) result))
++		       (reverse result)))
++      (when (funcall test (char string i) item)
++	(unless (= index i);; two spaces in a row
++	  (push (subseq string index i) result))
++	(setf index (1+ i))))))
++
+ #+ecl
+ (defun build-maxima-lib ()
+   (labels ((list-all-objects (module)
+@@ -79,12 +92,12 @@
+ 			  :ld-flags
+ 			  (let ((x (symbol-value (find-symbol "*AUTOCONF-LD-FLAGS*"
+ 							      (find-package "MAXIMA")))))
+-			    (if (and x (not (string= x ""))) (list x))))
++			    (if (and x (not (string= x ""))) (split-string x))))
+ 	(c::build-program "binary-ecl/maxima" :lisp-files obj
+ 			  :ld-flags
+ 			  (let ((x (symbol-value (find-symbol "*AUTOCONF-LD-FLAGS*"
+ 							      (find-package "MAXIMA")))))
+-			    (if (and x (not (string= x ""))) (list x)))
++			    (if (and x (not (string= x ""))) (split-string x)))
+ 			  :epilogue-code '(progn (cl-user::run)))))))
+ 
+ (defun maxima-binary-pathname ()
diff --git a/srcpkgs/maxima/patches/matrixexp.patch b/srcpkgs/maxima/patches/matrixexp.patch
new file mode 100644
index 000000000000..7cbd9ccac089
--- /dev/null
+++ b/srcpkgs/maxima/patches/matrixexp.patch
@@ -0,0 +1,23 @@
+Description: Fix error in matrix exponentiation
+ This patch was written by SageMath but not yet committed into Maxima releases.
+ However, it is needed for SageMath to work correctly:
+ .
+ https://git.sagemath.org/sage.git/tree/build/pkgs/maxima/patches/matrixexp.patch
+Author: Peter Bruin <P.J.Bruin@math.leidenuniv.nl>
+Bug-Sage: http://trac.sagemath.org/ticket/13973
+Bug: https://sourceforge.net/p/maxima/bugs/2596/
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+--- a/share/linearalgebra/matrixexp.lisp
++++ b/share/linearalgebra/matrixexp.lisp
+@@ -138,8 +138,8 @@
+ 	   (print `(ratvars = ,$ratvars gcd = '$gcd algebraic = ,$algebraic))
+ 	   (print `(ratfac = ,$ratfac))
+ 	   (merror "Unable to find the spectrum")))
+-   
+-    (setq res ($fullratsimp (ncpower (sub (mult z ($ident n)) mat) -1) z))
++
++    (setq res ($fullratsimp ($invert_by_lu (sub (mult z ($ident n)) mat) '$crering) z))
+     (setq m (length sp))
+     (dotimes (i m)
+       (setq zi (nth i sp))
diff --git a/srcpkgs/maxima/template b/srcpkgs/maxima/template
index 3a95e3706447..798b4f9f00de 100644
--- a/srcpkgs/maxima/template
+++ b/srcpkgs/maxima/template
@@ -1,11 +1,11 @@
 # Template file for 'maxima'
 pkgname=maxima
 version=5.45.1
-revision=1
+revision=2
 build_style=gnu-configure
-configure_args="$(vopt_enable clisp) $(vopt_enable sbcl sbcl-exec)"
+configure_args="$(vopt_enable clisp) $(vopt_enable sbcl sbcl-exec) $(vopt_enable ecl)"
 hostmakedepends="python3 perl emacs texinfo"
-makedepends="$(vopt_if clisp clisp) $(vopt_if sbcl sbcl)"
+makedepends="$(vopt_if clisp clisp) $(vopt_if sbcl sbcl) $(vopt_if ecl ecl)"
 depends="$(vopt_if clisp clisp) rlwrap"
 checkdepends="gnuplot"
 short_desc="Computer Algebra System"
@@ -17,10 +17,11 @@ checksum=fe9016276970bef214a1a244348558644514d7fdfaa4fc8b9d0e87afcbb4e7dc
 
 nostrip=yes
 nopie=yes
-build_options="clisp sbcl"
+build_options="clisp sbcl ecl"
 desc_option_clisp="Build with CLISP"
 desc_option_sbcl="Build with SBCL"
-build_options_default="sbcl"
+desc_option_ecl="Build with ECL"
+build_options_default="sbcl ecl"
 vopt_conflict clisp sbcl
 
 post_install() {
@@ -66,3 +67,26 @@ xmaxima_package() {
 			${PKGDESTDIR}/usr/share/pixmaps/maxima
 	}
 }
+
+subpackages="maxima-src maxima-emacs xmaxima"
+
+if [ "$build_option_ecl" ]; then
+	subpackages+=" maxima-ecl"
+fi
+
+maxima-ecl_package() {
+	short_desc+=" - compiled with ECL"
+	depends="${sourcepkg}-${version}_${revision}"
+	pkg_install() {
+		# this is /usr/lib/ecl-${ecl_version}
+		# ideally we would just place it in /usr/lib/ecl but this
+		# doesn't just work
+		# Maybe we can have the ecl package ship a symlink:
+		#     /usr/lib/ecl -> /usr/lib/ecl-${ecl_version}
+		# and have this package just install in /usr/lib/ecl
+		ECLDIR=$(ecl -eval "(princ (SI:GET-LIBRARY-PATHNAME))" -eval "(quit)")
+		vmkdir $ECLDIR
+		vinstall src/binary-ecl/maxima.fas 755 $ECLDIR
+		vmove usr/lib/maxima/${version}/binary-ecl
+	}
+}

From 0a3c0f740fad5726f768df3cd58426b8f977e24d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= <tornaria@cmat.edu.uy>
Date: Fri, 10 Dec 2021 14:01:01 -0300
Subject: [PATCH 2/2] maxima: use a shared lib

---
 .../maxima/patches/use-shared-library.patch   | 21 ++++++++
 srcpkgs/maxima/template                       | 50 +++++++++++++------
 2 files changed, 55 insertions(+), 16 deletions(-)
 create mode 100644 srcpkgs/maxima/patches/use-shared-library.patch

diff --git a/srcpkgs/maxima/patches/use-shared-library.patch b/srcpkgs/maxima/patches/use-shared-library.patch
new file mode 100644
index 000000000000..a8f986ac7033
--- /dev/null
+++ b/srcpkgs/maxima/patches/use-shared-library.patch
@@ -0,0 +1,21 @@
+--- a/src/maxima.system	2021-12-02 00:26:23.955984864 -0300
++++ b/src/maxima.system	2021-12-02 00:31:22.299541969 -0300
+@@ -87,13 +87,15 @@
+       (let ((obj (mapcar #'(lambda (p)
+ 			     ;; Convert dir/foo.fas to dir/foo.o
+ 			     (make-pathname :type "o" :defaults p))
+-			 files)))
+-	(c::build-fasl "binary-ecl/maxima" :lisp-files obj
++			 files))
++			(lib '("binary-ecl/libmaxima-ecl.so")))
++	(c::build-shared-library "binary-ecl/maxima-ecl" :lisp-files obj)
++	(c::build-fasl "binary-ecl/maxima" :lisp-files lib
+ 			  :ld-flags
+ 			  (let ((x (symbol-value (find-symbol "*AUTOCONF-LD-FLAGS*"
+ 							      (find-package "MAXIMA")))))
+ 			    (if (and x (not (string= x ""))) (split-string x))))
+-	(c::build-program "binary-ecl/maxima" :lisp-files obj
++	(c::build-program "binary-ecl/maxima" :lisp-files lib
+ 			  :ld-flags
+ 			  (let ((x (symbol-value (find-symbol "*AUTOCONF-LD-FLAGS*"
+ 							      (find-package "MAXIMA")))))
diff --git a/srcpkgs/maxima/template b/srcpkgs/maxima/template
index 798b4f9f00de..1a4bec0dba18 100644
--- a/srcpkgs/maxima/template
+++ b/srcpkgs/maxima/template
@@ -4,7 +4,7 @@ version=5.45.1
 revision=2
 build_style=gnu-configure
 configure_args="$(vopt_enable clisp) $(vopt_enable sbcl sbcl-exec) $(vopt_enable ecl)"
-hostmakedepends="python3 perl emacs texinfo"
+hostmakedepends="python3 perl emacs texinfo patchelf"
 makedepends="$(vopt_if clisp clisp) $(vopt_if sbcl sbcl) $(vopt_if ecl ecl)"
 depends="$(vopt_if clisp clisp) rlwrap"
 checkdepends="gnuplot"
@@ -24,6 +24,29 @@ desc_option_ecl="Build with ECL"
 build_options_default="sbcl ecl"
 vopt_conflict clisp sbcl
 
+post_build() {
+	if [ "$build_option_ecl" ]; then
+		# everything will go in the same directory, use rpath=$ORIGIN
+		patchelf --remove-rpath src/binary-ecl/libmaxima-ecl.so
+		patchelf --set-rpath \$ORIGIN \
+			src/binary-ecl/{maxima,maxima.fas}
+		patchelf \
+			--replace-needed  binary-ecl/libmaxima-ecl.so libmaxima-ecl.so \
+			src/binary-ecl/{maxima,maxima.fas}
+	fi
+}
+
+do_check() {
+	if [ "$build_option_ecl" ]; then
+		echo "Check that maxima.fas works"
+		ecl --eval "(require 'maxima \"src/binary-ecl/maxima.fas\")" \
+			--eval "(quit)"
+	fi
+
+	# now run the testsuite
+	make ${makejobs} check
+}
+
 post_install() {
 	vmkdir usr/share/doc
 	ln -sf ../maxima/${version}/doc ${DESTDIR}/usr/share/doc/maxima
@@ -68,25 +91,20 @@ xmaxima_package() {
 	}
 }
 
-subpackages="maxima-src maxima-emacs xmaxima"
-
-if [ "$build_option_ecl" ]; then
-	subpackages+=" maxima-ecl"
-fi
-
 maxima-ecl_package() {
 	short_desc+=" - compiled with ECL"
 	depends="${sourcepkg}-${version}_${revision}"
 	pkg_install() {
-		# this is /usr/lib/ecl-${ecl_version}
-		# ideally we would just place it in /usr/lib/ecl but this
-		# doesn't just work
-		# Maybe we can have the ecl package ship a symlink:
-		#     /usr/lib/ecl -> /usr/lib/ecl-${ecl_version}
-		# and have this package just install in /usr/lib/ecl
+		BINARY_ECL=/usr/lib/maxima/${version}/binary-ecl
+		vmove ${BINARY_ECL}
+		vinstall src/binary-ecl/libmaxima-ecl.so 755 ${BINARY_ECL}
+		vinstall src/binary-ecl/maxima.fas 755 ${BINARY_ECL}
+
+		# symlink maxima.fas in ECLDIR
 		ECLDIR=$(ecl -eval "(princ (SI:GET-LIBRARY-PATHNAME))" -eval "(quit)")
-		vmkdir $ECLDIR
-		vinstall src/binary-ecl/maxima.fas 755 $ECLDIR
-		vmove usr/lib/maxima/${version}/binary-ecl
+		vmkdir ${ECLDIR}
+		ln -sr ${PKGDESTDIR}/${BINARY_ECL}/maxima.fas ${PKGDESTDIR}/${ECLDIR}
 	}
 }
+
+subpackages="maxima-src maxima-emacs xmaxima $(vopt_if ecl maxima-ecl)"

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC] maxima: add a subpkg maxima-ecl needed for sagemath
  2021-11-27 23:25 [PR PATCH] [RFC] maxima: add a subpkg maxima-ecl needed for sagemath tornaria
                   ` (5 preceding siblings ...)
  2021-12-11 18:38 ` [PR PATCH] [Updated] " tornaria
@ 2021-12-11 18:56 ` tornaria
  2021-12-13 13:09 ` tornaria
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tornaria @ 2021-12-11 18:56 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1843 bytes --]

New comment by tornaria on void-packages repository

https://github.com/void-linux/void-packages/pull/34273#issuecomment-991748622

Comment:
In the old version there was an executable `maxima` and a library `maxima.fas` which where almost copies of each other.

In the new version I moved the common code to a shared library. The new package `maxima-ecl` contains:
 - `/usr/lib/maxima/5.45.1/binary-ecl/libmaxima-ecl.so`: shared library (13M)
 - `/usr/lib/maxima/5.45.1/binary-ecl/maxima`: binary for maxima -l ecl (20K)
 - `/usr/lib/maxima/5.45.1/binary-ecl/maxima.fas`: fasl for `(require 'maxima)` in ecl (20K)
 - `/usr/lib/ecl-21.2.1/maxima-fas` symlink to `maxima.fas` where ecl can find it

The way this is acomplished is placing all binaries (shared lib, executable, and fasl) in the same directory; the last two have `rpath=$ORIGIN` so they find the shared. An alternative is to place the shared library in `/usr/lib` to avoid the need for rpath.

Note that this change does _not_ affect current users of `maxima` pkg. All that changes is adding these four new files in a separate package `maxima-ecl`. Even installing this package doesn't affect current users of maxima since just running `maxima` in the cmdline will use the SBCL version by default. Only when doing `maxima -l ecl` will the ecl version be run. Alternatively, running ecl and doing `(require 'maxima)` loads maxima into ecl.

Given that the pkg `maxima-ecl` is just 10% size of the pkg `maxima`, it's also possible to just include those four files in the main pkg. That wouldn't be a problem and the only cost is this 10% extra space for users of `maxima` not interested in the ecl version of maxima.

This works well with sagemath and it would be really nice to have it available on the system, since maxima doesn't change as often as sagemath itself.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: maxima: add a subpkg maxima-ecl needed for sagemath
  2021-11-27 23:25 [PR PATCH] [RFC] maxima: add a subpkg maxima-ecl needed for sagemath tornaria
                   ` (6 preceding siblings ...)
  2021-12-11 18:56 ` tornaria
@ 2021-12-13 13:09 ` tornaria
  2021-12-21 13:08 ` tornaria
  2021-12-21 13:19 ` [PR PATCH] [Merged]: " leahneukirchen
  9 siblings, 0 replies; 11+ messages in thread
From: tornaria @ 2021-12-13 13:09 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 171 bytes --]

New comment by tornaria on void-packages repository

https://github.com/void-linux/void-packages/pull/34273#issuecomment-992460565

Comment:
IMO this is good for merging.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: maxima: add a subpkg maxima-ecl needed for sagemath
  2021-11-27 23:25 [PR PATCH] [RFC] maxima: add a subpkg maxima-ecl needed for sagemath tornaria
                   ` (7 preceding siblings ...)
  2021-12-13 13:09 ` tornaria
@ 2021-12-21 13:08 ` tornaria
  2021-12-21 13:19 ` [PR PATCH] [Merged]: " leahneukirchen
  9 siblings, 0 replies; 11+ messages in thread
From: tornaria @ 2021-12-21 13:08 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 197 bytes --]

New comment by tornaria on void-packages repository

https://github.com/void-linux/void-packages/pull/34273#issuecomment-998764955

Comment:
@leahneukirchen What do you think? Could we merge this?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PR PATCH] [Merged]: maxima: add a subpkg maxima-ecl needed for sagemath
  2021-11-27 23:25 [PR PATCH] [RFC] maxima: add a subpkg maxima-ecl needed for sagemath tornaria
                   ` (8 preceding siblings ...)
  2021-12-21 13:08 ` tornaria
@ 2021-12-21 13:19 ` leahneukirchen
  9 siblings, 0 replies; 11+ messages in thread
From: leahneukirchen @ 2021-12-21 13:19 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1673 bytes --]

There's a merged pull request on the void-packages repository

maxima: add a subpkg maxima-ecl needed for sagemath
https://github.com/void-linux/void-packages/pull/34273

Description:
 - Added a build option 'ecl' (enabled by default)
 - The ecl binary and library will be in a subpkg maxima-ecl so this
   should not affect current users of maxima
 - new patches:
   - a0d7a43...: build a FASL library for ECL (this is merged upstream)
   - handle-multiple-ldflags.patch: otherwise compilation with multiple options in LDFLAGS fails (taken from debian)
   - matrixexp.patch: fixes an error in matrix exponentiation (taken from debian, this originates in sagemath)

A weak point is that the library maxima.fas is installed in
/usr/lib/ecl-${ecl_version} which is where ecl looks for them, but this
doesn't seem right.

Maybe an alternative would be to have the ecl package ship a symlink at
/usr/lib/ecl pointing to the versioned directory, then have the
maxima-ecl package place its library in the non-versioned directory.

#### Testing the changes
- I tested the changes in this PR: **briefly**

To compile sagemath using system maxima, two things are necessary:
 - the maxima-ecl package that this PR introduces
 - the (yet unmerged) changes for sagemath in https://trac.sagemath.org/ticket/32867
Using both I compiled and doctested sagemath, and it seems to be working ok.

#### RFC
My doubts are:
- where to place the library `maxima.fas` as discussed above
- whether to have a build_option for ecl or just hardcode it as enabled
- whether to split the `maxima-ecl` package or place the two files it contains in the package `maxima` itself

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-12-21 13:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-27 23:25 [PR PATCH] [RFC] maxima: add a subpkg maxima-ecl needed for sagemath tornaria
2021-11-28 12:51 ` tornaria
2021-11-28 13:01 ` tornaria
2021-11-28 20:28 ` dkwo
2021-12-01 21:24 ` knusbaum
2021-12-01 23:02 ` tornaria
2021-12-11 18:38 ` [PR PATCH] [Updated] " tornaria
2021-12-11 18:56 ` tornaria
2021-12-13 13:09 ` tornaria
2021-12-21 13:08 ` tornaria
2021-12-21 13:19 ` [PR PATCH] [Merged]: " leahneukirchen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).