@@ -0,0 +1,61 @@
1+{ stdenv, fetchzip, rpmextract, ncurses5, numactl, zlib }:
2+
3+stdenv.mkDerivation rec {
4+ version = "r4.0-59481";
5+ name = "intel-ocl-${version}";
6+
7+ src = fetchzip {
8+ url = "https://software.intel.com/sites/default/files/managed/48/96/SRB4_linux64.zip";
9+ sha256 = "1q69g28i6l7p13hnsk82g2qhdf2chwh4f0wvzac6xml67hna3v34";
10+ stripRoot = false;
11+ };
12+
13+ buildInputs = [ rpmextract ];
14+
15+ sourceRoot = ".";
16+
17+ libPath = stdenv.lib.makeLibraryPath [
18+ stdenv.cc.cc.lib
19+ ncurses5
20+ numactl
21+ zlib
22+ ];
23+
24+ postUnpack = ''
25+ # Extract the RPMs contained within the source ZIP.
26+ rpmextract SRB4_linux64.zip/intel-opencl-${version}.x86_64.rpm
27+ rpmextract SRB4_linux64.zip/intel-opencl-cpu-${version}.x86_64.rpm
28+ '';
29+
30+ patchPhase = ''
31+ # Remove libOpenCL.so, since we use ocl-icd's libOpenCL.so instead and this would cause a clash.
32+ rm opt/intel/opencl/libOpenCL.so*
33+
34+ # Patch shared libraries.
35+ for lib in opt/intel/opencl/*.so; do
36+ patchelf --set-rpath "${libPath}:$out/lib/intel-ocl" $lib || true
37+ done
38+ '';
39+
40+ buildPhase = ''
41+ # Create ICD file, which just contains the path of the corresponding shared library.
42+ echo "$out/lib/intel-ocl/libintelocl.so" > intel.icd
43+ '';
44+
45+ installPhase = ''
46+ install -D -m 0755 opt/intel/opencl/*.so* -t $out/lib/intel-ocl
47+ install -D -m 0644 opt/intel/opencl/*.{o,rtl,bin} -t $out/lib/intel-ocl
48+ install -D -m 0644 opt/intel/opencl/{LICENSE,NOTICES} -t $out/share/doc/intel-ocl
49+ install -D -m 0644 intel.icd -t $out/etc/OpenCL/vendors
50+ '';
51+
52+ dontStrip = true;
53+
54+ meta = {
55+ description = "Official OpenCL runtime for Intel CPUs";
56+ homepage = https://software.intel.com/en-us/articles/opencl-drivers;
57+ license = stdenv.lib.licenses.unfree;
58+ platforms = [ "x86_64-linux" ];
59+ maintainers = [ stdenv.lib.maintainers.kierdavis ];
60+ };
61+}