2014-02-03 19:12:30 +01:00
|
|
|
{ stdenv, fetchurl, patchelf, gmp }:
|
2010-08-24 10:23:16 +02:00
|
|
|
|
2014-01-05 15:20:48 +01:00
|
|
|
let
|
|
|
|
version = "20130715";
|
2014-04-14 18:46:32 +02:00
|
|
|
|
|
|
|
usr_prefix = if stdenv.isDarwin then "usr/local" else "usr";
|
2014-04-15 15:59:01 +02:00
|
|
|
|
2018-10-12 05:58:25 +02:00
|
|
|
dynamic_linker = stdenv.cc.bintools.dynamicLinker;
|
2014-01-05 15:20:48 +01:00
|
|
|
in
|
2014-04-15 15:59:01 +02:00
|
|
|
|
2010-08-24 10:23:16 +02:00
|
|
|
stdenv.mkDerivation rec {
|
2014-01-05 15:20:48 +01:00
|
|
|
name = "mlton-${version}";
|
2010-08-24 10:23:16 +02:00
|
|
|
|
|
|
|
binSrc =
|
2018-08-20 21:11:29 +02:00
|
|
|
if stdenv.hostPlatform.system == "i686-linux" then (fetchurl {
|
2016-08-20 15:36:33 +02:00
|
|
|
url = "mirror://sourceforge/project/mlton/mlton/${version}/${name}-1.x86-linux.tgz";
|
2014-01-05 15:20:48 +01:00
|
|
|
sha256 = "1kxjjmnw4xk2d9hpvz43w9dvyhb3025k4zvjx785c33nrwkrdn4j";
|
2010-08-24 10:23:16 +02:00
|
|
|
})
|
2018-08-20 21:11:29 +02:00
|
|
|
else if stdenv.hostPlatform.system == "x86_64-linux" then (fetchurl {
|
2016-08-20 15:36:33 +02:00
|
|
|
url = "mirror://sourceforge/project/mlton/mlton/${version}/${name}-1.amd64-linux.tgz";
|
2014-01-05 15:20:48 +01:00
|
|
|
sha256 = "0fyhwxb4nmpirjbjcvk9f6w67gmn2gkz7xcgz0xbfih9kc015ygn";
|
2010-08-24 10:23:16 +02:00
|
|
|
})
|
2018-08-20 21:11:29 +02:00
|
|
|
else if stdenv.hostPlatform.system == "x86_64-darwin" then (fetchurl {
|
2016-08-20 15:36:33 +02:00
|
|
|
url = "mirror://sourceforge/project/mlton/mlton/${version}/${name}-1.amd64-darwin.gmp-macports.tgz";
|
2014-04-14 18:46:32 +02:00
|
|
|
sha256 = "044wnh9hhg6if886xy805683k0as347xd37r0r1yi4x7qlxzzgx9";
|
|
|
|
})
|
2010-08-24 10:23:16 +02:00
|
|
|
else throw "Architecture not supported";
|
|
|
|
|
|
|
|
codeSrc =
|
|
|
|
fetchurl {
|
2016-08-20 15:36:33 +02:00
|
|
|
url = "mirror://sourceforge/project/mlton/mlton/${version}/${name}.src.tgz";
|
2014-01-05 15:20:48 +01:00
|
|
|
sha256 = "0v1x2hrh9hiqkvnbq11kf34v4i5a2x0ffxbzqaa8skyl26nmfn11";
|
2010-08-24 10:23:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
srcs = [ binSrc codeSrc ];
|
|
|
|
|
|
|
|
sourceRoot = name;
|
|
|
|
|
2018-09-27 23:38:10 +02:00
|
|
|
buildInputs = [ gmp ];
|
|
|
|
nativeBuildInputs = stdenv.lib.optional stdenv.isLinux patchelf;
|
2010-08-24 10:23:16 +02:00
|
|
|
|
|
|
|
makeFlags = [ "all-no-docs" ];
|
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
# Fix paths in the source.
|
2012-04-22 22:39:43 +02:00
|
|
|
find . -type f | grep -v -e '\.tgz''$' | xargs sed -i "s@/usr/bin/env bash@$(type -p bash)@"
|
2010-08-24 10:23:16 +02:00
|
|
|
|
|
|
|
substituteInPlace $(pwd)/Makefile --replace '/bin/cp' $(type -p cp)
|
2015-02-09 01:22:52 +01:00
|
|
|
substituteInPlace bin/mlton-script --replace gcc cc
|
|
|
|
substituteInPlace bin/regression --replace gcc cc
|
|
|
|
substituteInPlace lib/mlnlffi-lib/Makefile --replace gcc cc
|
|
|
|
substituteInPlace mlnlffigen/gen-cppcmd --replace gcc cc
|
|
|
|
substituteInPlace runtime/Makefile --replace gcc cc
|
|
|
|
substituteInPlace ../${usr_prefix}/bin/mlton --replace gcc cc
|
2010-08-24 10:23:16 +02:00
|
|
|
|
|
|
|
# Fix paths in the binary distribution.
|
2014-04-14 18:46:32 +02:00
|
|
|
BIN_DIST_DIR="$(pwd)/../${usr_prefix}"
|
2010-08-24 10:23:16 +02:00
|
|
|
for f in "bin/mlton" "lib/mlton/platform" "lib/mlton/static-library" ; do
|
2014-04-14 18:46:32 +02:00
|
|
|
substituteInPlace "$BIN_DIST_DIR/$f" --replace '/${usr_prefix}/bin/env bash' $(type -p bash)
|
2010-08-24 10:23:16 +02:00
|
|
|
done
|
|
|
|
|
2014-04-14 18:46:32 +02:00
|
|
|
substituteInPlace $(pwd)/../${usr_prefix}/bin/mlton --replace '/${usr_prefix}/lib/mlton' $(pwd)/../${usr_prefix}/lib/mlton
|
2016-09-23 05:02:03 +02:00
|
|
|
'' + stdenv.lib.optionalString stdenv.cc.isClang ''
|
|
|
|
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
|
2016-09-24 21:28:10 +02:00
|
|
|
'' + stdenv.lib.optionalString stdenv.isDarwin ''
|
|
|
|
sed -i 's|XCFLAGS += -I/usr/local/include -I/sw/include -I/opt/local/include||' ./runtime/Makefile
|
2010-08-24 10:23:16 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
preBuild = ''
|
|
|
|
# To build the source we have to put the binary distribution in the $PATH.
|
2014-04-14 18:46:32 +02:00
|
|
|
export PATH="$PATH:$(pwd)/../${usr_prefix}/bin/"
|
2010-08-24 10:23:16 +02:00
|
|
|
|
|
|
|
# Let the builder execute the binary distribution.
|
2014-04-14 18:46:32 +02:00
|
|
|
chmod u+x $(pwd)/../${usr_prefix}/bin/mllex
|
|
|
|
chmod u+x $(pwd)/../${usr_prefix}/bin/mlyacc
|
|
|
|
chmod u+x $(pwd)/../${usr_prefix}/bin/mlton
|
2014-02-03 19:12:30 +01:00
|
|
|
|
|
|
|
# So the builder runs the binary compiler with gmp.
|
2015-10-15 17:43:23 +02:00
|
|
|
export LD_LIBRARY_PATH=${gmp.out}/lib:$LD_LIBRARY_PATH
|
2014-02-03 19:12:30 +01:00
|
|
|
|
2014-04-14 18:46:32 +02:00
|
|
|
'' + stdenv.lib.optionalString stdenv.isLinux ''
|
2014-02-03 19:12:30 +01:00
|
|
|
# Patch ELF interpreter.
|
2014-04-15 15:59:01 +02:00
|
|
|
patchelf --set-interpreter ${dynamic_linker} $(pwd)/../${usr_prefix}/lib/mlton/mlton-compile
|
2014-02-03 19:12:30 +01:00
|
|
|
for e in mllex mlyacc ; do
|
2014-04-15 15:59:01 +02:00
|
|
|
patchelf --set-interpreter ${dynamic_linker} $(pwd)/../${usr_prefix}/bin/$e
|
2014-02-03 19:12:30 +01:00
|
|
|
done
|
2016-09-24 21:28:10 +02:00
|
|
|
'' + stdenv.lib.optionalString stdenv.isDarwin ''
|
|
|
|
# Patch libgmp linking
|
|
|
|
install_name_tool -change /opt/local/lib/libgmp.10.dylib ${gmp}/lib/libgmp.10.dylib $(pwd)/../${usr_prefix}/lib/mlton/mlton-compile
|
|
|
|
install_name_tool -change /opt/local/lib/libgmp.10.dylib ${gmp}/lib/libgmp.10.dylib $(pwd)/../${usr_prefix}/bin/mlyacc
|
|
|
|
install_name_tool -change /opt/local/lib/libgmp.10.dylib ${gmp}/lib/libgmp.10.dylib $(pwd)/../${usr_prefix}/bin/mllex
|
2010-08-24 10:23:16 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
doCheck = true;
|
|
|
|
|
|
|
|
installTargets = [ "install-no-docs" ];
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
# Fix path to mlton libraries.
|
2014-04-14 18:46:32 +02:00
|
|
|
substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace '/${usr_prefix}/lib/mlton' $out/lib/mlton
|
2010-08-24 10:23:16 +02:00
|
|
|
|
|
|
|
# Path to libgmp.
|
2015-10-15 17:43:23 +02:00
|
|
|
substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace "-link-opt '-lm -lgmp'" "-link-opt '-lm -lgmp -L${gmp.out}/lib'"
|
2010-08-24 10:23:16 +02:00
|
|
|
|
|
|
|
# Path to gmp.h.
|
2015-10-15 17:43:23 +02:00
|
|
|
substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace "-cc-opt '-O1 -fno-common'" "-cc-opt '-O1 -fno-common -I${gmp.dev}/include'"
|
2010-08-24 10:23:16 +02:00
|
|
|
|
2015-02-09 01:22:52 +01:00
|
|
|
# Path to the same cc used in the build; needed at runtime.
|
|
|
|
substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace "gcc='gcc'" "gcc='"$(type -p cc)"'"
|
2010-08-24 10:23:16 +02:00
|
|
|
|
|
|
|
# Copy files to final positions.
|
2014-04-14 18:46:32 +02:00
|
|
|
cp -r $(pwd)/install/${usr_prefix}/bin $out
|
|
|
|
cp -r $(pwd)/install/${usr_prefix}/lib $out
|
|
|
|
cp -r $(pwd)/install/${usr_prefix}/man $out
|
2010-08-24 10:23:16 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
meta = {
|
2013-10-06 11:49:53 +02:00
|
|
|
description = "Open-source, whole-program, optimizing Standard ML compiler";
|
2010-08-24 10:23:16 +02:00
|
|
|
longDescription = ''
|
|
|
|
MLton is an open source, whole-program optimizing compiler for the Standard ML programming language.
|
|
|
|
MLton aims to produce fast executables, and to encourage rapid prototyping and modular programming
|
|
|
|
by eliminating performance penalties often associated with the use of high-level language features.
|
|
|
|
MLton development began in 1997, and continues to this day with a growing worldwide community of
|
|
|
|
developers and users, who have helped to port MLton to a number of platforms.
|
|
|
|
Description taken from http://en.wikipedia.org/wiki/Mlton .
|
|
|
|
'';
|
|
|
|
|
|
|
|
homepage = http://mlton.org/;
|
|
|
|
license = "bsd";
|
2014-04-14 18:46:32 +02:00
|
|
|
platforms = [ "i686-linux" "x86_64-linux" "x86_64-darwin"];
|
2010-08-24 10:23:16 +02:00
|
|
|
};
|
|
|
|
}
|