from spack import *

class Dealii(Package):
    """C++ software library providing well-documented tools to build finite element codes for a broad variety of PDEs."""
    homepage = "https://www.dealii.org"
    url      = "https://github.com/dealii/dealii/releases/download/v8.4.0/dealii-8.4.0.tar.gz"

    version('8.4.0', 'ac5dbf676096ff61e092ce98c80c2b00')

    depends_on ("cmake")
    depends_on ("blas")
    depends_on ("lapack")
    depends_on ("mpi")

    #depends_on ("arpack")
    depends_on ("boost")
    #depends_on ("doxygen")
    depends_on ("hdf5+mpi")
    depends_on ("metis")
    #depends_on "muparser"
    depends_on ("netcdf")
    #depends_on ("numdiff")
    #depends_on ("oce")
    depends_on ("p4est")
    depends_on ("parmetis")
    depends_on ("petsc")
    #depends_on ("slepc")
    depends_on ("SuiteSparse")
    #depends_on "tbb"
    depends_on ("trilinos")

    def install(self, spec, prefix):
        options = []
        options.extend(std_cmake_args)

        # CMAKE_BUILD_TYPE should be DebugRelease | Debug | Release
        for word in options[:]:
            if word.startswith('-DCMAKE_BUILD_TYPE'):
                options.remove(word)

        options.extend([
            '-DCMAKE_BUILD_TYPE=DebugRelease',
            '-DDEAL_II_WITH_THREADS:BOOL=ON'
            '-DDEAL_II_WITH_MPI:BOOL=ON',
            '-DCMAKE_C_COMPILER=%s' % join_path(self.spec['mpi'].prefix.bin, 'mpicc'),
            '-DCMAKE_CXX_COMPILER=%s' % join_path(self.spec['mpi'].prefix.bin, 'mpic++'),
            '-DCMAKE_Fortran_COMPILER=%s' % join_path(self.spec['mpi'].prefix.bin, 'mpif90'),
            #'-DARPACK_DIR=%s' %  ,
            '-DBOOST_DIR=%s' % spec['boost'].prefix,
            '-DHDF5_DIR=%s' % spec['hdf5'].prefix,
            '-DMETIS_DIR=%s' % spec['metis'].prefix,
            #'-DMUPARSER_DIR=%s '
            '-DNETCDF_DIR=%s' % spec['netcdf'].prefix,
            #'-DOPENCASCADE_DIR=
            '-DP4EST_DIR=%s' % spec['p4est'].prefix,
            '-DPETSC_DIR=%s' % spec['petsc'].prefix,
            #'-DSLEPC_DIR=
            '-DUMFPACK_DIR=%s' % spec['SuiteSparse'].prefix,
            #'-DTBB_DIR=%s'
            '-DTRILINOS_DIR=%s' % spec['trilinos'].prefix
        ])

        cmake('.', *options)

        make()
        make("test")
        make("install")

@@ -452,25 +452,24 @@
 %22mpi%22)%0A%0A    
-#
 depends_on (
@@ -471,24 +471,27 @@
 _on (%22arpack
+-ng
 %22)%0A    depen
@@ -506,25 +506,24 @@
 boost%22)%0A    
-#
 depends_on (
@@ -558,18 +558,72 @@
 hdf5+mpi
-%22)
+~cxx%22) #FIXME NetCDF declares dependency with ~cxx, why?
 %0A    dep
@@ -640,25 +640,24 @@
 metis%22)%0A    
-#
 depends_on %22
@@ -655,16 +655,17 @@
 ends_on 
+(
 %22muparse
@@ -666,16 +666,17 @@
 uparser%22
+)
 %0A    dep
@@ -721,22 +721,28 @@
 umdiff%22)
+ #FIXME
 %0A    
-#
 depends_
@@ -830,25 +830,24 @@
 petsc%22)%0A    
-#
 depends_on (
@@ -872,22 +872,23 @@
 ds_on (%22
-S
+s
 uite
-S
+-s
 parse%22)%0A
@@ -887,25 +887,24 @@
 parse%22)%0A    
-#
 depends_on %22
@@ -906,13 +906,15 @@
 _on 
+(
 %22tbb%22
+)
 %0A   
@@ -1474,16 +1474,61 @@
 mpicc'),
+ # FIXME: avoid hardcoding mpi wrappers names
 %0A       
@@ -1716,17 +1716,16 @@
         
-#
 '-DARPAC
@@ -1736,17 +1736,40 @@
 R=%25s' %25 
- 
+spec%5B'arpack-ng'%5D.prefix
 ,%0A      
@@ -1931,17 +1931,16 @@
         
-#
 '-DMUPAR
@@ -1951,16 +1951,43 @@
 DIR=%25s '
+ %25 spec%5B'muparser'%5D.prefix,
 %0A       
@@ -2046,17 +2046,16 @@
         
-#
 '-DOPENC
@@ -2061,24 +2061,49 @@
 CASCADE_DIR=
+%25s' %25 spec%5B'oce'%5D.prefix,
 %0A           
@@ -2209,17 +2209,16 @@
         
-#
 '-DSLEPC
@@ -2222,16 +2222,43 @@
 EPC_DIR=
+%25s' %25 spec%5B'slepc'%5D.prefix,
 %0A       
@@ -2293,14 +2293,15 @@
 ec%5B'
-S
+s
 uite
-S
+-s
 pars
@@ -2324,17 +2324,16 @@
         
-#
 '-DTBB_D
@@ -2338,16 +2338,38 @@
 _DIR=%25s'
+ %25 spec%5B'tbb'%5D.prefix,
 %0A       

update dependencies. Builds fine on OSX