···11+{ stdenvNoCC, writeText, fetchurl, rpmextract, undmg }:
22+/*
33+ Some (but not all) mkl functions require openmp, but Intel does not add these
44+ to SO_NEEDED and instructs users to put openmp on their LD_LIBRARY_PATH. If
55+ you are using mkl and your library/application is using some of the functions
66+ that require openmp, add a setupHook like this to your package:
77+88+ setupHook = writeText "setup-hook.sh" ''
99+ addOpenmp() {
1010+ addToSearchPath LD_LIBRARY_PATH ${openmp}/lib
1111+ }
1212+ addEnvHooks "$targetOffset" addOpenmp
1313+ '';
1414+1515+ We do not add the setup hook here, because avoiding it allows this large
1616+ package to be a fixed-output derivation with better cache efficiency.
1717+ */
1818+1919+stdenvNoCC.mkDerivation rec {
2020+ name = "mkl-${version}";
2121+ version = "${date}.${rel}";
2222+ date = "2019.0";
2323+ rel = "117";
2424+2525+ src = if stdenvNoCC.isDarwin
2626+ then
2727+ (fetchurl {
2828+ url = "http://registrationcenter-download.intel.com/akdlm/irc_nas/tec/13565/m_mkl_${version}.dmg";
2929+ sha256 = "1f1jppac7vqwn00hkws0p4njx38ajh0n25bsjyb5d7jcacwfvm02";
3030+ })
3131+ else
3232+ (fetchurl {
3333+ url = "http://registrationcenter-download.intel.com/akdlm/irc_nas/tec/13575/l_mkl_${version}.tgz";
3434+ sha256 = "1bf7i54iqlf7x7fn8kqwmi06g30sxr6nq3ac0r871i6g0p3y47sf";
3535+ });
3636+3737+ buildInputs = if stdenvNoCC.isDarwin then [ undmg ] else [ rpmextract ];
3838+3939+ buildPhase = if stdenvNoCC.isDarwin then ''
4040+ for f in Contents/Resources/pkg/*.tgz; do
4141+ tar xzvf $f
4242+ done
4343+ '' else ''
4444+ rpmextract rpm/intel-mkl-common-c-${date}-${rel}-${date}-${rel}.noarch.rpm
4545+ rpmextract rpm/intel-mkl-core-rt-${date}-${rel}-${date}-${rel}.x86_64.rpm
4646+ '';
4747+4848+ installPhase = if stdenvNoCC.isDarwin then ''
4949+ mkdir -p $out/lib
5050+ cp -r compilers_and_libraries_${version}/mac/mkl/include $out/
5151+ cp -r compilers_and_libraries_${version}/mac/mkl/lib/* $out/lib/
5252+ cp -r compilers_and_libraries_${version}/licensing/mkl/en/license.txt $out/lib/
5353+ '' else ''
5454+ mkdir -p $out/lib
5555+ cp -r opt/intel/compilers_and_libraries_${version}/linux/mkl/include $out/
5656+ cp -r opt/intel/compilers_and_libraries_${version}/linux/mkl/lib/intel64_lin/* $out/lib/
5757+ cp license.txt $out/lib/
5858+ '';
5959+6060+ # Per license agreement, do not modify the binary
6161+ dontStrip = true;
6262+ dontPatchELF = true;
6363+6464+ # Since these are unmodified binaries from Intel, they do not depend on stdenv
6565+ # and we can make them fixed-output derivations for cache efficiency.
6666+ outputHashAlgo = "sha256";
6767+ outputHashMode = "recursive";
6868+ outputHash = if stdenvNoCC.isDarwin
6969+ then "1224dln7n8px1rk8biiggf77wjhxh8mzw0hd8zlyjm8i6j8w7i12"
7070+ else "0d8ai0wi8drp071acqkm1wv6vyg12010y843y56zzi1pql81xqvx";
7171+7272+ meta = with stdenvNoCC.lib; {
7373+ description = "Intel Math Kernel Library";
7474+ longDescription = ''
7575+ Intel Math Kernel Library (Intel MKL) optimizes code with minimal effort
7676+ for future generations of Intel processors. It is compatible with your
7777+ choice of compilers, languages, operating systems, and linking and
7878+ threading models.
7979+ '';
8080+ homepage = https://software.intel.com/en-us/mkl;
8181+ license = [ licenses.issl licenses.unfreeRedistributable ];
8282+ platforms = [ "x86_64-linux" "x86_64-darwin" ];
8383+ maintainers = [ maintainers.bhipple ];
8484+ };
8585+}