on e94de40 help sign in
haskell.nix/compiler/ghc/configured-src.nix
116 lines 5.5 kB history raw
1{ stdenv, fetchurl
2, ghc-version, ghc-patches, src-spec
3, targetPrefix
4, targetPlatform, hostPlatform
5, targetPackages
6, perl, autoconf, automake, m4, python3, sphinx, ghc, bootPkgs
7, autoreconfHook, toolsForTarget, bash
8, libDeps
9, useLLVM, llvmPackages
10, targetCC
11, enableIntegerSimple, targetGmp
12, ncurses, targetLibffi, libiconv
13, disableLargeAddressSpace
14, buildMK
15}:
16stdenv.mkDerivation (rec {
18 version = ghc-version;
19 patches = ghc-patches;
20 name = "${targetPrefix}ghc-${ghc-version}-configured-src";
22 # Make sure we never relax`$PATH` and hooks support for compatability.
23 strictDeps = true;
25 nativeBuildInputs = [
26 perl autoconf automake m4 python3 sphinx
27 ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
28 ] ++ stdenv.lib.optional (patches != []) autoreconfHook;
30 # For building runtime libs
31 depsBuildTarget = toolsForTarget;
33 buildInputs = [ perl bash ] ++ (libDeps hostPlatform);
35 propagatedBuildInputs = [ targetPackages.stdenv.cc ]
36 ++ stdenv.lib.optional useLLVM llvmPackages.llvm;
38 depsTargetTarget = map stdenv.lib.getDev (libDeps targetPlatform);
39 depsTargetTargetPropagated = map (stdenv.lib.getOutput "out") (libDeps targetPlatform);
41 postPatch = "patchShebangs .";
43 src = if src-spec ? file
44 then src-spec.file
45 else fetchurl { inherit (src-spec) url sha256; };
47 # GHC is a bit confused on its cross terminology.
48 preConfigure = ''
49 for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
50 export "''${env#TARGET_}=''${!env}"
51 done
52 # GHC is a bit confused on its cross terminology, as these would normally be
53 # the *host* tools.
54 export CC="${targetCC}/bin/${targetCC.targetPrefix}cc"
55 export CXX="${targetCC}/bin/${targetCC.targetPrefix}cxx"
56 # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
57 export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${stdenv.lib.optionalString targetPlatform.isAarch32 ".gold"}"
58 export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as"
59 export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar"
60 export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm"
61 export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib"
62 export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf"
63 export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip"
65 echo -n "${buildMK}" > mk/build.mk
66 sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
67 '' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
68 export NIX_LDFLAGS+=" -rpath $out/lib/${targetPrefix}ghc-${version}"
69 '' + stdenv.lib.optionalString stdenv.isDarwin ''
70 export NIX_LDFLAGS+=" -no_dtrace_dof"
71 '' + stdenv.lib.optionalString targetPlatform.useAndroidPrebuilt ''
72 sed -i -e '5i ,("armv7a-unknown-linux-androideabi", ("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", "cortex-a8", ""))' llvm-targets
73 '' + stdenv.lib.optionalString targetPlatform.isMusl ''
74 echo "patching llvm-targets for musl targets..."
75 echo "Cloning these existing '*-linux-gnu*' targets:"
76 grep linux-gnu llvm-targets | sed 's/^/ /'
77 echo "(go go gadget sed)"
78 sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets
79 echo "llvm-targets now contains these '*-linux-musl*' targets:"
80 grep linux-musl llvm-targets | sed 's/^/ /'
82 echo "And now patching to preserve '-musleabi' as done with '-gnueabi'"
83 # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen)
84 for x in configure aclocal.m4; do
85 substituteInPlace $x \
86 --replace '*-android*|*-gnueabi*)' \
87 '*-android*|*-gnueabi*|*-musleabi*)'
88 done
89 '';
91 configurePlatforms = [ "build" "host" "target" ];
92 # `--with` flags for libraries needed for RTS linker
93 configureFlags = [
94 "--datadir=$doc/share/doc/ghc"
95 "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
96 ] ++ stdenv.lib.optionals (targetLibffi != null) ["--with-system-libffi" "--with-ffi-includes=${targetLibffi.dev}/include" "--with-ffi-libraries=${targetLibffi.out}/lib"
97 ] ++ stdenv.lib.optional (!enableIntegerSimple) [
98 "--with-gmp-includes=${targetGmp.dev}/include" "--with-gmp-libraries=${targetGmp.out}/lib"
99 ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
100 "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
101 ] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [
102 "--enable-bootstrap-with-devel-snapshot"
103 ] ++ stdenv.lib.optionals (disableLargeAddressSpace) [
104 "--disable-large-address-space"
105 ] ++ stdenv.lib.optionals (targetPlatform.isAarch32) [
106 "CFLAGS=-fuse-ld=gold"
107 "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
108 "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
109 ] ;
111 outputs = [ "out" ];
112 phases = [ "unpackPhase" "patchPhase" ]
113 ++ stdenv.lib.optional (ghc-patches != []) "autoreconfPhase"
114 ++ [ "configurePhase" "installPhase" ];
115 installPhase = "cp -r . $out";
116})