@@ -1,134 +1,26 @@
1−{ stdenv, fetchurl, patchelf, gmp }:
2−
3−let
4− version = "20130715";
5−
6− usr_prefix = if stdenv.isDarwin then "usr/local" else "usr";
7−
8− dynamic_linker =
9− if stdenv.isx86_64 then "${stdenv.glibc.out}/lib/ld-linux-x86-64.so.2"
10− else "${stdenv.glibc.out}/lib/ld-linux.so.2";
11−in
12−
13−stdenv.mkDerivation rec {
14− name = "mlton-${version}";
15−
16− binSrc =
17− if stdenv.hostPlatform.system == "i686-linux" then (fetchurl {
18− url = "mirror://sourceforge/project/mlton/mlton/${version}/${name}-1.x86-linux.tgz";
19− sha256 = "1kxjjmnw4xk2d9hpvz43w9dvyhb3025k4zvjx785c33nrwkrdn4j";
20− })
21− else if stdenv.hostPlatform.system == "x86_64-linux" then (fetchurl {
22− url = "mirror://sourceforge/project/mlton/mlton/${version}/${name}-1.amd64-linux.tgz";
23− sha256 = "0fyhwxb4nmpirjbjcvk9f6w67gmn2gkz7xcgz0xbfih9kc015ygn";
24− })
25− else if stdenv.hostPlatform.system == "x86_64-darwin" then (fetchurl {
26− url = "mirror://sourceforge/project/mlton/mlton/${version}/${name}-1.amd64-darwin.gmp-macports.tgz";
27− sha256 = "044wnh9hhg6if886xy805683k0as347xd37r0r1yi4x7qlxzzgx9";
28− })
29− else throw "Architecture not supported";
30−
31− codeSrc =
32− fetchurl {
33− url = "mirror://sourceforge/project/mlton/mlton/${version}/${name}.src.tgz";
34− sha256 = "0v1x2hrh9hiqkvnbq11kf34v4i5a2x0ffxbzqaa8skyl26nmfn11";
35− };
36−
37− srcs = [ binSrc codeSrc ];
38−
39− sourceRoot = name;
40−
41− buildInputs = [ gmp ];
42− nativeBuildInputs = stdenv.lib.optional stdenv.isLinux patchelf;
43−
44− makeFlags = [ "all-no-docs" ];
45−
46− configurePhase = ''
47− # Fix paths in the source.
48− find . -type f | grep -v -e '\.tgz''$' | xargs sed -i "s@/usr/bin/env bash@$(type -p bash)@"
49−
50− substituteInPlace $(pwd)/Makefile --replace '/bin/cp' $(type -p cp)
51− substituteInPlace bin/mlton-script --replace gcc cc
52− substituteInPlace bin/regression --replace gcc cc
53− substituteInPlace lib/mlnlffi-lib/Makefile --replace gcc cc
54− substituteInPlace mlnlffigen/gen-cppcmd --replace gcc cc
55− substituteInPlace runtime/Makefile --replace gcc cc
56− substituteInPlace ../${usr_prefix}/bin/mlton --replace gcc cc
57−
58− # Fix paths in the binary distribution.
59− BIN_DIST_DIR="$(pwd)/../${usr_prefix}"
60− for f in "bin/mlton" "lib/mlton/platform" "lib/mlton/static-library" ; do
61− substituteInPlace "$BIN_DIST_DIR/$f" --replace '/${usr_prefix}/bin/env bash' $(type -p bash)
62− done
63−
64− substituteInPlace $(pwd)/../${usr_prefix}/bin/mlton --replace '/${usr_prefix}/lib/mlton' $(pwd)/../${usr_prefix}/lib/mlton
65− '' + stdenv.lib.optionalString stdenv.cc.isClang ''
66− sed -i "s_ patch -s -p0 <gdtoa.hide-public-fns.patch_ patch -s -p0 <gdtoa.hide-public-fns.patch\n\tsed -i 's|printf(emptyfmt|printf(\"\"|g' ./gdtoa/arithchk.c_" ./runtime/Makefile
67− '' + stdenv.lib.optionalString stdenv.isDarwin ''
68− sed -i 's|XCFLAGS += -I/usr/local/include -I/sw/include -I/opt/local/include||' ./runtime/Makefile
69− '';
70−
71− preBuild = ''
72− # To build the source we have to put the binary distribution in the $PATH.
73− export PATH="$PATH:$(pwd)/../${usr_prefix}/bin/"
74−
75− # Let the builder execute the binary distribution.
76− chmod u+x $(pwd)/../${usr_prefix}/bin/mllex
77− chmod u+x $(pwd)/../${usr_prefix}/bin/mlyacc
78− chmod u+x $(pwd)/../${usr_prefix}/bin/mlton
79−
80− # So the builder runs the binary compiler with gmp.
81− export LD_LIBRARY_PATH=${gmp.out}/lib:$LD_LIBRARY_PATH
82−
83− '' + stdenv.lib.optionalString stdenv.isLinux ''
84− # Patch ELF interpreter.
85− patchelf --set-interpreter ${dynamic_linker} $(pwd)/../${usr_prefix}/lib/mlton/mlton-compile
86− for e in mllex mlyacc ; do
87− patchelf --set-interpreter ${dynamic_linker} $(pwd)/../${usr_prefix}/bin/$e
88− done
89− '' + stdenv.lib.optionalString stdenv.isDarwin ''
90− # Patch libgmp linking
91− install_name_tool -change /opt/local/lib/libgmp.10.dylib ${gmp}/lib/libgmp.10.dylib $(pwd)/../${usr_prefix}/lib/mlton/mlton-compile
92− install_name_tool -change /opt/local/lib/libgmp.10.dylib ${gmp}/lib/libgmp.10.dylib $(pwd)/../${usr_prefix}/bin/mlyacc
93− install_name_tool -change /opt/local/lib/libgmp.10.dylib ${gmp}/lib/libgmp.10.dylib $(pwd)/../${usr_prefix}/bin/mllex
94− '';
95−
96− doCheck = true;
97−
98− installTargets = [ "install-no-docs" ];
99−
100− postInstall = ''
101− # Fix path to mlton libraries.
102− substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace '/${usr_prefix}/lib/mlton' $out/lib/mlton
103−
104− # Path to libgmp.
105− substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace "-link-opt '-lm -lgmp'" "-link-opt '-lm -lgmp -L${gmp.out}/lib'"
106−
107− # Path to gmp.h.
108− substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace "-cc-opt '-O1 -fno-common'" "-cc-opt '-O1 -fno-common -I${gmp.dev}/include'"
109−
110− # Path to the same cc used in the build; needed at runtime.
111− substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace "gcc='gcc'" "gcc='"$(type -p cc)"'"
1+{ stdenv, fetchurl, fetchgit, patchelf, gmp }:
2+rec {
3+ mlton20130715 = import ./20130715.nix {
4+ inherit stdenv fetchurl patchelf gmp;
5+ };
1126
113− # Copy files to final positions.
114− cp -r $(pwd)/install/${usr_prefix}/bin $out
115− cp -r $(pwd)/install/${usr_prefix}/lib $out
116− cp -r $(pwd)/install/${usr_prefix}/man $out
117− '';
7+ mlton20180207Binary = import ./20180207-binary.nix {
8+ inherit stdenv fetchurl patchelf gmp;
9+ };
11810
119− meta = {
120− description = "Open-source, whole-program, optimizing Standard ML compiler";
121− longDescription = ''
122− MLton is an open source, whole-program optimizing compiler for the Standard ML programming language.
123− MLton aims to produce fast executables, and to encourage rapid prototyping and modular programming
124− by eliminating performance penalties often associated with the use of high-level language features.
125− MLton development began in 1997, and continues to this day with a growing worldwide community of
126− developers and users, who have helped to port MLton to a number of platforms.
127− Description taken from http://en.wikipedia.org/wiki/Mlton .
128− '';
11+ mlton20180207 = import ./from-git-source.nix {
12+ mltonBootstrap = mlton20180207Binary;
13+ version = "20180207";
14+ rev = "on-20180207-release";
15+ sha256 = "00rdd2di5x1dzac64il9z05m3fdzicjd3226wwjyynv631jj3q2a";
16+ inherit stdenv fetchgit gmp;
17+ };
12918
130− homepage = http://mlton.org/;
131− license = "bsd";
132− platforms = [ "i686-linux" "x86_64-linux" "x86_64-darwin"];
19+ mltonHEAD = import ./from-git-source.nix {
20+ mltonBootstrap = mlton20180207Binary;
21+ version = "HEAD";
22+ rev = "e149c9917cfbfe6aba5c986a958ed76d5cc6cfde";
23+ sha256 = "0a0j1i0f0fxw2my1309srq5j3vz0kawrrln01gxms2m5hy5dl50d";
24+ inherit stdenv fetchgit gmp;
13325 };
13426}