@@ -1,7 +1,14 @@
1−{ stdenv, fetchurl, ghc, pkgconfig, glibcLocales, coreutils, gnugrep, gnused
2−, jailbreak-cabal, hscolour, cpphs, nodejs, lib, removeReferencesTo
1+{ stdenv, buildPackages, ghc
2+, jailbreak-cabal, hscolour, cpphs, nodejs
3+, buildPlatform, hostPlatform
34}:
4−let isCross = (ghc.cross or null) != null; in
5+
6+let
7+ isCross = buildPlatform != hostPlatform;
8+ inherit (buildPackages)
9+ fetchurl removeReferencesTo
10+ pkgconfig binutils coreutils gnugrep gnused glibcLocales;
11+in
512
613{ pname
714, dontStrip ? (ghc.isGhcjs or false)
@@ -20,8 +27,8 @@ let isCross = (ghc.cross or null) != null; in
2027, enableLibraryProfiling ? false
2128, enableExecutableProfiling ? false
2229# TODO enable shared libs for cross-compiling
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))
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)
2532, enableSplitObjs ? null # OBSOLETE, use enableDeadCodeElimination
2633, enableDeadCodeElimination ? (!stdenv.isDarwin) # TODO: use -dead_strip for darwin
2734, enableStaticLibraries ? true
@@ -53,7 +60,7 @@ let isCross = (ghc.cross or null) != null; in
5360, shellHook ? ""
5461, coreSetup ? false # Use only core packages to build Setup.hs.
5562, useCpphs ? false
56−, hardeningDisable ? lib.optional (ghc.isHaLVM or false) "all"
63+, hardeningDisable ? stdenv.lib.optional (ghc.isHaLVM or false) "all"
5764, enableSeparateDataOutput ? false
5865, enableSeparateDocOutput ? doHaddock
5966} @ args:
@@ -102,11 +109,12 @@ let
102109 enableParallelBuilding = (versionOlder "7.8" ghc.version && !hasActiveLibrary) || versionOlder "8.0.1" ghc.version;
103110
104111 crossCabalFlags = [
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}"
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"
109116 "--with-hsc2hs=${nativeGhc}/bin/hsc2hs"
117+ "--with-strip=${binutils}/bin/${ghc.prefix}strip"
110118 ] ++ (if isHaLVM then [] else ["--hsc2hs-options=--cross-compile"]);
111119
112120 crossCabalFlagsString =
@@ -135,7 +143,7 @@ let
135143 ] ++ optionals isGhcjs [
136144 "--ghcjs"
137145 ] ++ optionals isCross ([
138− "--configure-option=--host=${ghc.cross.config}"
146+ "--configure-option=--host=${hostPlatform.config}"
139147 ] ++ crossCabalFlags);
140148
141149 setupCompileFlags = [
@@ -170,8 +178,7 @@ let
170178 setupBuilder = if isCross then "${nativeGhc}/bin/ghc" else ghcCommand;
171179 setupCommand = "./Setup";
172180 ghcCommand' = if isGhcjs then "ghcjs" else "ghc";
173− crossPrefix = if (ghc.cross or null) != null then "${ghc.cross.config}-" else "";
174− ghcCommand = "${crossPrefix}${ghcCommand'}";
181+ ghcCommand = "${ghc.prefix}${ghcCommand'}";
175182 ghcCommandCaps= toUpper ghcCommand';
176183
177184in
@@ -268,6 +275,8 @@ stdenv.mkDerivation ({
268275 runHook postCompileBuildDriver
269276 '';
270277
278+ inherit configureFlags;
279+
271280 configurePhase = ''
272281 runHook preConfigure
273282
@@ -393,7 +402,6 @@ stdenv.mkDerivation ({
393402// optionalAttrs (postCompileBuildDriver != "") { inherit postCompileBuildDriver; }
394403// optionalAttrs (preUnpack != "") { inherit preUnpack; }
395404// optionalAttrs (postUnpack != "") { inherit postUnpack; }
396−// optionalAttrs (configureFlags != []) { inherit configureFlags; }
397405// optionalAttrs (patches != []) { inherit patches; }
398406// optionalAttrs (patchPhase != "") { inherit patchPhase; }
399407// optionalAttrs (preConfigure != "") { inherit preConfigure; }
@@ -412,5 +420,5 @@ stdenv.mkDerivation ({
412420// optionalAttrs (postFixup != "") { inherit postFixup; }
413421// optionalAttrs (dontStrip) { inherit dontStrip; }
414422// optionalAttrs (hardeningDisable != []) { inherit hardeningDisable; }
415−// optionalAttrs (stdenv.isLinux) { LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive"; }
423+// optionalAttrs (buildPlatform.isLinux){ LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive"; }
416424)