anvil-editor: init at 0.4
[NixPkgs.git] / pkgs / development / libraries / science / math / suitesparse / 4.4.nix
blobef859cfc1ca2af267bddfc4c3de70eeaf3ea59ab
1 { lib, stdenv, fetchurl, gfortran, blas, lapack
2 , config
3 , enableCuda ? config.cudaSupport, cudatoolkit
4 }:
6 let
7   int_t = if blas.isILP64 then "int64_t" else "int32_t";
8   SHLIB_EXT = stdenv.hostPlatform.extensions.sharedLibrary;
9 in
10 stdenv.mkDerivation rec {
11   version = "4.4.4";
12   pname = "suitesparse";
14   src = fetchurl {
15     url = "http://faculty.cse.tamu.edu/davis/SuiteSparse/SuiteSparse-${version}.tar.gz";
16     sha256 = "1zdn1y0ij6amj7smmcslkqgbqv9yy5cwmbyzqc9v6drzdzllgbpj";
17   };
19   preConfigure = ''
20     mkdir -p $out/lib
21     mkdir -p $out/include
23     sed -i "SuiteSparse_config/SuiteSparse_config.mk" \
24         -e 's/METIS .*$/METIS =/' \
25         -e 's/METIS_PATH .*$/METIS_PATH =/' \
26         -e '/CHOLMOD_CONFIG/ s/$/-DNPARTITION -DLONGBLAS=${int_t}/' \
27         -e '/UMFPACK_CONFIG/ s/$/-DLONGBLAS=${int_t}/'
28   ''
29   + lib.optionalString stdenv.hostPlatform.isDarwin ''
30     sed -i "SuiteSparse_config/SuiteSparse_config.mk" \
31         -e 's/^[[:space:]]*\(LIB = -lm\) -lrt/\1/'
32   ''
33   + lib.optionalString enableCuda ''
34     sed -i "SuiteSparse_config/SuiteSparse_config.mk" \
35         -e 's|^[[:space:]]*\(CUDA_ROOT     =\)|CUDA_ROOT = ${cudatoolkit}|' \
36         -e 's|^[[:space:]]*\(GPU_BLAS_PATH =\)|GPU_BLAS_PATH = $(CUDA_ROOT)|' \
37         -e 's|^[[:space:]]*\(GPU_CONFIG    =\)|GPU_CONFIG = -I$(CUDA_ROOT)/include -DGPU_BLAS -DCHOLMOD_OMP_NUM_THREADS=$(NIX_BUILD_CORES) |' \
38         -e 's|^[[:space:]]*\(CUDA_PATH     =\)|CUDA_PATH = $(CUDA_ROOT)|' \
39         -e 's|^[[:space:]]*\(CUDART_LIB    =\)|CUDART_LIB = $(CUDA_ROOT)/lib64/libcudart.so|' \
40         -e 's|^[[:space:]]*\(CUBLAS_LIB    =\)|CUBLAS_LIB = $(CUDA_ROOT)/lib64/libcublas.so|' \
41         -e 's|^[[:space:]]*\(CUDA_INC_PATH =\)|CUDA_INC_PATH = $(CUDA_ROOT)/include/|' \
42         -e 's|^[[:space:]]*\(NV20          =\)|NV20 = -arch=sm_20 -Xcompiler -fPIC|' \
43         -e 's|^[[:space:]]*\(NV30          =\)|NV30 = -arch=sm_30 -Xcompiler -fPIC|' \
44         -e 's|^[[:space:]]*\(NV35          =\)|NV35 = -arch=sm_35 -Xcompiler -fPIC|' \
45         -e 's|^[[:space:]]*\(NVCC          =\) echo|NVCC = $(CUDA_ROOT)/bin/nvcc|' \
46         -e 's|^[[:space:]]*\(NVCCFLAGS     =\)|NVCCFLAGS = $(NV20) -O3 -gencode=arch=compute_20,code=sm_20 -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_35,code=sm_35 -gencode=arch=compute_60,code=sm_60|'
47   '';
49   makeFlags = [
50     "PREFIX=\"$(out)\""
51     "INSTALL_LIB=$(out)/lib"
52     "INSTALL_INCLUDE=$(out)/include"
53     "BLAS=-lblas"
54     "LAPACK=-llapack"
55   ];
57   env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isDarwin " -DNTIMER";
59   postInstall = ''
60     # Build and install shared library
61     (
62         cd "$(mktemp -d)"
63         for i in "$out"/lib/lib*.a; do
64           ar -x $i
65         done
66         ${if enableCuda then cudatoolkit else stdenv.cc.outPath}/bin/${if enableCuda then "nvcc" else "cc"} *.o ${if stdenv.hostPlatform.isDarwin then "-dynamiclib" else "--shared"} -o "$out/lib/libsuitesparse${SHLIB_EXT}" -lblas ${lib.optionalString enableCuda "-lcublas"}
67     )
68     for i in umfpack cholmod amd camd colamd spqr; do
69       ln -s libsuitesparse${SHLIB_EXT} "$out"/lib/lib$i${SHLIB_EXT}
70     done
72     # Install documentation
73     outdoc=$out/share/doc/suitesparse-${version}
74     mkdir -p $outdoc
75     cp -r AMD/Doc $outdoc/amd
76     cp -r BTF/Doc $outdoc/bft
77     cp -r CAMD/Doc $outdoc/camd
78     cp -r CCOLAMD/Doc $outdoc/ccolamd
79     cp -r CHOLMOD/Doc $outdoc/cholmod
80     cp -r COLAMD/Doc $outdoc/colamd
81     cp -r CXSparse/Doc $outdoc/cxsparse
82     cp -r KLU/Doc $outdoc/klu
83     cp -r LDL/Doc $outdoc/ldl
84     cp -r RBio/Doc $outdoc/rbio
85     cp -r SPQR/Doc $outdoc/spqr
86     cp -r UMFPACK/Doc $outdoc/umfpack
87   '';
89   nativeBuildInputs = [ gfortran ];
90   buildInputs = [ blas lapack ];
92   meta = with lib; {
93     homepage = "http://faculty.cse.tamu.edu/davis/suitesparse.html";
94     description = "Suite of sparse matrix algorithms";
95     license = with licenses; [ bsd2 gpl2Plus lgpl21Plus ];
96     maintainers = with maintainers; [ ttuegel ];
97     platforms = with platforms; unix;
98   };