Subject: [PATCH 02/20] gnu: Add suitesparse-config.

From: David Elsing <[email-masked]>
Date: Wed, 20 Sep 2023 22:07:52 +0000

The suitesparse-src variable contains the entire SuiteSparse source, from
which the source for the subpackages is extracted with the
suitesparse-package-src function using 'computed-origin-method'.

* gnu/packages/maths.scm (suitesparse-version, suitesparse-src,
suitesparse-config): New variable.
---
 gnu/packages/maths.scm | 88 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)

diff --git a/gnu/packages/maths.scm b/gnu/packages/maths.scm
index a77928f9b6..23c27c1746 100644
--- a/gnu/packages/maths.scm
+++ b/gnu/packages/maths.scm
@@ -4888,6 +4888,94 @@ (define-public openspecfun
     ;; public domain software.
     (license (list license:expat license:public-domain))))
 
+;; Source for the modular SuiteSparse packages. When updating, also update the
+;; (different) versions of the subpackages.
+(define suitesparse-version "7.2.0")
+(define suitesparse-src
+  (origin
+    (method git-fetch)
+    (uri (git-reference
+          (url "https://github.com/DrTimothyAldenDavis/SuiteSparse")
+          (commit (string-append "v" suitesparse-version))))
+    (file-name (git-file-name "suitesparse" suitesparse-version))
+    (sha256
+     (base32
+      "1draljn8i46862drc6008cnb2zjpklf74j8c34jirjazzpf53kaa"))
+    (modules '((guix build utils)))
+    (snippet
+     #~(begin
+         ;; Delete autogenerated and bundled files
+         (for-each delete-file (find-files "." "\\.pdf$"))
+         ;; ssget
+         (delete-file-recursively "ssget")
+         ;; SuiteSparse_config
+         (delete-file "SuiteSparse_config/SuiteSparse_config.h")
+         ;; CHOLMOD
+         (delete-file-recursively "CHOLMOD/SuiteSparse_metis")
+         ; GraphBLAS
+         (delete-file "GraphBLAS/README.md")
+         (delete-file "GraphBLAS/Config/GB_config.h")
+         (delete-file "GraphBLAS/Config/GB_prejit.c")
+         (delete-file-recursively "GraphBLAS/cpu_features")
+         (delete-file "GraphBLAS/CUDA/GB_cuda_common_jitFactory.hpp")
+         (delete-file "GraphBLAS/JITpackage/GB_JITpackage.c")
+         (delete-file-recursively "GraphBLAS/lz4/lz4.c")
+         (delete-file-recursively "GraphBLAS/lz4/lz4.h")
+         (delete-file-recursively "GraphBLAS/lz4/lz4hc.c")
+         (delete-file-recursively "GraphBLAS/lz4/lz4hc.h")
+         (delete-file "GraphBLAS/GraphBLAS/Config/GB_config.h")
+         (delete-file "GraphBLAS/Tcov/PreJIT/GB_prejit.c")
+         (delete-file-recursively "GraphBLAS/Source/FactoryKernels")
+         (delete-file "GraphBLAS/Source/GB_AxB__include1.h")
+         (delete-file "GraphBLAS/xxHash/xxhash.h")
+         (delete-file-recursively "GraphBLAS/zstd/zstd_subset")
+         ;; KLU
+         (delete-file "KLU/Include/klu.h")
+         (delete-file "KLU/Doc/klu_version.tex")
+         ;; LDL
+         (delete-file "LDL/Include/ldl.h")
+         (delete-file "LDL/Doc/ldl_version.tex")
+         ;; RBio
+         (delete-file "RBio/Include/RBio.h")
+         ;; SPEX
+         (delete-file "SPEX/Include/SPEX.h")
+         (delete-file "SPEX/Doc/SPEX_version.tex")
+         ;; SPQR
+         (delete-file "SPQR/Include/SuiteSparseQR_definitions.h")
+         (delete-file "SPQR/Doc/spqr_version.tex")
+         ;; UMFPACK
+         (delete-file "UMFPACK/Include/umfpack.h")
+         (delete-file "UMFPACK/Doc/umfpack_version.tex")))))
+
+(define (suitesparse-package-src name path)
+  (origin
+    (method (@@ (guix packages) computed-origin-method))
+    (file-name
+     (string-append name "-" suitesparse-version))
+    (sha256 #f)
+    (uri
+     (delay
+       (with-imported-modules '((guix build utils))
+         #~(begin
+             (use-modules (guix build utils))
+             (copy-recursively
+              (string-append #$suitesparse-src "/" #$path) #$output)))))))
+
+(define-public suitesparse-config
+  (package
+    (name "suitesparse-config")
+    (version suitesparse-version)
+    (source (suitesparse-package-src name "SuiteSparse_config"))
+    (build-system cmake-build-system)
+    (arguments (list #:tests? #f))
+    (inputs (list openblas))
+    (native-inputs (list pkg-config))
+    (home-page "https://people.engr.tamu.edu/davis/suitesparse.html")
+    (synopsis "Configuration for all SuiteSparse packages")
+    (description "SuiteSparse is a suite of sparse matrix algorithms.  This
+package contains a library with common configuration options.")
+    (license license:bsd-3)))
+
 (define-public suitesparse
   (package
     (name "suitesparse")
-- 
2.41.0