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