Subject: [bug#69443] [PATCH] gnu: guile-gsl: Fix build.

From: "Artyom V. Poptsov" <[email-masked]>
Date: Sat, 9 Mar 2024 02:29:41 +0300

* gnu/packages/guile-xyz.scm (guile-gsl): Fix build.

Change-Id: Iaf653f25fd2b972e575d9c2fd1607cd490cc17db
---
 gnu/packages/guile-xyz.scm | 86 ++++++++++++++++++++++++++++----------
 1 file changed, 65 insertions(+), 21 deletions(-)

diff --git a/gnu/packages/guile-xyz.scm b/gnu/packages/guile-xyz.scm
index 9ddcc626fe..1f9d1ecb3e 100644
--- a/gnu/packages/guile-xyz.scm
+++ b/gnu/packages/guile-xyz.scm
@@ -4522,31 +4522,75 @@ (define-public guile-gsl
     (package
       (name "guile-gsl")
       (version "0.0.1")
-      (source (origin
-                (method git-fetch)
-                (uri (git-reference
-                      (url "https://github.com/aartaka/guile-gsl")
-                      (commit commit)))
-                (file-name (git-file-name name version))
-                (sha256
-                 (base32
-                  "00dy33ibvfhzs5xp65g4g8d02wy4fiamjbp3pg87cghg41q4lwkr"))))
-      (build-system guile-build-system)
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (url "https://github.com/aartaka/guile-gsl")
+               (commit commit)))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "00dy33ibvfhzs5xp65g4g8d02wy4fiamjbp3pg87cghg41q4lwkr"))))
+      (build-system gnu-build-system)
       (arguments
-       '(#:source-directory "modules"
-         #:phases
-         #~(modify-phases %standard-phases
-             (add-before 'build 'substitute-gsl-so
-               (lambda _
-                 (let ((gsl (string-append #$(this-package-input "lmdb")
-                                           "/lib/libgsl.so")))
-                   (substitute* "modules/gsl/core.scm"
-                     (("libgsl.so") gsl))))))))
+       (list
+        #:modules `(((guix build guile-build-system)
+                     #:select (target-guile-effective-version))
+                    ,@%gnu-build-system-modules)
+        #:imported-modules `((guix build guile-build-system)
+                             ,@%gnu-build-system-modules)
+        #:phases #~(modify-phases %standard-phases
+                     (add-before 'build 'substitute-gsl-so
+                       (lambda _
+                         (let ((gsl (string-append #$(this-package-input "gsl")
+                                                   "/lib/libgsl.so")))
+                           (substitute* "modules/gsl/core.scm"
+                             (("libgsl.so")
+                              gsl)))))
+                     (delete 'configure)
+                     (replace 'build
+                       (lambda* (#:key inputs #:allow-other-keys)
+                         (setenv "CC" "gcc")
+                         (setenv "GUILE_AUTO_COMPILE" "0")
+                         (invoke "make")
+                         (setenv "LD_LIBRARY_PATH" "./")
+                         (let* ((module-dir "modules")
+                                (prefix (string-length module-dir)))
+                           (for-each (lambda (file)
+                                       (let* ((base (string-drop (string-drop-right
+                                                                  file 4)
+                                                                 prefix))
+                                              (go (string-append "go" base
+                                                                 ".go")))
+                                         (invoke "guild"
+                                                 "compile"
+                                                 "-L"
+                                                 module-dir
+                                                 file
+                                                 "-o"
+                                                 go)))
+                                     (find-files module-dir "\\.scm$")))))
+                     (delete 'check) ;no tests
+                     (replace 'install
+                       (lambda* (#:key outputs #:allow-other-keys)
+                         (let* ((lib (string-append #$output "/lib"))
+                                (guile #$(this-package-input "guile"))
+                                (version (target-guile-effective-version guile))
+                                (scm (string-append "/share/guile/site/"
+                                                    version))
+                                (go (string-append "/lib/guile/" version
+                                                   "/site-ccache")))
+                           (install-file "libguilegslblas.so" lib)
+                           (copy-recursively "modules/"
+                                             (string-append #$output scm))
+                           (copy-recursively "go/"
+                                             (string-append #$output go))))))))
       (native-inputs (list guile-3.0))
       (inputs (list guile-3.0 gsl))
       (home-page "https://github.com/aartaka/guile-gsl")
-      (synopsis "Bindings for GNU Scientific library in Guile.")
-      (description "This package provides Guile Scheme wrapper for libgsl.so.
+      (synopsis "Bindings for GNU Scientific library in Guile")
+      (description
+       "This package provides Guile Scheme wrapper for @code{libgsl.so}.
 Only vector, matrix, and BLAS operations are covered for now.")
       (license license:gpl3+))))

base-commit: 38a00bc089205818a351c363a107b8ba5c99fd0d
-- 
2.41.0