From 01913fb34db4f7568286b89d48dadf6a56be4d33 Mon Sep 17 00:00:00 2001
From: Piotr Luszczek <luszczek@icl.utk.edu>
Date: Mon, 22 Oct 2018 14:26:23 -0400
Subject: [PATCH] PLASMA: add version 18.9.0 (w/CMake) (#9489)

* Add version 18.9.0 (w/CMake)
* Add version dependent install methods to handle transition from
  Make-based package (17.1) to CMake-based package, using the NEST
  package as an example
* Remove unnecessary build_targets method for older Make-based
  version
* Don't retrieve just the C/Fortran interfaces for netlib-lapack -
  blas/lapack libs are now handled the same for all implementations
* Remove netlib-lapack detection patch
---
 .../plasma/add_netlib_lapacke_detection.patch | 11 ---
 .../repos/builtin/packages/plasma/package.py  | 93 ++++++++++---------
 2 files changed, 49 insertions(+), 55 deletions(-)
 delete mode 100644 var/spack/repos/builtin/packages/plasma/add_netlib_lapacke_detection.patch

diff --git a/var/spack/repos/builtin/packages/plasma/add_netlib_lapacke_detection.patch b/var/spack/repos/builtin/packages/plasma/add_netlib_lapacke_detection.patch
deleted file mode 100644
index 403dc8d40b..0000000000
--- a/var/spack/repos/builtin/packages/plasma/add_netlib_lapacke_detection.patch
+++ /dev/null
@@ -1,11 +0,0 @@
---- a/include/core_lapack.h 2017-01-13 13:59:46.000000000 -0500
-+++ b/include/core_lapack.h 2017-10-30 16:37:54.481966195 -0400
-@@ -27,7 +27,7 @@
-     // Netlib    cblas.h does: enum CBLAS_ORDER {...};
-     // OpenBLAS  cblas.h does: typedef enum CBLAS_ORDER {...} CBLAS_ORDER;
-     // We use (CBLAS_ORDER), so add these typedefs for Netlib.
--    #ifndef OPENBLAS_VERSION
-+    #if ! defined(OPENBLAS_VERSION) && ! defined(F77_HEADER_INCLUDED)
-     typedef enum CBLAS_ORDER CBLAS_ORDER;
-     typedef enum CBLAS_TRANSPOSE CBLAS_TRANSPOSE;
-     typedef enum CBLAS_UPLO CBLAS_UPLO;
diff --git a/var/spack/repos/builtin/packages/plasma/package.py b/var/spack/repos/builtin/packages/plasma/package.py
index 6fb436bc48..dc40658789 100644
--- a/var/spack/repos/builtin/packages/plasma/package.py
+++ b/var/spack/repos/builtin/packages/plasma/package.py
@@ -6,7 +6,7 @@
 from spack import *
 
 
-class Plasma(MakefilePackage):
+class Plasma(CMakePackage):
     """Parallel Linear Algebra Software for Multicore Architectures, PLASMA is
     a software package for solving problems in dense linear algebra using
     multicore processors and Xeon Phi coprocessors. PLASMA provides
@@ -16,17 +16,20 @@ class Plasma(MakefilePackage):
     problems, and singular value problems."""
 
     homepage = "https://bitbucket.org/icl/plasma/"
-    url      = "https://bitbucket.org/icl/plasma/downloads/plasma-17.1.tar.gz"
-    hg       = "https://luszczek@bitbucket.org/icl/plasma"
+    url = "https://bitbucket.org/icl/plasma/downloads/plasma18.9.0.tar.gz"
+    hg = "https://luszczek@bitbucket.org/icl/plasma"
 
     version("develop", hg=hg)
-    version("17.1", "64b410b76023a41b3f07a5f0dca554e1")
+    version("18.9.0", sha256="753eae28ea48986a2cc7b8204d6eef646584541e59d42c3c94fa9879116b0774")
+    version("17.1",
+            sha256="d4b89f7c3d240a69dfe986284a14471eec4830b9e352ae902ea8861f15573dee",
+            url="https://bitbucket.org/icl/plasma/downloads/plasma-17.1.tar.gz")
 
-    variant('shared', default=True, description="Build shared library (disables static library)")
+    variant("shared", default=True,
+            description="Build shared library (disables static library)")
 
     depends_on("blas")
     depends_on("lapack")
-    depends_on("readline", when='@17.2:')
 
     conflicts("atlas")  # does not have LAPACKE interface
 
@@ -53,36 +56,60 @@ class Plasma(MakefilePackage):
     conflicts("%xl_r")
 
     patch("remove_absolute_mkl_include.patch", when="@17.1")
-    patch("add_netlib_lapacke_detection.patch", when="@17.1")
-
-    def getblaslapacklibs(self):
-        if '^netlib-lapack' in self.spec:
-            bl_attr = ':c,fortran'
-        else:
-            bl_attr = ''
-        return self.spec['lapack' + bl_attr].libs + \
-            self.spec['blas' + bl_attr].libs + \
-            find_system_libraries(['libm'])
 
+    @when("@18.9.0:")
+    def cmake_args(self):
+        options = list()
+
+        options.extend([
+            "-DCMAKE_INSTALL_PREFIX=%s" % prefix,
+            "-DCMAKE_INSTALL_NAME_DIR:PATH=%s/lib" % prefix,
+            "-DBLAS_LIBRARIES=%s" % self.spec["blas"].libs.joined(";"),
+            "-DLAPACK_LIBRARIES=%s" % self.spec["lapack"].libs.joined(";")
+        ])
+
+        options += [
+            "-DBUILD_SHARED_LIBS=%s" %
+            ('ON' if ('+shared' in self.spec) else 'OFF')
+        ]
+
+        return options
+
+    # Before 18.9.0 it was an Makefile package
+    @when("@:17.1")
+    def cmake(self, spec, prefix):
+        pass
+
+    # Before 18.9.0 it was an Makefile package
+    @when("@:17.1")
+    def build(self, spec, prefix):
+        pass
+
+    # Before 18.9.0 it was an Makefile package
+    @when("@:17.1")
+    def install(self, spec, prefix):
+        self.edit(spec, prefix)
+        make()
+        make("install")
+
+    @when("@:17.1")
     def edit(self, spec, prefix):
         # copy "make.inc.mkl-gcc" provided by default into "make.inc"
         open("make.inc", "w").write(open("make.inc.mkl-gcc").read())
 
         make_inc = FileFilter("make.inc")
 
-        if '~shared' in self.spec:
-            make_inc.filter("-fPIC", "")  # not using fPIC
-
-        if "^mkl" not in spec:
+        if not spec.satisfies("^intel-mkl"):
             make_inc.filter("-DPLASMA_WITH_MKL", "")  # not using MKL
-            make_inc.filter("-DHAVE_MKL", "")         # not using MKL
+            make_inc.filter("LIBS *= *.*", "LIBS = " +
+                            self.spec["blas"].libs.ld_flags + " -lm")
 
         header_flags = ""
         # accumulate CPP flags for headers: <cblas.h> and <lapacke.h>
         for dep in ("blas", "lapack"):
             try:  # in case the dependency does not provide header flags
                 header_flags += " " + spec[dep].headers.cpp_flags
-            except Exception:
+            except AttributeError:
                 pass
 
         make_inc.filter("CFLAGS +[+]=", "CFLAGS += " + header_flags + " ")
@@ -92,25 +119,3 @@ def edit(self, spec, prefix):
 
         # make sure CC variable comes from build environment
         make_inc.filter("CC *[?]*= * .*cc", "")
-
-        libs = self.getblaslapacklibs().ld_flags
-        if 'readline' in self.spec:
-            libs += ' ' + self.spec['readline'].libs.ld_flags
-            libs += ' ' + find_system_libraries(['libdl']).ld_flags
-        make_inc.filter("LIBS *[?]*= * .*", "LIBS = " + libs)
-
-    @property
-    def build_targets(self):
-        targets = list()
-
-        # use $CC set by Spack
-        targets.append("CC = {0}".format(self.compiler.cc))
-
-        if "^mkl" in self.spec:
-            targets.append("MKLROOT = {0}".format(env["MKLROOT"]))
-
-        targets.append("LIBS = {0} {1} {2}".format(
-                       self.getblaslapacklibs().ld_flags,
-                       self.spec['readline'].libs.ld_flags,
-                       find_system_libraries(['libdl']).ld_flags))
-        return targets
-- 
GitLab