2 , lapack-reference, openblasCompat, openblas
4 , blasProvider ? if isILP64 then openblas else openblasCompat }:
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 isILP64 = blasProvider.blas64 or false;
35 blasImplementation = lib.getName blasProvider;
39 assert isILP64 -> (blasImplementation == "openblas" && blasProvider.blas64) || blasImplementation == "mkl";
45 outputs = [ "out" "dev" ];
47 meta = (blasProvider.meta or {}) // {
48 description = "${lib.getName blasProvider} with just the BLAS C and FORTRAN ABI";
53 provider = blasProvider;
54 implementation = blasImplementation;
59 unpackPhase = "src=$PWD";
64 mkdir -p $out/lib $dev/include $dev/lib/pkgconfig
66 libblas="${lib.getLib blasProvider}/lib/libblas${canonicalExtension}"
68 if ! [ -e "$libblas" ]; then
69 echo "$libblas does not exist, ${blasProvider.name} does not provide libblas."
73 $NM -an "$libblas" | cut -f3 -d' ' > symbols
74 for symbol in ${toString blasFortranSymbols}; do
75 grep -q "^$symbol_$" symbols || { echo "$symbol" was not found in "$libblas"; exit 1; }
78 cp -L "$libblas" $out/lib/libblas${canonicalExtension}
79 chmod +w $out/lib/libblas${canonicalExtension}
81 '' + (if stdenv.hostPlatform.parsed.kernel.execFormat.name == "elf" then ''
82 patchelf --set-soname libblas${canonicalExtension} $out/lib/libblas${canonicalExtension}
83 patchelf --set-rpath "$(patchelf --print-rpath $out/lib/libblas${canonicalExtension}):${lib.getLib blasProvider}/lib" $out/lib/libblas${canonicalExtension}
84 '' else if stdenv.hostPlatform.isDarwin then ''
86 -id libblas${canonicalExtension} \
87 -add_rpath ${lib.getLib blasProvider}/lib \
88 $out/lib/libblas${canonicalExtension}
91 if [ "$out/lib/libblas${canonicalExtension}" != "$out/lib/libblas${stdenv.hostPlatform.extensions.sharedLibrary}" ]; then
92 ln -s $out/lib/libblas${canonicalExtension} "$out/lib/libblas${stdenv.hostPlatform.extensions.sharedLibrary}"
95 cat <<EOF > $dev/lib/pkgconfig/blas.pc
98 Description: BLAS FORTRAN implementation
99 Libs: -L$out/lib -lblas
100 Cflags: -I$dev/include
103 libcblas="${lib.getLib blasProvider}/lib/libcblas${canonicalExtension}"
105 if ! [ -e "$libcblas" ]; then
106 echo "$libcblas does not exist, ${blasProvider.name} does not provide libcblas."
110 cp -L "$libcblas" $out/lib/libcblas${canonicalExtension}
111 chmod +w $out/lib/libcblas${canonicalExtension}
113 '' + (if stdenv.hostPlatform.parsed.kernel.execFormat.name == "elf" then ''
114 patchelf --set-soname libcblas${canonicalExtension} $out/lib/libcblas${canonicalExtension}
115 patchelf --set-rpath "$(patchelf --print-rpath $out/lib/libcblas${canonicalExtension}):${lib.getLib blasProvider}/lib" $out/lib/libcblas${canonicalExtension}
116 '' else if stdenv.hostPlatform.isDarwin then ''
118 -id libcblas${canonicalExtension} \
119 -add_rpath ${lib.getLib blasProvider}/lib \
120 $out/lib/libcblas${canonicalExtension}
122 if [ "$out/lib/libcblas${canonicalExtension}" != "$out/lib/libcblas${stdenv.hostPlatform.extensions.sharedLibrary}" ]; then
123 ln -s $out/lib/libcblas${canonicalExtension} "$out/lib/libcblas${stdenv.hostPlatform.extensions.sharedLibrary}"
126 cp ${lib.getDev lapack-reference}/include/cblas{,_mangling}.h $dev/include
128 cat <<EOF > $dev/lib/pkgconfig/cblas.pc
131 Description: BLAS C implementation
132 Cflags: -I$dev/include
133 Libs: -L$out/lib -lcblas
135 '' + lib.optionalString (blasImplementation == "mkl") ''
136 mkdir -p $out/nix-support
137 echo 'export MKL_INTERFACE_LAYER=${lib.optionalString isILP64 "I"}LP64,GNU' > $out/nix-support/setup-hook
138 ln -s $out/lib/libblas${canonicalExtension} $out/lib/libmkl_rt${stdenv.hostPlatform.extensions.sharedLibrary}
139 ln -sf ${blasProvider}/include/* $dev/include