summary refs log tree commit diff
path: root/pkgs/development/libraries/science/math/suitesparse/default.nix
blob: f4adafd0f38762fbba9f8783c6ca545c8e75e86c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{ stdenv
, fetchFromGitHub
, gfortran
, openblas
, metis
, fixDarwinDylibNames
, gnum4
, enableCuda ? false
, cudatoolkit
}:

stdenv.mkDerivation rec {
  pname = "suitesparse";
  version = "5.7.1";

  outputs = [ "out" "dev" "doc" ];

  src = fetchFromGitHub {
    owner = "DrTimothyAldenDavis";
    repo = "SuiteSparse";
    rev = "v${version}";
    sha256 = "SA9SQKRDKUI1GilNMuCXljcvovLUwRKBUi/tiQ4dl5w=";
  };

  nativeBuildInputs = [
    gnum4
  ] ++ stdenv.lib.optional stdenv.isDarwin fixDarwinDylibNames;

  buildInputs = [
    openblas
    metis
    gfortran.cc.lib
  ] ++ stdenv.lib.optional enableCuda cudatoolkit;

  preConfigure = ''
    # Mongoose and GraphBLAS are packaged separately
    sed -i "Makefile" -e '/GraphBLAS\|Mongoose/d'
  '';

  makeFlags = [
    "INSTALL=${placeholder "out"}"
    "INSTALL_INCLUDE=${placeholder "dev"}/include"
    "JOBS=$(NIX_BUILD_CORES)"
    "BLAS=-lopenblas"
    "MY_METIS_LIB=-lmetis"
    "LAPACK="
  ] ++ stdenv.lib.optionals openblas.blas64 [
    "CFLAGS=-DBLAS64"
  ] ++ stdenv.lib.optionals enableCuda [
    "CUDA_PATH=${cudatoolkit}"
    "CUDART_LIB=${cudatoolkit.lib}/lib/libcudart.so"
    "CUBLAS_LIB=${cudatoolkit}/lib/libcublas.so"
  ];

  buildFlags = [
    # Build individual shared libraries, not demos
    "library"
  ];

  # Likely fixed after 5.7.1
  # https://github.com/DrTimothyAldenDavis/SuiteSparse/commit/f6daae26ee391e475e2295e77c839aa7c1a8b784
  postInstall = stdenv.lib.optionalString stdenv.isDarwin ''
    # The fixDarwinDylibNames in nixpkgs can't seem to fix all the libraries.
    # We manually fix them up here.
    fixDarwinDylibNames() {
        local flags=()
        local old_id

        for fn in "$@"; do
            flags+=(-change "$PWD/lib/$(basename "$fn")" "$fn")
        done

        for fn in "$@"; do
            if [ -L "$fn" ]; then continue; fi
            echo "$fn: fixing dylib"
            install_name_tool -id "$fn" "''${flags[@]}" "$fn"
        done
    }

    fixDarwinDylibNames $(find "$out" -name "*.dylib")
  '';

  meta = with stdenv.lib; {
    homepage = "http://faculty.cse.tamu.edu/davis/suitesparse.html";
    description = "A suite of sparse matrix algorithms";
    license = with licenses; [ bsd2 gpl2Plus lgpl21Plus ];
    maintainers = with maintainers; [ ttuegel ];
    platforms = with platforms; unix;
  };
}