1{
2 lib,
3 stdenv,
4 fetchurl,
5 patchelf,
6 gmp,
7}:
8let
9 dynamic-linker = stdenv.cc.bintools.dynamicLinker;
10in
11stdenv.mkDerivation rec {
12 pname = "mlton";
13 version = "20180207";
14
15 src =
16 if stdenv.hostPlatform.system == "x86_64-linux" then
17 (fetchurl {
18 url = "https://github.com/MLton/mlton/releases/download/on-${version}-release/${pname}-${version}-1.amd64-linux.tgz";
19 sha256 = "0f4q575yfm5dpg4a2wsnqn4l2zrar96p6rlsk0dw10ggyfwvsjlf";
20 })
21 else if stdenv.hostPlatform.system == "x86_64-darwin" then
22 (fetchurl {
23 url = "https://github.com/MLton/mlton/releases/download/on-${version}-release/${pname}-${version}-1.amd64-darwin.gmp-static.tgz";
24 sha256 = "1cw7yhw48qp12q0adwf8srpjzrgkp84kmlkqw3pz8vkxz4p9hbdv";
25 })
26 else
27 throw "Architecture not supported";
28
29 buildInputs = [ gmp ];
30 nativeBuildInputs = lib.optional stdenv.hostPlatform.isLinux patchelf;
31
32 buildPhase = ''
33 make update \
34 CC="$(type -p cc)" \
35 WITH_GMP_INC_DIR="${gmp.dev}/include" \
36 WITH_GMP_LIB_DIR="${gmp}/lib"
37 '';
38
39 installPhase = ''
40 make install PREFIX=$out
41 '';
42
43 postFixup =
44 lib.optionalString stdenv.hostPlatform.isLinux ''
45 patchelf --set-interpreter ${dynamic-linker} $out/lib/mlton/mlton-compile
46 patchelf --set-rpath ${gmp}/lib $out/lib/mlton/mlton-compile
47
48 for e in mllex mlnlffigen mlprof mlyacc; do
49 patchelf --set-interpreter ${dynamic-linker} $out/bin/$e
50 patchelf --set-rpath ${gmp}/lib $out/bin/$e
51 done
52 ''
53 + lib.optionalString stdenv.hostPlatform.isDarwin ''
54 install_name_tool -change \
55 /opt/local/lib/libgmp.10.dylib \
56 ${gmp}/lib/libgmp.10.dylib \
57 $out/lib/mlton/mlton-compile
58
59 for e in mllex mlnlffigen mlprof mlyacc; do
60 install_name_tool -change \
61 /opt/local/lib/libgmp.10.dylib \
62 ${gmp}/lib/libgmp.10.dylib \
63 $out/bin/$e
64 done
65 '';
66
67 meta = import ./meta.nix;
68}