fork
Configure Feed
Select the types of activity you want to include in your feed.
lol
fork
Configure Feed
Select the types of activity you want to include in your feed.
1{ stdenv
2, fetchurl, perl
3, ncurses5, gmp, libiconv
4}:
5
6# Prebuilt only does native
7assert stdenv.targetPlatform == stdenv.hostPlatform;
8
9let
10 libPath = stdenv.lib.makeLibraryPath ([
11 ncurses5 gmp
12 ] ++ stdenv.lib.optional (stdenv.hostPlatform.isDarwin) libiconv);
13
14 libEnvVar = stdenv.lib.optionalString stdenv.hostPlatform.isDarwin "DY"
15 + "LD_LIBRARY_PATH";
16
17in
18
19stdenv.mkDerivation rec {
20 version = "7.8.4";
21
22 name = "ghc-${version}-binary";
23
24 src = fetchurl ({
25 "i686-linux" = {
26 url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-i386-unknown-linux-deb7.tar.bz2";
27 sha256 = "5da2cf45986f33319a92a666f1f0149915334a7b64b41892ab94f4557242b406";
28 };
29 "x86_64-linux" = {
30 url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-unknown-linux-deb7.tar.bz2";
31 sha256 = "20b5731d268613bbf6e977dbb192a3a3b7b78d954c35edbfca4fb36b652e24f7";
32 };
33 "x86_64-darwin" = {
34 url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-apple-darwin.tar.bz2";
35 sha256 = "dfa161c2a136ee16214a49d5902e2377407c8292dbbdbb14fa0fa6b17220cae6";
36 };
37 }.${stdenv.hostPlatform.system}
38 or (throw "cannot bootstrap GHC on this platform"));
39
40 nativeBuildInputs = [ perl ];
41
42 # Cannot patchelf beforehand due to relative RPATHs that anticipate
43 # the final install location/
44 ${libEnvVar} = libPath;
45
46 postUnpack =
47 # GHC has dtrace probes, which causes ld to try to open /usr/lib/libdtrace.dylib
48 # during linking
49 stdenv.lib.optionalString stdenv.isDarwin ''
50 export NIX_LDFLAGS+=" -no_dtrace_dof"
51 # not enough room in the object files for the full path to libiconv :(
52 for exe in $(find . -type f -executable); do
53 isScript $exe && continue
54 ln -fs ${libiconv}/lib/libiconv.dylib $(dirname $exe)/libiconv.dylib
55 install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $exe
56 for file in $(find . -name setup-config); do
57 substituteInPlace $file --replace /usr/bin/ranlib "$(type -P ranlib)"
58 done
59 done
60 '' +
61
62 # Some scripts used during the build need to have their shebangs patched
63 ''
64 patchShebangs ghc-${version}/utils/
65 '' +
66
67 # Strip is harmful, see also below. It's important that this happens
68 # first. The GHC Cabal build system makes use of strip by default and
69 # has hardcoded paths to /usr/bin/strip in many places. We replace
70 # those below, making them point to our dummy script.
71 ''
72 mkdir "$TMP/bin"
73 for i in strip; do
74 echo '#! ${stdenv.shell}' > "$TMP/bin/$i"
75 chmod +x "$TMP/bin/$i"
76 done
77 PATH="$TMP/bin:$PATH"
78 '' +
79 # We have to patch the GMP paths for the integer-gmp package.
80 ''
81 find . -name integer-gmp.buildinfo \
82 -exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${gmp.out}/lib@" {} \;
83 '' + stdenv.lib.optionalString stdenv.isDarwin ''
84 find . -name base.buildinfo \
85 -exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${libiconv}/lib@" {} \;
86 '' +
87 # Rename needed libraries and binaries, fix interpreter
88 stdenv.lib.optionalString stdenv.isLinux ''
89 find . -type f -perm -0100 -exec patchelf \
90 --replace-needed libncurses${stdenv.lib.optionalString stdenv.is64bit "w"}.so.5 libncurses.so \
91 --replace-needed libtinfo.so libtinfo.so.5 \
92 --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" {} \;
93
94 paxmark m ./ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
95
96 sed -i "s|/usr/bin/perl|perl\x00 |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
97 sed -i "s|/usr/bin/gcc|gcc\x00 |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
98 '';
99
100 configurePlatforms = [ ];
101 configureFlags = [
102 "--with-gmp-libraries=${stdenv.lib.getLib gmp}/lib"
103 "--with-gmp-includes=${stdenv.lib.getDev gmp}/include"
104 ] ++ stdenv.lib.optional stdenv.isDarwin "--with-gcc=${./gcc-clang-wrapper.sh}";
105
106 # Stripping combined with patchelf breaks the executables (they die
107 # with a segfault or the kernel even refuses the execve). (NIXPKGS-85)
108 dontStrip = true;
109
110 # No building is necessary, but calling make without flags ironically
111 # calls install-strip ...
112 dontBuild = true;
113
114 # On Linux, use patchelf to modify the executables so that they can
115 # find editline/gmp.
116 preFixup = stdenv.lib.optionalString stdenv.isLinux ''
117 for p in $(find "$out" -type f -executable); do
118 if isELF "$p"; then
119 echo "Patchelfing $p"
120 patchelf --set-rpath "${libPath}:$(patchelf --print-rpath $p)" $p
121 fi
122 done
123 '' + stdenv.lib.optionalString stdenv.isDarwin ''
124 # not enough room in the object files for the full path to libiconv :(
125 for exe in $(find "$out" -type f -executable); do
126 isScript $exe && continue
127 ln -fs ${libiconv}/lib/libiconv.dylib $(dirname $exe)/libiconv.dylib
128 install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib $exe
129 done
130
131 for file in $(find "$out" -name setup-config); do
132 substituteInPlace $file --replace /usr/bin/ranlib "$(type -P ranlib)"
133 done
134 '';
135
136 doInstallCheck = true;
137 installCheckPhase = ''
138 unset ${libEnvVar}
139 # Sanity check, can ghc create executables?
140 cd $TMP
141 mkdir test-ghc; cd test-ghc
142 cat > main.hs << EOF
143 {-# LANGUAGE TemplateHaskell #-}
144 module Main where
145 main = putStrLn \$([|"yes"|])
146 EOF
147 $out/bin/ghc --make main.hs || exit 1
148 echo compilation ok
149 [ $(./main) == "yes" ]
150 '';
151
152 passthru = { targetPrefix = ""; };
153
154 meta.license = stdenv.lib.licenses.bsd3;
155 meta.platforms = ["x86_64-linux" "i686-linux" "x86_64-darwin"];
156}