Repository: spack/spack

Issue:
`cmake` not defined
Spack defines a `cmake` command by default. I find that this is `None` unless `cmake` is installed on the system; Spack does not pick up `cmake` as installed by a dependency on `cmake.`

I'm looking at `setup_package` -- maybe `which("cmake")` is called before the dependencies have a chance to modify `PATH`?



Discussion:
I forgot to add: If I add `cmake = which('cmake')` in the respective package, all works fine.

Yep it's an ordering thing in `build_environment.py`.  Will send a fix momentarily.

I'm dubious about all these "convenience" things that get added to the environment:
1. They're non-standard Python, so I can never remember how they work.  I understand "self.".
2. They're (temporarily) part of the the module not the class.  Although I can't say if or when this might hurt us for the particular usage in Spack, I know this is not clean OO programming.
3. They're not always available.  In my StagedPackage class, they're NOT available, so I used the "native" Python methods (via self.) instead.  Same thing in git/package.py, I had to write "which('autoconf')('-i')".  Having two ways to do it is harder than having just one.

I'm becoming more dubious about them too.

I think they should probably go into two places eventually:
1. The `spack` namespace, or some other namespace that can be easily imported into package files.  `from spack import *` was intended to be simple and to provide this stuff.
2. Make them attributes on the spec (e.g., so that deps can make fields available to a package).  Some packages like `netlib-scalapack` already do this, so you can write:
   
   ```
   spec['scalapack'].fc_link
   ```
   
   in packages that depend on `scalapack`.

I'm not ready to deprecate this stuff yet though -- it's still used and I'd like to see how the packages evolve before throwing yet another not-quite-good-enough convention in there.

@tgamblin I still see this problem on the current master. Since this is a show-stopper, can we quickly add the respective `cmake = which('cmake')` calls to all packages? We can easily revert that patch later.

PR #664 patches cmake --> which('cmake') for all packages.

On Tue, Mar 29, 2016 at 10:07 AM, Erik Schnetter notifications@github.com
wrote:

> @tgamblin https://github.com/tgamblin I still see this problem on the
> current master. Since this is a show-stopper, can we quickly add the
> respective cmake = which('cmake') calls to all packages? We can easily
> revert that patch later.
> 
> —
> You are receiving this because you commented.
> Reply to this email directly or view it on GitHub
> https://github.com/LLNL/spack/issues/620#issuecomment-202909973

@citibeth Thanks; I read about this. That's essentially what I did on my master branch as well.

Maybe the Spack self-tests should include installing some small packages, on a bare-bones Ubuntu virtual machine?

> Maybe the Spack self-tests should include installing some small packages, on a bare-bones Ubuntu virtual machine?

and OSX perhaps?

A bit out-of-topic, but one could think about using Travis to build packages that are being changed in PRs at least on one system (e.g. Ubuntu 14.04 LTS?). Just to be able to check that nothing is broken at least there with GNU compilers. Ideally one would also build on OSX and maybe another Linux with Intel compilers to try to cover bigger ground.

Ping: Please either correct this in Spack, or apply @citibeth's patch.

AFAICT, `cmake@3.5.1` is still broken; not sure if this error is related to the issues in this thread. Log of `spack install --verbose cmake` is below:

