From 15692c5475dba43b8410857079896ece5890986c Mon Sep 17 00:00:00 2001
From: sknigh <sknigh@sandia.gov>
Date: Fri, 28 Apr 2017 12:57:55 -0700
Subject: ncurses package builds ncurses and ncursesw (#3953)

* ncurses package will build ncurses and ncursesw

* Added libs property to ncurses, added fix for hstr

* flake8 is a harsh mistress

* make libs() more robust

* atop depends on ncurses

* fish depends on ncurses

* libtermkey and nano depend on ncurses

* Adjust url spacing
---
 var/spack/repos/builtin/packages/atop/package.py   |  3 ++
 var/spack/repos/builtin/packages/fish/package.py   |  2 +
 var/spack/repos/builtin/packages/hstr/package.py   |  1 +
 .../repos/builtin/packages/libtermkey/package.py   |  3 ++
 var/spack/repos/builtin/packages/nano/package.py   |  2 +
 .../repos/builtin/packages/ncurses/package.py      | 55 ++++++++++++++++++++--
 6 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/var/spack/repos/builtin/packages/atop/package.py b/var/spack/repos/builtin/packages/atop/package.py
index e3a9d464a9..7a34d129f7 100644
--- a/var/spack/repos/builtin/packages/atop/package.py
+++ b/var/spack/repos/builtin/packages/atop/package.py
@@ -32,6 +32,9 @@ class Atop(Package):
 
     version('2.2-3', '034dc1544f2ec4e4d2c739d320dc326d')
 
+    depends_on('zlib')
+    depends_on('ncurses')
+
     def install(self, spec, prefix):
         make()
         mkdirp(prefix.bin)
diff --git a/var/spack/repos/builtin/packages/fish/package.py b/var/spack/repos/builtin/packages/fish/package.py
index f0dfac70c8..715d4797e3 100644
--- a/var/spack/repos/builtin/packages/fish/package.py
+++ b/var/spack/repos/builtin/packages/fish/package.py
@@ -34,4 +34,6 @@ class Fish(AutotoolsPackage):
     url      = "http://fishshell.com/files/2.2.0/fish-2.2.0.tar.gz"
     list_url = "http://fishshell.com/"
 
+    depends_on('ncurses')
+
     version('2.2.0', 'a76339fd14ce2ec229283c53e805faac48c3e99d9e3ede9d82c0554acfc7b77a')
diff --git a/var/spack/repos/builtin/packages/hstr/package.py b/var/spack/repos/builtin/packages/hstr/package.py
index 3a556b9b6c..0efae70d87 100644
--- a/var/spack/repos/builtin/packages/hstr/package.py
+++ b/var/spack/repos/builtin/packages/hstr/package.py
@@ -40,3 +40,4 @@ class Hstr(AutotoolsPackage):
     depends_on('libtool',  type='build')
     depends_on('m4',       type='build')
     depends_on('ncurses@5.9')
+    depends_on('readline')
diff --git a/var/spack/repos/builtin/packages/libtermkey/package.py b/var/spack/repos/builtin/packages/libtermkey/package.py
index 64688505c4..359e077284 100644
--- a/var/spack/repos/builtin/packages/libtermkey/package.py
+++ b/var/spack/repos/builtin/packages/libtermkey/package.py
@@ -36,6 +36,9 @@ class Libtermkey(Package):
     version('0.15b', '27689756e6c86c56ae454f2ac259bc3d')
     version('0.14', 'e08ce30f440f9715c459060e0e048978')
 
+    depends_on('libtool', type='build')
+    depends_on('ncurses')
+
     def install(self, spec, prefix):
         make()
         make("install", "PREFIX=" + prefix)
diff --git a/var/spack/repos/builtin/packages/nano/package.py b/var/spack/repos/builtin/packages/nano/package.py
index d303b5e424..49415bb7ef 100644
--- a/var/spack/repos/builtin/packages/nano/package.py
+++ b/var/spack/repos/builtin/packages/nano/package.py
@@ -33,3 +33,5 @@ class Nano(AutotoolsPackage):
 
     version('2.6.3', '1213c7f17916e65afefc95054c1f90f9')
     version('2.6.2', '58568a4b8a33841d774c25f285fc11c1')
+
+    depends_on('ncurses')
diff --git a/var/spack/repos/builtin/packages/ncurses/package.py b/var/spack/repos/builtin/packages/ncurses/package.py
index a19cdd08dd..869bc4e5ae 100644
--- a/var/spack/repos/builtin/packages/ncurses/package.py
+++ b/var/spack/repos/builtin/packages/ncurses/package.py
@@ -23,6 +23,10 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 ##############################################################################
 from spack import *
+from glob import glob
+from os.path import exists, join
+from os import makedirs
+from shutil import copy
 
 
 class Ncurses(AutotoolsPackage):
@@ -46,20 +50,65 @@ class Ncurses(AutotoolsPackage):
     patch('patch_gcc_5.txt', when='@6.0%gcc@5.0:')
     patch('sed_pgi.patch',   when='@:6.0')
 
-    def configure_args(self):
+    def configure(self, spec, prefix):
         opts = [
             'CFLAGS={0}'.format(self.compiler.pic_flag),
             'CXXFLAGS={0}'.format(self.compiler.pic_flag),
             '--with-shared',
             '--with-cxx-shared',
-            '--enable-widec',
             '--enable-overwrite',
             '--without-ada',
             '--enable-pc-files',
             '--with-pkg-config-libdir={0}/lib/pkgconfig'.format(self.prefix)
         ]
 
+        nwide_opts = ['--without-manpages',
+                      '--without-progs',
+                      '--without-tests']
+
+        wide_opts = ['--enable-widec']
+
         if '+symlinks' in self.spec:
             opts.append('--enable-symlinks')
 
-        return opts
+        prefix = '--prefix={0}'.format(prefix)
+
+        configure = Executable('../configure')
+
+        with working_dir('build_ncurses', create=True):
+            configure(prefix, *(opts + nwide_opts))
+
+        with working_dir('build_ncursesw', create=True):
+            configure(prefix, *(opts + wide_opts))
+
+    def build(self, spec, prefix):
+        with working_dir('build_ncurses'):
+            make()
+        with working_dir('build_ncursesw'):
+            make()
+
+    def check(self):
+        with working_dir('build_ncurses'):
+            make('check')
+        with working_dir('build_ncursesw'):
+            make('check')
+
+    def install(self, spec, prefix):
+        with working_dir('build_ncurses'):
+            make('install')
+        with working_dir('build_ncursesw'):
+            make('install')
+
+        # fix for packages like hstr that use "#include <ncurses/ncurses.h>"
+        headers = glob(join(prefix.include, '*'))
+        for p_dir in ['ncurses', 'ncursesw']:
+            path = join(prefix.include, p_dir)
+            if not exists(path):
+                makedirs(path)
+            for header in headers:
+                copy(header, path)
+
+    @property
+    def libs(self):
+        return find_libraries(
+            ['libncurses', 'libncursesw'], root=self.prefix, recurse=True)
-- 
cgit v1.2.3-70-g09d2