2 , lapack-reference, openblas
4 , blasProvider ? openblas }:
8 "caxpy" "ccopy" "cdotc" "cdotu" "cgbmv" "cgemm" "cgemv" "cgerc" "cgeru"
9 "chbmv" "chemm" "chemv" "cher" "cher2" "cher2k" "cherk" "chpmv" "chpr"
10 "chpr2" "crotg" "cscal" "csrot" "csscal" "cswap" "csymm" "csyr2k" "csyrk"
11 "ctbmv" "ctbsv" "ctpmv" "ctpsv" "ctrmm" "ctrmv" "ctrsm" "ctrsv" "dasum"
12 "daxpy" "dcabs1" "dcopy" "ddot" "dgbmv" "dgemm" "dgemv" "dger" "dnrm2"
13 "drot" "drotg" "drotm" "drotmg" "dsbmv" "dscal" "dsdot" "dspmv" "dspr"
14 "dspr2" "dswap" "dsymm" "dsymv" "dsyr" "dsyr2" "dsyr2k" "dsyrk" "dtbmv"
15 "dtbsv" "dtpmv" "dtpsv" "dtrmm" "dtrmv" "dtrsm" "dtrsv" "dzasum" "dznrm2"
16 "icamax" "idamax" "isamax" "izamax" "lsame" "sasum" "saxpy" "scabs1"
17 "scasum" "scnrm2" "scopy" "sdot" "sdsdot" "sgbmv" "sgemm" "sgemv"
18 "sger" "snrm2" "srot" "srotg" "srotm" "srotmg" "ssbmv" "sscal" "sspmv"
19 "sspr" "sspr2" "sswap" "ssymm" "ssymv" "ssyr" "ssyr2" "ssyr2k" "ssyrk"
20 "stbmv" "stbsv" "stpmv" "stpsv" "strmm" "strmv" "strsm" "strsv" "xerbla"
21 "xerbla_array" "zaxpy" "zcopy" "zdotc" "zdotu" "zdrot" "zdscal" "zgbmv"
22 "zgemm" "zgemv" "zgerc" "zgeru" "zhbmv" "zhemm" "zhemv" "zher" "zher2"
23 "zher2k" "zherk" "zhpmv" "zhpr" "zhpr2" "zrotg" "zscal" "zswap" "zsymm"
24 "zsyr2k" "zsyrk" "ztbmv" "ztbsv" "ztpmv" "ztpsv" "ztrmm" "ztrmv" "ztrsm"
29 canonicalExtension = if stdenv.hostPlatform.isLinux
30 then "${stdenv.hostPlatform.extensions.sharedLibrary}.${version}"
31 else stdenv.hostPlatform.extensions.sharedLibrary;
34 blasImplementation = lib.getName blasProvider;
35 blasProvider' = if blasImplementation == "mkl"
37 else blasProvider.override { blas64 = isILP64; };
41 assert isILP64 -> blasImplementation == "mkl" || blasProvider'.blas64;
47 outputs = [ "out" "dev" ];
49 meta = (blasProvider'.meta or {}) // {
50 description = "${lib.getName blasProvider} with just the BLAS C and FORTRAN ABI";
55 provider = blasProvider';
56 implementation = blasImplementation;
61 unpackPhase = "src=$PWD";
66 mkdir -p $out/lib $dev/include $dev/lib/pkgconfig
68 libblas="${lib.getLib blasProvider'}/lib/libblas${canonicalExtension}"
70 if ! [ -e "$libblas" ]; then
71 echo "$libblas does not exist, ${blasProvider'.name} does not provide libblas."
75 $NM -an "$libblas" | cut -f3 -d' ' > symbols
76 for symbol in ${toString blasFortranSymbols}; do
77 grep -q "^$symbol_$" symbols || { echo "$symbol" was not found in "$libblas"; exit 1; }
80 cp -L "$libblas" $out/lib/libblas${canonicalExtension}
81 chmod +w $out/lib/libblas${canonicalExtension}
83 '' + (if stdenv.hostPlatform.isElf then ''
84 patchelf --set-soname libblas${canonicalExtension} $out/lib/libblas${canonicalExtension}
85 patchelf --set-rpath "$(patchelf --print-rpath $out/lib/libblas${canonicalExtension}):${lib.getLib blasProvider'}/lib" $out/lib/libblas${canonicalExtension}
86 '' else lib.optionalString (stdenv.hostPlatform.isDarwin) ''
88 -id $out/lib/libblas${canonicalExtension} \
89 -add_rpath ${lib.getLib blasProvider'}/lib \
90 $out/lib/libblas${canonicalExtension}
93 if [ "$out/lib/libblas${canonicalExtension}" != "$out/lib/libblas${stdenv.hostPlatform.extensions.sharedLibrary}" ]; then
94 ln -s $out/lib/libblas${canonicalExtension} "$out/lib/libblas${stdenv.hostPlatform.extensions.sharedLibrary}"
97 cat <<EOF > $dev/lib/pkgconfig/blas.pc
100 Description: BLAS FORTRAN implementation
101 Libs: -L$out/lib -lblas
102 Cflags: -I$dev/include
105 libcblas="${lib.getLib blasProvider'}/lib/libcblas${canonicalExtension}"
107 if ! [ -e "$libcblas" ]; then
108 echo "$libcblas does not exist, ${blasProvider'.name} does not provide libcblas."
112 cp -L "$libcblas" $out/lib/libcblas${canonicalExtension}
113 chmod +w $out/lib/libcblas${canonicalExtension}
115 '' + (if stdenv.hostPlatform.isElf then ''
116 patchelf --set-soname libcblas${canonicalExtension} $out/lib/libcblas${canonicalExtension}
117 patchelf --set-rpath "$(patchelf --print-rpath $out/lib/libcblas${canonicalExtension}):${lib.getLib blasProvider'}/lib" $out/lib/libcblas${canonicalExtension}
118 '' else lib.optionalString stdenv.hostPlatform.isDarwin ''
120 -id $out/lib/libcblas${canonicalExtension} \
121 -add_rpath ${lib.getLib blasProvider'}/lib \
122 $out/lib/libcblas${canonicalExtension}
124 if [ "$out/lib/libcblas${canonicalExtension}" != "$out/lib/libcblas${stdenv.hostPlatform.extensions.sharedLibrary}" ]; then
125 ln -s $out/lib/libcblas${canonicalExtension} "$out/lib/libcblas${stdenv.hostPlatform.extensions.sharedLibrary}"
128 cp ${lib.getDev lapack-reference}/include/cblas{,_mangling}.h $dev/include
130 cat <<EOF > $dev/lib/pkgconfig/cblas.pc
133 Description: BLAS C implementation
134 Cflags: -I$dev/include
135 Libs: -L$out/lib -lcblas
137 '' + lib.optionalString (blasImplementation == "mkl") ''
138 mkdir -p $out/nix-support
139 echo 'export MKL_INTERFACE_LAYER=${lib.optionalString isILP64 "I"}LP64,GNU' > $out/nix-support/setup-hook
140 ln -s $out/lib/libblas${canonicalExtension} $out/lib/libmkl_rt${stdenv.hostPlatform.extensions.sharedLibrary}
141 ln -sf ${blasProvider'}/include/* $dev/include