summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--pkgs/development/compilers/ghc/7.4.2-binary.nix5
-rwxr-xr-xpkgs/development/compilers/ghc/gcc-clang-wrapper.sh46
2 files changed, 49 insertions, 2 deletions
diff --git a/pkgs/development/compilers/ghc/7.4.2-binary.nix b/pkgs/development/compilers/ghc/7.4.2-binary.nix
index bc083fe7a82..9fd1f038e7c 100644
--- a/pkgs/development/compilers/ghc/7.4.2-binary.nix
+++ b/pkgs/development/compilers/ghc/7.4.2-binary.nix
@@ -62,8 +62,9 @@ stdenv.mkDerivation rec {
      '' else "");
 
   configurePhase = ''
-    ./configure --prefix=$out --with-gmp-libraries=${gmp}/lib --with-gmp-includes=${gmp}/include \
-      --with-clang
+    ./configure --prefix=$out \
+      --with-gmp-libraries=${gmp}/lib --with-gmp-includes=${gmp}/include \
+      ${stdenv.lib.optionalString stdenv.isDarwin "--with-gcc=${./gcc-clang-wrapper.sh}"}
   '';
 
   # Stripping combined with patchelf breaks the executables (they die
diff --git a/pkgs/development/compilers/ghc/gcc-clang-wrapper.sh b/pkgs/development/compilers/ghc/gcc-clang-wrapper.sh
new file mode 100755
index 00000000000..d081be231a1
--- /dev/null
+++ b/pkgs/development/compilers/ghc/gcc-clang-wrapper.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+inPreprocessorMode () {
+    hasE=0
+    hasU=0
+    hasT=0
+    for arg in "$@"
+    do
+        if [ 'x-E' = "x$arg" ];             then hasE=1; fi
+        if [ 'x-undef' = "x$arg" ];         then hasU=1; fi
+        if [ 'x-traditional' = "x$arg" ];   then hasT=1; fi
+    done
+    [ "$hasE$hasU$hasT" = '111' ]
+}
+
+extraClangArgs="-Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs"
+
+adjustPreprocessorLanguage () {
+    newArgs=''
+    while [ $# -gt 0 ]
+    do
+        newArgs="$newArgs $1"
+        if [ "$1" = '-x' ]
+        then
+            shift
+            if [ $# -gt 0 ]
+            then
+                if [ "$1" = 'c' ]
+                then
+                    newArgs="$newArgs assembler-with-cpp"
+                else
+                    newArgs="$newArgs $1"
+                fi
+            fi
+        fi
+        shift
+    done
+    echo $newArgs
+}
+
+if inPreprocessorMode "$@"
+then
+    exec clang $extraClangArgs `adjustPreprocessorLanguage "$@"`
+else
+    exec clang $extraClangArgs "${@/-nodefaultlibs/}"
+fi