@@ -1,14 +1,7 @@
1−{ stdenv, buildPackages, ghc
2−, jailbreak-cabal, hscolour, cpphs, nodejs
3−, buildPlatform, hostPlatform
1+{ stdenv, fetchurl, ghc, pkgconfig, glibcLocales, coreutils, gnugrep, gnused
2+, jailbreak-cabal, hscolour, cpphs, nodejs, lib, removeReferencesTo
43}:
5−
6−let
7− isCross = buildPlatform != hostPlatform;
8− inherit (buildPackages)
9− fetchurl removeReferencesTo
10− pkgconfig binutils coreutils gnugrep gnused glibcLocales;
11−in
4+let isCross = (ghc.cross or null) != null; in
125
136{ pname
147, dontStrip ? (ghc.isGhcjs or false)
@@ -27,8 +20,8 @@ in
2720, enableLibraryProfiling ? false
2821, enableExecutableProfiling ? false
2922# TODO enable shared libs for cross-compiling
30−, enableSharedExecutables ? ((ghc.isGhcjs or false) || stdenv.lib.versionOlder "7.7" ghc.version)
31−, enableSharedLibraries ? ((ghc.isGhcjs or false) || stdenv.lib.versionOlder "7.7" ghc.version)
23+, enableSharedExecutables ? !isCross && (((ghc.isGhcjs or false) || stdenv.lib.versionOlder "7.7" ghc.version))
24+, enableSharedLibraries ? !isCross && (((ghc.isGhcjs or false) || stdenv.lib.versionOlder "7.7" ghc.version))
3225, enableSplitObjs ? null # OBSOLETE, use enableDeadCodeElimination
3326, enableDeadCodeElimination ? (!stdenv.isDarwin) # TODO: use -dead_strip for darwin
3427, enableStaticLibraries ? true
@@ -60,7 +53,7 @@ in
6053, shellHook ? ""
6154, coreSetup ? false # Use only core packages to build Setup.hs.
6255, useCpphs ? false
63−, hardeningDisable ? stdenv.lib.optional (ghc.isHaLVM or false) "all"
56+, hardeningDisable ? lib.optional (ghc.isHaLVM or false) "all"
6457, enableSeparateDataOutput ? false
6558, enableSeparateDocOutput ? doHaddock
6659} @ args:
@@ -109,12 +102,11 @@ let
109102 enableParallelBuilding = (versionOlder "7.8" ghc.version && !hasActiveLibrary) || versionOlder "8.0.1" ghc.version;
110103
111104 crossCabalFlags = [
112− "--with-ghc=${ghc.prefix}ghc"
113− "--with-ghc-pkg=${ghc.prefix}ghc-pkg"
114− "--with-gcc=${ghc.prefix}cc"
115− "--with-ld=${ghc.prefix}ld"
105+ "--with-ghc=${ghc.cross.config}-ghc"
106+ "--with-ghc-pkg=${ghc.cross.config}-ghc-pkg"
107+ "--with-gcc=${ghc.cc}"
108+ "--with-ld=${ghc.ld}"
116109 "--with-hsc2hs=${nativeGhc}/bin/hsc2hs"
117− "--with-strip=${binutils}/bin/${ghc.prefix}strip"
118110 ] ++ (if isHaLVM then [] else ["--hsc2hs-options=--cross-compile"]);
119111
120112 crossCabalFlagsString =
@@ -143,7 +135,7 @@ let
143135 ] ++ optionals isGhcjs [
144136 "--ghcjs"
145137 ] ++ optionals isCross ([
146− "--configure-option=--host=${hostPlatform.config}"
138+ "--configure-option=--host=${ghc.cross.config}"
147139 ] ++ crossCabalFlags);
148140
149141 setupCompileFlags = [
@@ -178,7 +170,8 @@ let
178170 setupBuilder = if isCross then "${nativeGhc}/bin/ghc" else ghcCommand;
179171 setupCommand = "./Setup";
180172 ghcCommand' = if isGhcjs then "ghcjs" else "ghc";
181− ghcCommand = "${ghc.prefix}${ghcCommand'}";
173+ crossPrefix = if (ghc.cross or null) != null then "${ghc.cross.config}-" else "";
174+ ghcCommand = "${crossPrefix}${ghcCommand'}";
182175 ghcCommandCaps= toUpper ghcCommand';
183176
184177in
@@ -275,8 +268,6 @@ stdenv.mkDerivation ({
275268 runHook postCompileBuildDriver
276269 '';
277270
278− inherit configureFlags;
279−
280271 configurePhase = ''
281272 runHook preConfigure
282273
@@ -402,6 +393,7 @@ stdenv.mkDerivation ({
402393// optionalAttrs (postCompileBuildDriver != "") { inherit postCompileBuildDriver; }
403394// optionalAttrs (preUnpack != "") { inherit preUnpack; }
404395// optionalAttrs (postUnpack != "") { inherit postUnpack; }
396+// optionalAttrs (configureFlags != []) { inherit configureFlags; }
405397// optionalAttrs (patches != []) { inherit patches; }
406398// optionalAttrs (patchPhase != "") { inherit patchPhase; }
407399// optionalAttrs (preConfigure != "") { inherit preConfigure; }
@@ -420,5 +412,5 @@ stdenv.mkDerivation ({
420412// optionalAttrs (postFixup != "") { inherit postFixup; }
421413// optionalAttrs (dontStrip) { inherit dontStrip; }
422414// optionalAttrs (hardeningDisable != []) { inherit hardeningDisable; }
423−// optionalAttrs (buildPlatform.isLinux){ LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive"; }
415+// optionalAttrs (stdenv.isLinux) { LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive"; }
424416)