```
narella:spack oxberry1$ bin/spack install --verbose cmake
==> Installing cmake
==> ncurses is already installed in /Users/oxberry1/spack/opt/spack/darwin-x86_64/gcc-5.3.0/ncurses-6.0-f2klgir4qnijs3fensv7ysloknqas7hi
==> openssl is already installed in /Users/oxberry1/spack/opt/spack/darwin-x86_64/gcc-5.3.0/openssl-1.0.2g-zi52d5dlje7ipf4uprnu7u2kgtcauhwi
==> Already downloaded /Users/oxberry1/spack/var/spack/stage/cmake-3.5.1-tgxyhlo2ckyde7erzn4chgq7kye3axui/cmake-3.5.1.tar.gz
==> Already staged cmake-3.5.1-tgxyhlo2ckyde7erzn4chgq7kye3axui in /Users/oxberry1/spack/var/spack/stage/cmake-3.5.1-tgxyhlo2ckyde7erzn4chgq7kye3axui
==> No patches needed for cmake
==> Building cmake
==> ./configure --prefix=/Users/oxberry1/spack/opt/spack/darwin-x86_64/gcc-5.3.0/cmake-3.5.1-tgxyhlo2ckyde7erzn4chgq7kye3axui --parallel=4 -- -DCMAKE_USE_OPENSSL=ON
---------------------------------------------
CMake 3.5.1, Copyright 2000-2016 Kitware, Inc.
C compiler on this system is: /Users/oxberry1/spack/lib/spack/env/gcc/gcc
C++ compiler on this system is: /Users/oxberry1/spack/lib/spack/env/gcc/g++
Makefile processor on this system is: make
/Users/oxberry1/spack/lib/spack/env/gcc/g++ is GNU compiler
/Users/oxberry1/spack/lib/spack/env/gcc/g++ has setenv
/Users/oxberry1/spack/lib/spack/env/gcc/g++ has unsetenv
/Users/oxberry1/spack/lib/spack/env/gcc/g++ does not have environ in stdlib.h
/Users/oxberry1/spack/lib/spack/env/gcc/g++ has stl wstring
---------------------------------------------
/Users/oxberry1/spack/lib/spack/env/gcc/g++  -I/private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Bootstrap.cmk -I/private/var/folders/37/zqjg7vn9
7kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Source   -I/private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Utiliti
es -c /private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Source/cmBootstrapCommands1.cxx -o cmBootstrapCommands1.o
/Users/oxberry1/spack/lib/spack/env/gcc/g++  -I/private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Bootstrap.cmk -I/private/var/folders/37/zqjg7vn9
7kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Source   -I/private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Utiliti
es -c /private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Source/cmCustomCommandGenerator.cxx -o cmCustomCommandGenerator.o
/Users/oxberry1/spack/lib/spack/env/gcc/g++  -I/private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Bootstrap.cmk -I/private/var/folders/37/zqjg7vn9
7kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Source   -I/private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Utiliti
es -c /private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Source/cmCacheManager.cxx -o cmCacheManager.o
/Users/oxberry1/spack/lib/spack/env/gcc/g++  -I/private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Bootstrap.cmk -I/private/var/folders/37/zqjg7vn9
7kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Source   -I/private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Utiliti
es -c /private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Source/cmListFileCache.cxx -o cmListFileCache.o
/Users/oxberry1/spack/lib/spack/env/gcc/g++  -I/private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Bootstrap.cmk -I/private/var/folders/37/zqjg7vn9
7kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Source   -I/private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Utiliti
es -c /private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Source/cmComputeLinkDepends.cxx -o cmComputeLinkDepends.o
/Users/oxberry1/spack/lib/spack/env/gcc/g++  -I/private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Bootstrap.cmk -I/private/var/folders/37/zqjg7vn9
7kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Source   -I/private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Utiliti
es -c /private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Source/cmComputeLinkInformation.cxx -o cmComputeLinkInformation.o
/Users/oxberry1/spack/lib/spack/env/gcc/g++  -I/private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Bootstrap.cmk -I/private/var/folders/37/zqjg7vn9
7kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Source   -I/private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Utiliti
es -c /private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Source/cmOrderDirectories.cxx -o cmOrderDirectories.o
In file included from /usr/include/dispatch/dispatch.h:51:0,
                 from /System/Library/Frameworks/CoreFoundation.framework/Headers/CFStream.h:15,
                 from /System/Library/Frameworks/CoreFoundation.framework/Headers/CFPropertyList.h:13,
                 from /System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:55,
                 from /private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Source/cmFindProgramCommand.cxx:16,
                 from /private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Source/cmBootstrapCommands1.cxx:52:
/usr/include/dispatch/object.h:143:15: error: expected unqualified-id before '^' token
 typedef void (^dispatch_block_t)(void);
               ^
/usr/include/dispatch/object.h:143:15: error: expected ')' before '^' token
/usr/include/dispatch/object.h:362:3: error: 'dispatch_block_t' has not been declared
   dispatch_block_t notification_block);
   ^
make: *** [cmBootstrapCommands1.o] Error 1
make: *** Waiting for unfinished jobs....
---------------------------------------------
Error when bootstrapping CMake:
Problem while running make
---------------------------------------------
Log of errors: /private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/Bootstrap.cmk/cmake_bootstrap.log
---------------------------------------------
==> Error: Command exited with status 9:
./configure --prefix=/Users/oxberry1/spack/opt/spack/darwin-x86_64/gcc-5.3.0/cmake-3.5.1-tgxyhlo2ckyde7erzn4chgq7kye3axui --parallel=4 -- -DCMAKE_USE_OPENSSL=ON

See build log for details:
  /private/var/folders/37/zqjg7vn97kggmzjdbcm55j6h001b24/T/oxberry1/spack-stage/spack-stage-Zs9eGR/cmake-3.5.1/spack-build.out

/Users/oxberry1/spack/var/spack/repos/builtin/packages/cmake/package.py:87, in install:
     68       def install(self, spec, prefix):
     69           # Consistency check
     70           self.validate(spec)
     71
     72           # configure, build, install:
     73           options = ['--prefix=%s' % prefix]
     74           options.append('--parallel=%s' % str(make_jobs))
     75
     76           if '+qt' in spec:
     77               options.append('--qt-gui')
     78
     79           if '+doc' in spec:
     80               options.append('--sphinx-html')
     81               options.append('--sphinx-man')
     82
     83           if '+openssl' in spec:
     84               options.append('--')
     85               options.append('-DCMAKE_USE_OPENSSL=ON')
     86
  >> 87           configure(*options)
     88           make()
     89           make('install')
==> Error: Installation process had nonzero exit code.
narella:spack oxberry1$ git rev-parse HEAD
8ef9d685427e60ce5af660be5f27d36683ea8845
```

