1{
2 lib,
3 stdenv,
4 fetchpatch,
5 fetchurl,
6 patchelf,
7 bash,
8 gmp,
9}:
10let
11 dynamic-linker = stdenv.cc.bintools.dynamicLinker;
12in
13stdenv.mkDerivation rec {
14 pname = "mlton";
15 version = "20210117";
16
17 src =
18 if stdenv.hostPlatform.system == "x86_64-linux" then
19 (fetchurl {
20 url = "https://github.com/MLton/mlton/releases/download/on-${version}-release/${pname}-${version}-1.amd64-linux-glibc2.31.tgz";
21 sha256 = "1lj51xg9p75qj1x5036lvjvd4a2j21kfi6vh8d0n9kdcdffvb73l";
22 })
23 else if stdenv.hostPlatform.system == "x86_64-darwin" then
24 (fetchurl {
25 url = "https://github.com/MLton/mlton/releases/download/on-${version}-release/${pname}-${version}-1.amd64-darwin-19.6.gmp-static.tgz";
26 sha256 = "0xndr2awlxdqr81j6snl9zqjx8r6f5fy9x65j1w899kf2dh9zsjv";
27 })
28 else if stdenv.hostPlatform.system == "aarch64-darwin" then
29 (fetchurl {
30 url = "https://projects.laas.fr/tina/software/mlton-${version}-1.arm64-darwin-21.6-gmp-static.tgz";
31 sha256 = "1s61ayk3yj2xw8ilqk3fhb03x5x1wcakkmbhhvcsfb2hdw2c932x";
32 })
33 else
34 throw "Architecture not supported";
35
36 patches = [
37 (fetchpatch {
38 name = "remove-duplicate-if.patch";
39 url = "https://github.com/MLton/mlton/commit/22002cd0a53a1ab84491d74cb8dc6a4e50c1f7b7.patch";
40 decode = "sed -e 's|Makefile\\.binary|Makefile|g'";
41 hash = "sha256-Gtmc+OIh+m7ordSn74fpOKVDQDtYyLHe6Le2snNCBYQ=";
42 })
43 ];
44
45 buildInputs = [
46 bash
47 gmp
48 ];
49 nativeBuildInputs = lib.optional stdenv.hostPlatform.isLinux patchelf;
50 strictDeps = true;
51
52 buildPhase = ''
53 make update \
54 CC="$(type -p cc)" \
55 WITH_GMP_INC_DIR="${gmp.dev}/include" \
56 WITH_GMP_LIB_DIR="${gmp}/lib"
57 '';
58
59 installPhase = ''
60 make install PREFIX=$out
61 '';
62
63 postFixup =
64 lib.optionalString stdenv.hostPlatform.isLinux ''
65 patchelf --set-interpreter ${dynamic-linker} $out/lib/mlton/mlton-compile
66 patchelf --set-rpath ${gmp}/lib $out/lib/mlton/mlton-compile
67
68 for e in mllex mlnlffigen mlprof mlyacc; do
69 patchelf --set-interpreter ${dynamic-linker} $out/bin/$e
70 patchelf --set-rpath ${gmp}/lib $out/bin/$e
71 done
72 ''
73 + lib.optionalString stdenv.hostPlatform.isDarwin ''
74 install_name_tool -change \
75 /opt/local/lib/libgmp.10.dylib \
76 ${gmp}/lib/libgmp.10.dylib \
77 $out/lib/mlton/mlton-compile
78
79 for e in mllex mlnlffigen mlprof mlyacc; do
80 install_name_tool -change \
81 /opt/local/lib/libgmp.10.dylib \
82 ${gmp}/lib/libgmp.10.dylib \
83 $out/bin/$e
84 done
85 '';
86
87 meta = import ./meta.nix;
88}