From 4a8fbb789a827e0251c7ba61ce45d5463177e722 Mon Sep 17 00:00:00 2001
From: Thomas Tuegel <ttuegel@gmail.com>
Date: Sat, 19 Sep 2015 08:14:46 -0500
Subject: [PATCH 1/5] llvm_33: backport patch from LLVM 3.5

This patch was backported from LLVM 3.5 by the Julia project.
---
 pkgs/development/compilers/llvm/3.3/llvm.nix | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/pkgs/development/compilers/llvm/3.3/llvm.nix b/pkgs/development/compilers/llvm/3.3/llvm.nix
index d0f8fcb3bf8f..8dca8b43bc2c 100644
--- a/pkgs/development/compilers/llvm/3.3/llvm.nix
+++ b/pkgs/development/compilers/llvm/3.3/llvm.nix
@@ -12,6 +12,11 @@ in stdenv.mkDerivation rec {
   patches = [
     ./more-memory-for-bugpoint.patch # The default rlimits in 3.3 are too low for shared libraries.
     ./no-rule-aarch64.patch          # http://llvm.org/bugs/show_bug.cgi?id=16625
+    # Patch needed for Julia, backports fixes from LLVM 3.5
+    (fetchurl {
+      url = "https://raw.githubusercontent.com/JuliaLang/julia/3bdda3750efc4ebf8ce7eda8a0888ffef3851605/deps/llvm-3.3.patch";
+      sha256 = "0j6chyx4k8zr1qha5dks8lqlcraqrj4q1hwnk2kj3qi6cajsd8k3";
+    })
   ];
 
   buildInputs = [ perl groff cmake python libffi ];

From 1daa0b39f658bce468c16e8438c7b06649aeb6ea Mon Sep 17 00:00:00 2001
From: Thomas Tuegel <ttuegel@gmail.com>
Date: Sat, 19 Sep 2015 08:15:33 -0500
Subject: [PATCH 2/5] julia03: use system LLVM

It should be safe to use the Nixpkgs LLVM again, now that the approriate
patches have been backported. Hopefully, this will also fix the i686
build.
---
 pkgs/development/compilers/julia/0.3.nix | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/pkgs/development/compilers/julia/0.3.nix b/pkgs/development/compilers/julia/0.3.nix
index 70ba2b6fd061..2e412590be5f 100644
--- a/pkgs/development/compilers/julia/0.3.nix
+++ b/pkgs/development/compilers/julia/0.3.nix
@@ -45,7 +45,7 @@ stdenv.mkDerivation rec {
         md5 = "cb61be3be7254eae39684612c524740d";
       };
 
-    in [ dsfmt_src llvm.src ];
+    in [ dsfmt_src ];
 
   prePatch = ''
     copy_kill_hash(){
@@ -70,22 +70,18 @@ stdenv.mkDerivation rec {
     sed -e "s@/sbin/ldconfig@true@" -i src/ccall.*
   '';
 
-  buildInputs =
-    [ libunwind readline utf8proc zlib
-      double_conversion fftw fftwSinglePrec glpk gmp mpfr pcre
-      openblas arpack suitesparse
-    ];
+  buildInputs = [
+    arpack double_conversion fftw fftwSinglePrec glpk gmp libunwind
+    llvm mpfr pcre openblas readline suitesparse utf8proc zlib
+  ];
 
-  nativeBuildInputs = [ gfortran git m4 patchelf perl which python2 ];
+  nativeBuildInputs = [ gfortran git m4 patchelf perl python2 which ];
 
   makeFlags =
     let
       arch = head (splitString "-" stdenv.system);
-      march =
-        { "x86_64-linux" = "x86-64";
-          "x86_64-darwin" = "x86-64";
-          "i686-linux" = "i686";
-        }."${stdenv.system}" or (throw "unsupported system: ${stdenv.system}");
+      march = { "x86_64" = "x86-64"; "i686" = "i686"; }."${arch}"
+              or (throw "unsupported architecture: ${arch}");
     in [
       "ARCH=${arch}"
       "MARCH=${march}"
@@ -108,6 +104,7 @@ stdenv.mkDerivation rec {
       "USE_SYSTEM_GMP=1"
       "USE_SYSTEM_GRISU=1"
       "USE_SYSTEM_LIBUNWIND=1"
+      "USE_SYSTEM_LLVM=1"
       "USE_SYSTEM_MPFR=1"
       "USE_SYSTEM_PATCHELF=1"
       "USE_SYSTEM_PCRE=1"

From 51bbf7f2a30f616e4c0511390ca5aed6c95c9fba Mon Sep 17 00:00:00 2001
From: Thomas Tuegel <ttuegel@gmail.com>
Date: Sat, 19 Sep 2015 08:43:07 -0500
Subject: [PATCH 3/5] julia03: re-enable tests

---
 pkgs/development/compilers/julia/0.3.nix | 1 +
 1 file changed, 1 insertion(+)

diff --git a/pkgs/development/compilers/julia/0.3.nix b/pkgs/development/compilers/julia/0.3.nix
index 2e412590be5f..608061aceec3 100644
--- a/pkgs/development/compilers/julia/0.3.nix
+++ b/pkgs/development/compilers/julia/0.3.nix
@@ -140,6 +140,7 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
 
+  doCheck = true;
   checkTarget = "testall";
 
   meta = {

From 32b9ac511756a661a2aedd2620ac21296ea8df3e Mon Sep 17 00:00:00 2001
From: Thomas Tuegel <ttuegel@gmail.com>
Date: Sat, 19 Sep 2015 09:28:22 -0500
Subject: [PATCH 4/5] julia03: re-enable tests

---
 pkgs/development/compilers/julia/0.3.nix | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pkgs/development/compilers/julia/0.3.nix b/pkgs/development/compilers/julia/0.3.nix
index 608061aceec3..c4af1b3a7f05 100644
--- a/pkgs/development/compilers/julia/0.3.nix
+++ b/pkgs/development/compilers/julia/0.3.nix
@@ -140,7 +140,8 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
 
-  doCheck = true;
+  # Test fail on i686 (julia version 0.3.10)
+  doCheck = !stdenv.isi686;
   checkTarget = "testall";
 
   meta = {

From 87e5b5c3ef8c6ae1a716008cb4c10609b2c3c1ff Mon Sep 17 00:00:00 2001
From: Thomas Tuegel <ttuegel@gmail.com>
Date: Sat, 19 Sep 2015 09:38:37 -0500
Subject: [PATCH 5/5] julia03: add i686-linux to platforms

---
 pkgs/development/compilers/julia/0.3.nix | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pkgs/development/compilers/julia/0.3.nix b/pkgs/development/compilers/julia/0.3.nix
index c4af1b3a7f05..710ddec9c105 100644
--- a/pkgs/development/compilers/julia/0.3.nix
+++ b/pkgs/development/compilers/julia/0.3.nix
@@ -149,6 +149,6 @@ stdenv.mkDerivation rec {
     homepage = "http://julialang.org/";
     license = stdenv.lib.licenses.mit;
     maintainers = with stdenv.lib.maintainers; [ raskin ttuegel ];
-    platforms = [ "x86_64-linux" "x86_64-darwin" ];
+    platforms = [ "i686-linux" "x86_64-linux" "x86_64-darwin" ];
   };
 }