about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/mlton/20180207-binary.nix
blob: 0589733cb3c6251550e09cb99bed0cdb896826a9 (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
{ stdenv, fetchurl, patchelf, gmp }:
let
  dynamic-linker = stdenv.cc.bintools.dynamicLinker;
in
stdenv.mkDerivation rec {
  name = "mlton-${version}";
  version = "20180207";

  src = if stdenv.hostPlatform.system == "x86_64-linux" then (fetchurl {
    url = "https://github.com/MLton/mlton/releases/download/on-${version}-release/${name}-1.amd64-linux.tgz";
    sha256 = "0f4q575yfm5dpg4a2wsnqn4l2zrar96p6rlsk0dw10ggyfwvsjlf";
    })
  else if stdenv.hostPlatform.system == "x86_64-darwin" then (fetchurl {
    url = "https://github.com/MLton/mlton/releases/download/on-${version}-release/${name}-1.amd64-darwin.gmp-static.tgz";
      sha256 = "1cw7yhw48qp12q0adwf8srpjzrgkp84kmlkqw3pz8vkxz4p9hbdv";
    })
  else
    throw "Architecture not supported";

  buildInputs = [ gmp ];
  nativeBuildInputs = stdenv.lib.optional stdenv.isLinux patchelf;

  buildPhase = ''
    make update \
      CC="$(type -p cc)" \
      WITH_GMP_INC_DIR="${gmp.dev}/include" \
      WITH_GMP_LIB_DIR="${gmp}/lib"
  '';

  installPhase = ''
    make install PREFIX=$out
  '';

  postFixup = stdenv.lib.optionalString stdenv.isLinux ''
    patchelf --set-interpreter ${dynamic-linker} $out/lib/mlton/mlton-compile
    patchelf --set-rpath ${gmp}/lib $out/lib/mlton/mlton-compile

    for e in mllex mlnlffigen mlprof mlyacc; do
      patchelf --set-interpreter ${dynamic-linker} $out/bin/$e
      patchelf --set-rpath ${gmp}/lib $out/bin/$e
    done
  '' + stdenv.lib.optionalString stdenv.isDarwin ''
    install_name_tool -change \
      /opt/local/lib/libgmp.10.dylib \
      ${gmp}/lib/libgmp.10.dylib \
      $out/lib/mlton/mlton-compile

    for e in mllex mlnlffigen mlprof mlyacc; do
      install_name_tool -change \
        /opt/local/lib/libgmp.10.dylib \
        ${gmp}/lib/libgmp.10.dylib \
        $out/bin/$e
    done
  '';

  meta = import ./meta.nix;
}