about summary refs log tree commit diff
path: root/pkgs/development/compilers/mlton
diff options
context:
space:
mode:
authorMarco Maggesi <maggesi@math.unifi.it>2014-04-14 18:46:32 +0200
committerRok Garbas <rok@garbas.si>2014-04-19 14:30:39 +0100
commit3737ec7c746c7cdf7236793f07ac1d3d30978054 (patch)
tree3932496031f60740c2355d5ac19c5dbd5e6c099b /pkgs/development/compilers/mlton
parent6926d6c97df32e02aa9767b3d121a6480c968f52 (diff)
downloadnixlib-3737ec7c746c7cdf7236793f07ac1d3d30978054.tar
nixlib-3737ec7c746c7cdf7236793f07ac1d3d30978054.tar.gz
nixlib-3737ec7c746c7cdf7236793f07ac1d3d30978054.tar.bz2
nixlib-3737ec7c746c7cdf7236793f07ac1d3d30978054.tar.lz
nixlib-3737ec7c746c7cdf7236793f07ac1d3d30978054.tar.xz
nixlib-3737ec7c746c7cdf7236793f07ac1d3d30978054.tar.zst
nixlib-3737ec7c746c7cdf7236793f07ac1d3d30978054.zip
Enable compilation of MLton on darwin
Diffstat (limited to 'pkgs/development/compilers/mlton')
-rw-r--r--pkgs/development/compilers/mlton/default.nix41
1 files changed, 24 insertions, 17 deletions
diff --git a/pkgs/development/compilers/mlton/default.nix b/pkgs/development/compilers/mlton/default.nix
index 4bd05301ecff..44cbb5951f2a 100644
--- a/pkgs/development/compilers/mlton/default.nix
+++ b/pkgs/development/compilers/mlton/default.nix
@@ -2,6 +2,8 @@
 
 let
   version = "20130715";
+
+  usr_prefix = if stdenv.isDarwin then "usr/local" else "usr";
 in
 stdenv.mkDerivation rec {
   name = "mlton-${version}";
@@ -15,6 +17,10 @@ stdenv.mkDerivation rec {
         url = "http://sourceforge.net/projects/mlton/files/mlton/${version}/${name}-1.amd64-linux.tgz";
         sha256 = "0fyhwxb4nmpirjbjcvk9f6w67gmn2gkz7xcgz0xbfih9kc015ygn";
     })
+    else if stdenv.system == "x86_64-darwin" then (fetchurl {
+        url = "http://sourceforge.net/projects/mlton/files/mlton/${version}/${name}-1.amd64-darwin.gmp-macports.tgz";
+        sha256 = "044wnh9hhg6if886xy805683k0as347xd37r0r1yi4x7qlxzzgx9";
+    })
     else throw "Architecture not supported";
 
   codeSrc =
@@ -38,30 +44,31 @@ stdenv.mkDerivation rec {
     substituteInPlace $(pwd)/Makefile --replace '/bin/cp' $(type -p cp)
 
     # Fix paths in the binary distribution.
-    BIN_DIST_DIR="$(pwd)/../usr"
+    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/bin/env bash' $(type -p bash)
+      substituteInPlace "$BIN_DIST_DIR/$f" --replace '/${usr_prefix}/bin/env bash' $(type -p bash)
     done
 
-    substituteInPlace $(pwd)/../usr/bin/mlton --replace '/usr/lib/mlton' $(pwd)/../usr/lib/mlton
+    substituteInPlace $(pwd)/../${usr_prefix}/bin/mlton --replace '/${usr_prefix}/lib/mlton' $(pwd)/../${usr_prefix}/lib/mlton
   '';
 
   preBuild = ''
     # To build the source we have to put the binary distribution in the $PATH.
-    export PATH="$PATH:$(pwd)/../usr/bin/"
+    export PATH="$PATH:$(pwd)/../${usr_prefix}/bin/"
 
     # Let the builder execute the binary distribution.
-    chmod u+x $(pwd)/../usr/bin/mllex
-    chmod u+x $(pwd)/../usr/bin/mlyacc
-    chmod u+x $(pwd)/../usr/bin/mlton
+    chmod u+x $(pwd)/../${usr_prefix}/bin/mllex
+    chmod u+x $(pwd)/../${usr_prefix}/bin/mlyacc
+    chmod u+x $(pwd)/../${usr_prefix}/bin/mlton
 
     # So the builder runs the binary compiler with gmp.
     export LD_LIBRARY_PATH=${gmp}/lib:$LD_LIBRARY_PATH
 
+  '' + stdenv.lib.optionalString stdenv.isLinux ''
     # Patch ELF interpreter.
-    patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux-x86-64.so.2 $(pwd)/../usr/lib/mlton/mlton-compile
+    patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux-x86-64.so.2 $(pwd)/../${usr_prefix}/lib/mlton/mlton-compile
     for e in mllex mlyacc ; do
-      patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux-x86-64.so.2 $(pwd)/../usr/bin/$e
+      patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux-x86-64.so.2 $(pwd)/../${usr_prefix}/bin/$e
     done
   '';
 
@@ -71,21 +78,21 @@ stdenv.mkDerivation rec {
 
   postInstall = ''
     # Fix path to mlton libraries.
-    substituteInPlace $(pwd)/install/usr/bin/mlton --replace '/usr/lib/mlton' $out/lib/mlton
+    substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace '/${usr_prefix}/lib/mlton' $out/lib/mlton
 
     # Path to libgmp.
-    substituteInPlace $(pwd)/install/usr/bin/mlton --replace "-link-opt '-lm -lgmp'" "-link-opt '-lm -lgmp -L${gmp}/lib'"
+    substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace "-link-opt '-lm -lgmp'" "-link-opt '-lm -lgmp -L${gmp}/lib'"
 
     # Path to gmp.h.
-    substituteInPlace $(pwd)/install/usr/bin/mlton --replace "-cc-opt '-O1 -fno-common'" "-cc-opt '-O1 -fno-common -I${gmp}/include'"
+    substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace "-cc-opt '-O1 -fno-common'" "-cc-opt '-O1 -fno-common -I${gmp}/include'"
 
     # Path to the same gcc used in the build; needed at runtime.
-    substituteInPlace $(pwd)/install/usr/bin/mlton --replace "gcc='gcc'" "gcc='"$(type -p gcc)"'"
+    substituteInPlace $(pwd)/install/${usr_prefix}/bin/mlton --replace "gcc='gcc'" "gcc='"$(type -p gcc)"'"
 
     # Copy files to final positions.
-    cp -r $(pwd)/install/usr/bin $out
-    cp -r $(pwd)/install/usr/lib $out
-    cp -r $(pwd)/install/usr/man $out
+    cp -r $(pwd)/install/${usr_prefix}/bin $out
+    cp -r $(pwd)/install/${usr_prefix}/lib $out
+    cp -r $(pwd)/install/${usr_prefix}/man $out
   '';
 
   meta = {
@@ -101,6 +108,6 @@ stdenv.mkDerivation rec {
 
     homepage = http://mlton.org/;
     license = "bsd";
-    platforms = [ "i686-linux" "x86_64-linux" ];
+    platforms = [ "i686-linux" "x86_64-linux" "x86_64-darwin"];
   };
 }