{ lib, stdenv, fetchurl, patchelf, gmp, }: let version = "20130715"; usr_prefix = if stdenv.hostPlatform.isDarwin then "usr/local" else "usr"; dynamic_linker = stdenv.cc.bintools.dynamicLinker; in stdenv.mkDerivation rec { pname = "mlton"; inherit version; binSrc = if stdenv.hostPlatform.system == "i686-linux" then (fetchurl { url = "mirror://sourceforge/project/mlton/mlton/${version}/${pname}-${version}-1.x86-linux.tgz"; hash = "sha256-ktiWJ892DFbQ6XJ/MosAY0G/W+KD/H1hamJ2wm2Vss8="; }) else if stdenv.hostPlatform.system == "x86_64-linux" then (fetchurl { url = "mirror://sourceforge/project/mlton/mlton/${version}/${pname}-${version}-1.amd64-linux.tgz"; hash = "sha256-9vkSAJsJRrc6+I/18+cTtr5juHFpbiaXzPFWS1bn0Ds="; }) else throw "Architecture not supported"; codeSrc = fetchurl { url = "mirror://sourceforge/project/mlton/mlton/${version}/${pname}-${version}.src.tgz"; hash = "sha256-IVhXrRHUT42Uwn9150AXqkSyyXAzBLzsnjjCBDMUPWw="; }; srcs = [ binSrc codeSrc ]; sourceRoot = "${pname}-${version}"; buildInputs = [ gmp ]; nativeBuildInputs = lib.optional stdenv.hostPlatform.isLinux patchelf; makeFlags = [ "all-no-docs" ]; configurePhase = '' # Fix paths in the source. find . -type f | grep -v -e '\.tgz''$' | xargs sed -i "s@/usr/bin/env bash@$(type -p bash)@" substituteInPlace $(pwd)/Makefile --replace '/bin/cp' $(type -p cp) 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 # Fix paths in the binary distribution. BIN_DIST_DIR="$(pwd)/../${usr_prefix}" for f in "bin/mlton" "lib/mlton/platform" "lib/mlton/static-library" ; do substituteInPlace "$BIN_DIST_DIR/$f" --replace '/${usr_prefix}/bin/env bash' $(type -p bash) done substituteInPlace $(pwd)/../${usr_prefix}/bin/mlton --replace '/${usr_prefix}/lib/mlton' $(pwd)/../${usr_prefix}/lib/mlton '' + lib.optionalString stdenv.cc.isClang '' sed -i "s_ patch -s -p0