Subject: [PATCH v2 6/6] gnu: define dune-*-openmpi packages

From: Felix Gruber <[email-masked]>
Date: Tue, 10 Mar 2020 20:29:10 +0100

* gnu/packages/maths.scm (dune-*-openmpi): New variables.
* gnu/packages/maths.scm (add-openmpi-to-dune-package): New function to
  add openmpi to the inputs of a dune-* package and replace all dune-*
  packages in its input with the corresponding dune-*-openmpi package.
---
 gnu/packages/maths.scm | 79 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 78 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/maths.scm b/gnu/packages/maths.scm
index 33a5efd2f0..e904ca1bd8 100644
--- a/gnu/packages/maths.scm
+++ b/gnu/packages/maths.scm
@@ -126,7 +126,9 @@
   #:use-module (gnu packages version-control)
   #:use-module (gnu packages wxwidgets)
   #:use-module (gnu packages xml)
-  #:use-module (srfi srfi-1))
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-34)
+  #:use-module (srfi srfi-35))
 
 (define-public aris
   (package
@@ -5027,6 +5029,81 @@ built on top of DUNE, the Distributed and Unified Numerics Environment.")
     ;; Either GPL version 2 with "runtime exception" or LGPLv3+.
     (license (list license:lgpl3+ license:gpl2))))
 
+(define add-openmpi-to-dune-package
+  (let ((transformed-packages '()))
+   (lambda (p)
+    (let* ((p-name (package-name p))
+           (replace-package
+             (lambda (mapping)
+               (let* ((name (car mapping))
+                      (p (cadr mapping))
+                      (new-p
+                        (match (assoc-ref transformed-packages name)
+                          (#f
+                           (if (string-prefix? "dune-" name)
+                               (raise (condition
+                                 (&message
+                                  (message
+                                   (format #f "Need to call \
+add-openmpi-to-dune-package on '~a' before '~a'."
+                                           name p-name)))))
+                               p))
+                          (transformed-p transformed-p))))
+                `(,name ,new-p))))
+           (substitute-mpi-packages (lambda (inputs)
+                                      (map replace-package inputs)))
+           (mpi-p
+             (package (inherit p)
+               (name (string-append p-name "-openmpi"))
+               (inputs `(,@(substitute-mpi-packages (package-inputs p))
+                         ("openmpi" ,openmpi)))
+               (propagated-inputs
+                 (substitute-mpi-packages (package-propagated-inputs p)))
+               (arguments
+                (substitute-keyword-arguments (package-arguments p)
+                  ((#:phases phases '%standard-phases)
+                   `(modify-phases ,phases
+                      (add-before 'check 'mpi-setup
+                        ,%openmpi-setup)))))
+               (synopsis (string-append (package-synopsis p) " (with MPI support)")))))
+     (begin
+      (set! transformed-packages
+            (acons p-name mpi-p transformed-packages))
+      mpi-p)))))
+
+(define-public dune-common-openmpi
+  (add-openmpi-to-dune-package dune-common))
+
+(define-public dune-geometry-openmpi
+  (add-openmpi-to-dune-package dune-geometry))
+
+(define-public dune-istl-openmpi
+  (add-openmpi-to-dune-package dune-istl))
+
+(define-public dune-typetree-openmpi
+  (add-openmpi-to-dune-package dune-typetree))
+
+(define-public dune-uggrid-openmpi
+  (add-openmpi-to-dune-package dune-uggrid))
+
+(define-public dune-grid-openmpi
+  (add-openmpi-to-dune-package dune-grid))
+
+(define-public dune-alugrid-openmpi
+  (add-openmpi-to-dune-package dune-alugrid))
+
+(define-public dune-subgrid-openmpi
+  (add-openmpi-to-dune-package dune-subgrid))
+
+(define-public dune-localfunctions-openmpi
+  (add-openmpi-to-dune-package dune-localfunctions))
+
+(define-public dune-functions-openmpi
+  (add-openmpi-to-dune-package dune-functions))
+
+(define-public dune-pdelab-openmpi
+  (add-openmpi-to-dune-package dune-pdelab))
+
 (define-public mlucas
   (package
     (name "mlucas")
-- 
2.25.1