2020-04-24 23:36:52 +00:00
|
|
|
{ lib, stdenv
|
2022-03-30 09:31:56 +00:00
|
|
|
, lapack-reference, openblas
|
2020-04-24 23:36:52 +00:00
|
|
|
, isILP64 ? false
|
2022-03-30 09:31:56 +00:00
|
|
|
, lapackProvider ? openblas }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
version = "3";
|
|
|
|
canonicalExtension = if stdenv.hostPlatform.isLinux
|
|
|
|
then "${stdenv.hostPlatform.extensions.sharedLibrary}.${version}"
|
|
|
|
else stdenv.hostPlatform.extensions.sharedLibrary;
|
|
|
|
|
|
|
|
lapackImplementation = lib.getName lapackProvider;
|
2022-03-30 09:31:56 +00:00
|
|
|
lapackProvider' = if lapackImplementation == "mkl"
|
|
|
|
then lapackProvider
|
|
|
|
else lapackProvider.override { blas64 = isILP64; };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
2022-03-30 09:31:56 +00:00
|
|
|
assert isILP64 -> lapackImplementation == "mkl" || lapackProvider'.blas64;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
pname = "lapack";
|
|
|
|
inherit version;
|
|
|
|
|
|
|
|
outputs = [ "out" "dev" ];
|
|
|
|
|
2022-03-30 09:31:56 +00:00
|
|
|
meta = (lapackProvider'.meta or {}) // {
|
|
|
|
description = "${lib.getName lapackProvider'} with just the LAPACK C and FORTRAN ABI";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
inherit isILP64;
|
2022-03-30 09:31:56 +00:00
|
|
|
provider = lapackProvider';
|
2020-04-24 23:36:52 +00:00
|
|
|
implementation = lapackImplementation;
|
|
|
|
};
|
|
|
|
|
2023-03-27 19:17:25 +00:00
|
|
|
# TODO: drop this forced rebuild, as it was needed just once.
|
|
|
|
rebuild_salt = if stdenv.isDarwin && stdenv.isx86_64 then "J4AQ" else null;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
dontBuild = true;
|
|
|
|
dontConfigure = true;
|
|
|
|
unpackPhase = "src=$PWD";
|
|
|
|
|
|
|
|
dontPatchELF = true;
|
|
|
|
|
|
|
|
installPhase = (''
|
|
|
|
mkdir -p $out/lib $dev/include $dev/lib/pkgconfig
|
|
|
|
|
2022-03-30 09:31:56 +00:00
|
|
|
liblapack="${lib.getLib lapackProvider'}/lib/liblapack${canonicalExtension}"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
if ! [ -e "$liblapack" ]; then
|
2022-03-30 09:31:56 +00:00
|
|
|
echo "$liblapack does not exist, ${lapackProvider'.name} does not provide liblapack."
|
2020-04-24 23:36:52 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
cp -L "$liblapack" $out/lib/liblapack${canonicalExtension}
|
|
|
|
chmod +w $out/lib/liblapack${canonicalExtension}
|
|
|
|
|
2023-02-16 17:41:37 +00:00
|
|
|
'' + (lib.optionalString (stdenv.hostPlatform.parsed.kernel.execFormat.name == "elf") ''
|
2020-04-24 23:36:52 +00:00
|
|
|
patchelf --set-soname liblapack${canonicalExtension} $out/lib/liblapack${canonicalExtension}
|
2022-03-30 09:31:56 +00:00
|
|
|
patchelf --set-rpath "$(patchelf --print-rpath $out/lib/liblapack${canonicalExtension}):${lapackProvider'}/lib" $out/lib/liblapack${canonicalExtension}
|
2023-02-16 17:41:37 +00:00
|
|
|
'') + ''
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
if [ "$out/lib/liblapack${canonicalExtension}" != "$out/lib/liblapack${stdenv.hostPlatform.extensions.sharedLibrary}" ]; then
|
|
|
|
ln -s $out/lib/liblapack${canonicalExtension} "$out/lib/liblapack${stdenv.hostPlatform.extensions.sharedLibrary}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
install -D ${lib.getDev lapack-reference}/include/lapack.h $dev/include/lapack.h
|
|
|
|
|
|
|
|
cat <<EOF > $dev/lib/pkgconfig/lapack.pc
|
|
|
|
Name: lapack
|
|
|
|
Version: ${version}
|
|
|
|
Description: LAPACK FORTRAN implementation
|
|
|
|
Cflags: -I$dev/include
|
|
|
|
Libs: -L$out/lib -llapack
|
|
|
|
EOF
|
|
|
|
|
2022-03-30 09:31:56 +00:00
|
|
|
liblapacke="${lib.getLib lapackProvider'}/lib/liblapacke${canonicalExtension}"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
if ! [ -e "$liblapacke" ]; then
|
2022-03-30 09:31:56 +00:00
|
|
|
echo "$liblapacke does not exist, ${lapackProvider'.name} does not provide liblapacke."
|
2020-04-24 23:36:52 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
cp -L "$liblapacke" $out/lib/liblapacke${canonicalExtension}
|
|
|
|
chmod +w $out/lib/liblapacke${canonicalExtension}
|
|
|
|
|
2023-02-16 17:41:37 +00:00
|
|
|
'' + (lib.optionalString (stdenv.hostPlatform.parsed.kernel.execFormat.name == "elf") ''
|
2020-04-24 23:36:52 +00:00
|
|
|
patchelf --set-soname liblapacke${canonicalExtension} $out/lib/liblapacke${canonicalExtension}
|
2022-03-30 09:31:56 +00:00
|
|
|
patchelf --set-rpath "$(patchelf --print-rpath $out/lib/liblapacke${canonicalExtension}):${lib.getLib lapackProvider'}/lib" $out/lib/liblapacke${canonicalExtension}
|
2023-02-16 17:41:37 +00:00
|
|
|
'') + ''
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
if [ -f "$out/lib/liblapacke.so.3" ]; then
|
|
|
|
ln -s $out/lib/liblapacke.so.3 $out/lib/liblapacke.so
|
|
|
|
fi
|
|
|
|
|
2022-01-13 20:06:32 +00:00
|
|
|
cp ${lib.getDev lapack-reference}/include/lapacke{,_mangling,_config,_utils}.h $dev/include
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
cat <<EOF > $dev/lib/pkgconfig/lapacke.pc
|
|
|
|
Name: lapacke
|
|
|
|
Version: ${version}
|
|
|
|
Description: LAPACK C implementation
|
|
|
|
Cflags: -I$dev/include
|
|
|
|
Libs: -L$out/lib -llapacke
|
|
|
|
EOF
|
2021-02-05 17:12:51 +00:00
|
|
|
'' + lib.optionalString (lapackImplementation == "mkl") ''
|
2020-04-24 23:36:52 +00:00
|
|
|
mkdir -p $out/nix-support
|
|
|
|
echo 'export MKL_INTERFACE_LAYER=${lib.optionalString isILP64 "I"}LP64,GNU' > $out/nix-support/setup-hook
|
|
|
|
ln -s $out/lib/liblapack${canonicalExtension} $out/lib/libmkl_rt${stdenv.hostPlatform.extensions.sharedLibrary}
|
2022-03-30 09:31:56 +00:00
|
|
|
ln -sf ${lapackProvider'}/include/* $dev/include
|
2020-04-24 23:36:52 +00:00
|
|
|
'');
|
|
|
|
}
|