summary refs log tree commit diff
path: root/pkgs/development/misc/amdapp-sdk/default.nix
blob: 355afb9587b69b9b159d759641632ce96a832800 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{ stdenv, fetchurl, makeWrapper, perl, mesa, xorg,
  version? "2.8", # What version
  samples? false # Should samples be installed
}:

let

  src_hashes = {
    "2.6" = {
      x86 = "99610737f21b2f035e0eac4c9e776446cc4378a614c7667de03a82904ab2d356";
      x86_64 = "1fj55358s4blxq9bp77k07gqi22n5nfkzwjkbdc62gmy1zxxlhih";
    };

    "2.7" = {
      x86 = "99610737f21b2f035e0eac4c9e776446cc4378a614c7667de03a82904ab2d356";
      x86_64 = "08bi43bgnsxb47vbirh09qy02w7zxymqlqr8iikk9aavfxjlmch1";
    };

    "2.8" = {
      x86 = "99610737f21b2f035e0eac4c9e776446cc4378a614c7667de03a82904ab2d356";
      x86_64 = "d9c120367225bb1cd21abbcf77cb0a69cfb4bb6932d0572990104c566aab9681";
    };
  };

  bits = if stdenv.system == "x86_64-linux" then "64"
         else "32";

  arch = if stdenv.system == "x86_64-linux" then "x86_64"
         else "x86";

in stdenv.mkDerivation rec {
  name = "amdapp-sdk-${version}";

  src = if stdenv.system == "x86_64-linux" then fetchurl {
    url = "http://developer.amd.com/wordpress/media/2012/11/AMD-APP-SDK-v${version}-lnx64.tgz";
    sha256 = (builtins.getAttr version src_hashes).x86_64;
  } else if stdenv.system == "i686-linux" then fetchurl {
    url = "http://developer.amd.com/wordpress/media/2012/11/AMD-APP-SDK-v${version}-lnx32.tgz";
    sha256 = (builtins.getAttr version src_hashes).x86;
  } else
    throw "System not supported";

  # TODO: Add support for aparapi, java parallel api
  patches = [ ./01-remove-aparapi-samples.patch ];

  patchFlags = "-p0";
  buildInputs = [ makeWrapper perl mesa xorg.libX11 xorg.libXext xorg.libXaw xorg.libXi xorg.libXxf86vm ];
  propagatedBuildInputs = [ stdenv.gcc ];
  NIX_LDFLAGS = "-lX11 -lXext -lXmu -lXi -lXxf86vm";
  doCheck = false;

  unpackPhase = ''
    tar xvzf $src
    tar xf AMD-APP-SDK-v${version}-RC-lnx${bits}.tgz
    cd AMD-APP-SDK-v${version}-RC-lnx${bits}
  '';

  buildPhase = if !samples then ''echo "nothing to build"'' else null;

  installPhase = ''
    # Install SDK
    mkdir -p $out
    cp -r {docs,include} "$out/"
    mkdir -p "$out/"{bin,lib,samples/opencl/bin}
    cp -r "./bin/${arch}/clinfo" "$out/bin/clinfo"
    cp -r "./lib/${arch}/"* "$out/lib/"

    # Register ICD
    mkdir -p "$out/etc/OpenCL/vendors"
    echo "$out/lib/libamdocl${bits}.so" > "$out/etc/OpenCL/vendors/amd.icd"
    # The OpenCL ICD specifications: http://www.khronos.org/registry/cl/extensions/khr/cl_khr_icd.txt

    # Install includes
    mkdir -p "$out/usr/include/"{CAL,OpenVideo}
    install -m644 './include/OpenVideo/'{OVDecode.h,OVDecodeTypes.h} "$out/usr/include/OpenVideo/"

    ${ if samples then ''
      # Install samples
      find ./samples/opencl/ -mindepth 1 -maxdepth 1 -type d -not -name bin -exec cp -r {} "$out/samples/opencl" \;
      cp -r "./samples/opencl/bin/${arch}/"* "$out/samples/opencl/bin"
      for f in $(find "$out/samples/opencl/bin/" -type f -not -name "*.*");
      do
        wrapProgram "$f" --prefix PATH ":" "${stdenv.gcc}/bin"
      done'' else ""
    }

    # Create wrappers
    patchelf --set-interpreter "$(cat $NIX_GCC/nix-support/dynamic-linker)" $out/bin/clinfo
    patchelf --set-rpath ${stdenv.gcc.gcc}/lib64:${stdenv.gcc.gcc}/lib $out/bin/clinfo

    # Fix modes
    find "$out/" -type f -exec chmod 644 {} \;
    chmod -R 755 "$out/bin/"
    find "$out/samples/opencl/bin/" -type f -name ".*" -exec chmod 755 {} \;
    find "$out/samples/opencl/bin/" -type f -not -name "*.*" -exec chmod 755 {} \;
  '';

  meta = with stdenv.lib; {
    description = "AMD Accelerated Parallel Processing (APP) SDK, with OpenCL 1.2 support";
    homepage = http://developer.amd.com/tools/heterogeneous-computing/amd-accelerated-parallel-processing-app-sdk/;
    license = licenses.amd;
    maintainers = [ maintainers.offline ];
    platforms = [ "i686-linux" "x86_64-linux" ];
 };
}