librewolf: 132.0.1 -> 132.0.1-1 (#355483)
[NixPkgs.git] / pkgs / by-name / bl / blas / package.nix
blob91001bc85377a25ab28643797f2a920df5e454fa
1 { lib, stdenv
2 , lapack-reference, openblas
3 , isILP64 ? false
4 , blasProvider ? openblas }:
6 let
7   blasFortranSymbols = [
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"
25     "ztrsv"
26   ];
28   version = "3";
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"
36                   then blasProvider
37                   else blasProvider.override { blas64 = isILP64; };
41 assert isILP64 -> blasImplementation == "mkl" || blasProvider'.blas64;
43 stdenv.mkDerivation {
44   pname = "blas";
45   inherit version;
47   outputs = [ "out" "dev" ];
49   meta = (blasProvider'.meta or {}) // {
50     description = "${lib.getName blasProvider} with just the BLAS C and FORTRAN ABI";
51   };
53   passthru = {
54     inherit isILP64;
55     provider = blasProvider';
56     implementation = blasImplementation;
57   };
59   dontBuild = true;
60   dontConfigure = true;
61   unpackPhase = "src=$PWD";
63   dontPatchELF = true;
65   installPhase = (''
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."
72     exit 1
73   fi
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; }
78   done
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) ''
87   install_name_tool \
88     -id $out/lib/libblas${canonicalExtension} \
89     -add_rpath ${lib.getLib blasProvider'}/lib \
90     $out/lib/libblas${canonicalExtension}
91 '') + ''
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}"
95   fi
97   cat <<EOF > $dev/lib/pkgconfig/blas.pc
98 Name: blas
99 Version: ${version}
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."
109     exit 1
110   fi
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 ''
119   install_name_tool \
120     -id $out/lib/libcblas${canonicalExtension} \
121     -add_rpath ${lib.getLib blasProvider'}/lib \
122     $out/lib/libcblas${canonicalExtension}
123 '') + ''
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}"
126   fi
128   cp ${lib.getDev lapack-reference}/include/cblas{,_mangling}.h $dev/include
130   cat <<EOF > $dev/lib/pkgconfig/cblas.pc
131 Name: cblas
132 Version: ${version}
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
142 '');