lol
1{stdenv, fetchurl, perl, ncurses, gmp, libiconv}:
2
3stdenv.mkDerivation rec {
4 version = "7.0.4";
5
6 name = "ghc-${version}-binary";
7
8 src =
9 if stdenv.system == "i686-linux" then
10 fetchurl {
11 url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-i386-unknown-linux.tar.bz2";
12 sha256 = "0mfnihiyjl06f5w1yrjp36sw9g67g2ymg5sdl0g23h1pab99jx63";
13 }
14 else if stdenv.system == "x86_64-linux" then
15 fetchurl {
16 url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-unknown-linux.tar.bz2";
17 sha256 = "0mc4rhqcxz427wq4zgffmnn0d2yjqvy6af4x9mha283p1gdj5q99";
18 }
19 else if stdenv.system == "i686-darwin" then
20 fetchurl {
21 url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-i386-apple-darwin.tar.bz2";
22 sha256 = "0qj45hslrrr8zfks8m1jcb3awwx9rh35ndnpfmb0gwb6j7azq5n3";
23 }
24 else if stdenv.system == "x86_64-darwin" then
25 fetchurl {
26 url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-apple-darwin.tar.bz2";
27 sha256 = "1m2ml88p1swf4dnv2vq8hz4drcp46n3ahpfi05wh01ajkf8hnn3l";
28 }
29 else throw "cannot bootstrap GHC on this platform";
30
31 buildInputs = [perl];
32
33 postUnpack =
34 # GHC has dtrace probes, which causes ld to try to open /usr/lib/libdtrace.dylib
35 # during linking
36 stdenv.lib.optionalString stdenv.isDarwin ''
37 export NIX_LDFLAGS+=" -no_dtrace_dof"
38 '' +
39
40 # Strip is harmful, see also below. It's important that this happens
41 # first. The GHC Cabal build system makes use of strip by default and
42 # has hardcoded paths to /usr/bin/strip in many places. We replace
43 # those below, making them point to our dummy script.
44 ''
45 mkdir "$TMP/bin"
46 for i in strip; do
47 echo '#! ${stdenv.shell}' > "$TMP/bin/$i"
48 chmod +x "$TMP/bin/$i"
49 done
50 PATH="$TMP/bin:$PATH"
51 '' +
52 # We have to patch the GMP paths for the integer-gmp package.
53 ''
54 find . -name integer-gmp.buildinfo \
55 -exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${gmp}/lib@" {} \;
56 '' + stdenv.lib.optionalString stdenv.isDarwin ''
57 find . -name base.buildinfo \
58 -exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${libiconv}/lib@" {} \;
59 '' +
60 # On Linux, use patchelf to modify the executables so that they can
61 # find editline/gmp.
62 stdenv.lib.optionalString stdenv.isLinux ''
63 find . -type f -perm -0100 \
64 -exec patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
65 --set-rpath "${ncurses}/lib:${gmp}/lib" {} \;
66 sed -i "s|/usr/bin/perl|perl\x00 |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
67 sed -i "s|/usr/bin/gcc|gcc\x00 |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
68 for prog in ld ar gcc strip ranlib; do
69 find . -name "setup-config" -exec sed -i "s@/usr/bin/$prog@$(type -p $prog)@g" {} \;
70 done
71 '' + stdenv.lib.optionalString stdenv.isDarwin ''
72 # not enough room in the object files for the full path to libiconv :(
73 fix () {
74 install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $1
75 }
76
77 ln -s ${libiconv}/lib/libiconv.dylib ghc-7.0.4/utils/ghc-pwd/dist/build/tmp
78 ln -s ${libiconv}/lib/libiconv.dylib ghc-7.0.4/utils/hpc/dist/build/tmp
79 ln -s ${libiconv}/lib/libiconv.dylib ghc-7.0.4/ghc/stage2/build/tmp
80
81 for file in ghc-cabal ghc-pwd ghc-stage2 ghc-pkg haddock hsc2hs hpc; do
82 fix $(find . -type f -name $file)
83 done
84
85 for file in $(find . -name setup-config); do
86 substituteInPlace $file --replace /usr/bin/ranlib "$(type -P ranlib)"
87 done
88 '';
89
90 configurePhase = ''
91 ./configure --prefix=$out \
92 --with-gmp-libraries=${gmp}/lib --with-gmp-includes=${gmp}/include \
93 ${stdenv.lib.optionalString stdenv.isDarwin "--with-gcc=${./gcc-clang-wrapper.sh}"}
94 '';
95
96 # Stripping combined with patchelf breaks the executables (they die
97 # with a segfault or the kernel even refuses the execve). (NIXPKGS-85)
98 dontStrip = true;
99
100 # No building is necessary, but calling make without flags ironically
101 # calls install-strip ...
102 buildPhase = "true";
103
104 postInstall =
105 ''
106 # Sanity check, can ghc create executables?
107 cd $TMP
108 mkdir test-ghc; cd test-ghc
109 cat > main.hs << EOF
110 module Main where
111 main = putStrLn "yes"
112 EOF
113 $out/bin/ghc --make main.hs
114 echo compilation ok
115 [ $(./main) == "yes" ]
116 '';
117
118 meta.license = stdenv.lib.licenses.bsd3;
119 meta.platforms = ["x86_64-linux" "i686-linux" "x86_64-darwin"];
120}