@goxberry: This looks like a CMake build failure (not that the `cmake` symbol isn't properly in scope).  Does `cmake` work when you build it with clang on OS X?  I think the issue is that it's not building properly with gcc 5.  This works for me:

```
    spack install cmake@3.5.1 %clang
```

I think this could be solved with some better defaults so that `cmake` can prefer a compiler when one isn't specified -- there isn't a reason that packages like this _need_ to build with the same compiler as the code -- adding this is on my list after #378.  

For now, does this work?

```
    spack install metis %gcc ^cmake %clang
```

@tgamblin I think I responded to this on #749, but for completeness, `spack install metis %gcc ^cmake clang` does work. The tricky thing about this fix is that if a spack package depends on a package that depends on cmake -- that is, cmake is a second- (or higher-) order dependency -- then this command won't work, because spack returns an error saying that `<package> does not depend on cmake`. (Which is sort of accurate -- cmake is not a direct (or first-order) dependency.)

Yeah, that's a problem with Xcode changing headers and GCC not being compatible with some Objective-C code in it. Should have been fixed in 3.5.1 by cmake/cmake@d84ba668d7dd77ac38b3795f92e4ef0f894c696e though. It's a separate issue anyways.

I just tried installing a package that builds with cmake but doesn't depend on cmake. It crashed because I'm on my laptop and I don't have cmake installed. When I added `depends_on('cmake')`, Spack built cmake and correctly used it to build the package. I think the scope thing must have gotten figured out. Should be able to close this issue now.

Hi 

I am not able to install cmake with qt. Here is the error I am getting 

`spack install cmake~ownlibs@3.8.1 qt=true`

```
 './bootstrap' '--prefix=/home/user1/spack/opt/spack/linux-sles12-x86_64/gcc-4.8/cmake-3.8.1-w4cp2rscxv562fo4ez54awgto5f7plss' '--parallel=32' '--no-system-jsoncpp' '--system-libs' '--qt-gui' '--' '-DCMAKE_USE_OPENSSL=ON'
---------------------------------------------
CMake 3.8.1, Copyright 2000-2017 Kitware, Inc. and Contributors
C compiler on this system is: /home/user1/spack/lib/spack/env/gcc/gcc
C++ compiler on this system is: /home/user1/spack/lib/spack/env/gcc/g++
Makefile processor on this system is: gmake
/home/user1/spack/lib/spack/env/gcc/g++ is GNU compiler
/home/user1/spack/lib/spack/env/gcc/g++ has setenv
/home/user1/spack/lib/spack/env/gcc/g++ has unsetenv
/home/user1/spack/lib/spack/env/gcc/g++ does not have environ in stdlib.h
/home/user1/spack/lib/spack/env/gcc/g++ has stl wstring
/home/user1/spack/lib/spack/env/gcc/g++ has <ext/stdio_filebuf.h>
---------------------------------------------
gmake: 'cmake' is up to date.
loading initial cache file /tmp/user1/spack-stage/spack-stage-Qn2BTX/cmake-3.8.1/Bootstrap.cmk/InitialCacheFlags.cmake
-- Using system-installed BZIP2
-- Using system-installed CURL
-- Using system-installed EXPAT
-- Using system-installed FORM
-- Using system-installed LIBARCHIVE
-- Using system-installed LIBLZMA
-- Using system-installed LIBRHASH
-- Using system-installed LIBUV
-- Using system-installed ZLIB
-- Could NOT find LibRHash (missing:  LibRHash_LIBRARY LibRHash_INCLUDE_DIR)
CMake Error at CMakeLists.txt:309 (message):
  CMAKE_USE_SYSTEM_LIBRHASH is ON but LibRHash is not found!
Call Stack (most recent call first):
  CMakeLists.txt:663 (CMAKE_BUILD_UTILITIES)


-- Configuring incomplete, errors occurred!
See also "/tmp/user1/spack-stage/spack-stage-Qn2BTX/cmake-3.8.1/CMakeFiles/CMakeOutput.log".
```


```
Determining if compiler supports C11 _Thread_local failed with the following output:
Change Dir: /tmp/user1/spack-stage/spack-stage-Qn2BTX/cmake-3.8.1/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/gmake" "cmTC_5620d/fast"
gmake -f CMakeFiles/cmTC_5620d.dir/build.make CMakeFiles/cmTC_5620d.dir/build
gmake[1]: Entering directory '/tmp/user1/spack-stage/spack-stage-Qn2BTX/cmake-3.8.1/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_5620d.dir/cm_c11_thread_local.c.o
/home1/user1/spack/lib/spack/env/gcc/gcc   -std=gnu11 -o CMakeFiles/cmTC_5620d.dir/cm_c11_thread_local.c.o   -c /tmp/user1/spack-stage/spack-stage-Qn2BTX/cmake-3.8.1/Source/Checks/cm_c11_thread_local.c
/tmp/user1/spack-stage/spack-stage-Qn2BTX/cmake-3.8.1/Source/Checks/cm_c11_thread_local.c:1:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
 _Thread_local int i = 42;
               ^
CMakeFiles/cmTC_5620d.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_5620d.dir/cm_c11_thread_local.c.o' failed
gmake[1]: *** [CMakeFiles/cmTC_5620d.dir/cm_c11_thread_local.c.o] Error 1
gmake[1]: Leaving directory '/tmp/user1/spack-stage/spack-stage-Qn2BTX/cmake-3.8.1/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_5620d/fast' failed
gmake: *** [cmTC_5620d/fast] Error 2


Determining if compiler supports C++ auto_ptr failed with the following output:
Change Dir: /tmp/user1/spack-stage/spack-stage-Qn2BTX/cmake-3.8.1/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/gmake" "cmTC_5af52/fast"
gmake -f CMakeFiles/cmTC_5af52.dir/build.make CMakeFiles/cmTC_5af52.dir/build
gmake[1]: Entering directory '/tmp/user1/spack-stage/spack-stage-Qn2BTX/cmake-3.8.1/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_5af52.dir/cm_cxx_auto_ptr.cxx.o
/home1/user1/spack/lib/spack/env/gcc/g++    -std=gnu++1y -o CMakeFiles/cmTC_5af52.dir/cm_cxx_auto_ptr.cxx.o -c /tmp/user1/spack-stage/spack-stage-Qn2BTX/cmake-3.8.1/Source/Checks/cm_cxx_auto_ptr.cxx
/tmp/user1/spack-stage/spack-stage-Qn2BTX/cmake-3.8.1/Source/Checks/cm_cxx_auto_ptr.cxx: In function 'std::auto_ptr<int> get_auto_ptr()':
/tmp/user1/spack-stage/spack-stage-Qn2BTX/cmake-3.8.1/Source/Checks/cm_cxx_auto_ptr.cxx:5:22: warning: 'auto_ptr' is deprecated (declared at /usr/include/c++/4.8/backward/auto_ptr.h:87) [-Wdeprecated-declarations]
   std::auto_ptr<int> ptr;

```
Any help would be appreciated.

Thank You
Sounds like the package is missing a dependency on LibRHash. @mathstuf Can you confirm?
Yes, `librhash` is a dependency as of 3.8.0.
I'll start writing a package for it.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/cmake/package.py b/var/spack/repos/builtin/packages/cmake/package.py
--- a/var/spack/repos/builtin/packages/cmake/package.py
+++ b/var/spack/repos/builtin/packages/cmake/package.py
@@ -64,72 +64,74 @@ class Cmake(Package):
     depends_on('bzip2',          when='~ownlibs')
     depends_on('xz',             when='~ownlibs')
     depends_on('libarchive',     when='~ownlibs')
+    depends_on('libuv@1.0.0:',   when='~ownlibs')
+    depends_on('rhash',          when='@3.8.0:~ownlibs')
     depends_on('qt',             when='+qt')
     depends_on('python@2.7.11:', when='+doc', type='build')
     depends_on('py-sphinx',      when='+doc', type='build')
-    depends_on("openssl", when='+openssl')
-    depends_on("openssl@:1.0.99", when='@:3.6.9+openssl')
+    depends_on('openssl', when='+openssl')
+    depends_on('openssl@:1.0.99', when='@:3.6.9+openssl')
     depends_on('ncurses',        when='+ncurses')
 
     # Cannot build with Intel, should be fixed in 3.6.2
     # https://gitlab.kitware.com/cmake/cmake/issues/16226
     patch('intel-c-gnu11.patch', when='@3.6.0:3.6.1')
 
-    def url_for_version(self, version):
-        """Handle CMake's version-based custom URLs."""
-        return 'https://cmake.org/files/v%s/cmake-%s.tar.gz' % (
-            version.up_to(2), version)
+    conflicts('+qt', when='^qt@5.4.0')  # qt-5.4.0 has broken CMake modules
 
-    def validate(self, spec):
-        """
-        Checks if incompatible versions of qt were specified
+    phases = ['bootstrap', 'build', 'install']
 
-        :param spec: spec of the package
-        :raises RuntimeError: in case of inconsistencies
-        """
-
-        if '+qt' in spec and spec.satisfies('^qt@5.4.0'):
-            msg = 'qt-5.4.0 has broken CMake modules.'
-            raise RuntimeError(msg)
+    def url_for_version(self, version):
+        """Handle CMake's version-based custom URLs."""
+        url = 'https://cmake.org/files/v{0}/cmake-{1}.tar.gz'
+        return url.format(version.up_to(2), version)
 
-    def install(self, spec, prefix):
-        # Consistency check
-        self.validate(spec)
-
-        options = [
-            '--prefix={0}'.format(prefix),
-            '--parallel={0}'.format(make_jobs)]
-        if spec.satisfies("@3.2:"):
-            options.append(
-                # jsoncpp requires CMake to build
-                # use CMake-provided library to avoid circular dependency
-                '--no-system-jsoncpp'
-            )
+    def bootstrap_args(self):
+        spec = self.spec
+        args = [
+            '--prefix={0}'.format(self.prefix),
+            '--parallel={0}'.format(make_jobs)
+        ]
 
         if '+ownlibs' in spec:
             # Build and link to the CMake-provided third-party libraries
-            options.append('--no-system-libs')
+            args.append('--no-system-libs')
         else:
             # Build and link to the Spack-installed third-party libraries
-            options.append('--system-libs')
+            args.append('--system-libs')
+
+            if spec.satisfies('@3.2:'):
+                # jsoncpp requires CMake to build
+                # use CMake-provided library to avoid circular dependency
+                args.append('--no-system-jsoncpp')
 
         if '+qt' in spec:
-            options.append('--qt-gui')
+            args.append('--qt-gui')
         else:
-            options.append('--no-qt-gui')
+            args.append('--no-qt-gui')
 
         if '+doc' in spec:
-            options.append('--sphinx-html')
-            options.append('--sphinx-man')
+            args.append('--sphinx-html')
+            args.append('--sphinx-man')
 
         if '+openssl' in spec:
-            options.append('--')
-            options.append('-DCMAKE_USE_OPENSSL=ON')
+            args.append('--')
+            args.append('-DCMAKE_USE_OPENSSL=ON')
+
+        return args
 
+    def bootstrap(self, spec, prefix):
         bootstrap = Executable('./bootstrap')
-        bootstrap(*options)
+        bootstrap(*self.bootstrap_args())
 
+    def build(self, spec, prefix):
         make()
-        if self.run_tests:
-            make('test')  # some tests fail, takes forever
+
+    @run_after('build')
+    @on_package_attributes(run_tests=True)
+    def test(self):
+        # Some tests fail, takes forever
+        make('test')
+
+    def install(self, spec, prefix):
         make('install')
diff --git a/var/spack/repos/builtin/packages/rhash/package.py b/var/spack/repos/builtin/packages/rhash/package.py
new file mode 100644
--- /dev/null
+++ b/var/spack/repos/builtin/packages/rhash/package.py
@@ -0,0 +1,78 @@
+##############################################################################
+# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC.
+# Produced at the Lawrence Livermore National Laboratory.
+#
+# This file is part of Spack.
+# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
+# LLNL-CODE-647188
+#
+# For details, see https://github.com/llnl/spack
+# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License (as
+# published by the Free Software Foundation) version 2.1, February 1999.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
+# conditions of the GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##############################################################################
+import glob
+from spack import *
+
+
+class Rhash(MakefilePackage):
+    """RHash is a console utility for computing and verifying hash sums of
+    files. It supports CRC32, MD4, MD5, SHA1, SHA256, SHA512, SHA3, Tiger,
+    TTH, Torrent BTIH, AICH, ED2K, GOST R 34.11-94, RIPEMD-160, HAS-160,
+    EDON-R 256/512, WHIRLPOOL and SNEFRU hash sums."""
+
+    homepage = "https://sourceforge.net/projects/rhash/"
+    url      = "https://github.com/rhash/RHash/archive/v1.3.5.tar.gz"
+
+    version('1.3.5', 'f586644019c10c83c6b6835de4b99e74')
+
+    # For macOS build instructions, see:
+    # https://github.com/Homebrew/homebrew-core/blob/master/Formula/rhash.rb
+
+    def build(self, spec, prefix):
+        # Doesn't build shared libraries by default
+        make()
+
+        if spec.satisfies('platform=darwin'):
+            make('-C', 'librhash', 'dylib')
+        else:
+            make('lib-shared')
+
+    def check(self):
+        # Makefile has both `test` and `check` targets:
+        #
+        # * `test`  - used to test that the build is working properly
+        # * `check` - used to check that the tarball is ready for upload
+        #
+        # Default implmentation is to run both `make test` and `make check`.
+        # `test` passes, but `check` fails, so only run `test`.
+        make('test')
+        make('test-static-lib')
+
+        if not self.spec.satisfies('platform=darwin'):
+            make('test-shared')
+            make('test-shared-lib')
+
+    def install(self, spec, prefix):
+        # Some things are installed to $(DESTDIR)$(PREFIX) while other things
+        # are installed to $DESTDIR/etc.
+        make('install', 'DESTDIR={0}'.format(prefix), 'PREFIX=')
+        make('install-lib-static', 'DESTDIR={0}'.format(prefix), 'PREFIX=')
+
+        if spec.satisfies('platform=darwin'):
+            libs = glob.glob('librhash/*.dylib')
+            for lib in libs:
+                install(lib, prefix.lib)
+        else:
+            make('install-lib-shared', 'DESTDIR={0}'.format(prefix), 'PREFIX=')


Test patch: