@@ -131,109 +131,23 @@ let
131131
132132 targetCC = builtins.head toolsForTarget;
133133
134−in let configured-src = stdenv.mkDerivation (rec {
135−
136− version = ghc-version;
137−
138− patches = ghc-patches;
139−
140− name = "${targetPrefix}ghc-${ghc-version}-configured-src";
141−
142− # Make sure we never relax`$PATH` and hooks support for compatability.
143− strictDeps = true;
144−
145− nativeBuildInputs = [
146− perl autoconf automake m4 python3 sphinx
147− ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
148− ] ++ stdenv.lib.optional (patches != []) autoreconfHook;
149−
150− # For building runtime libs
151− depsBuildTarget = toolsForTarget;
152−
153− buildInputs = [ perl bash ] ++ (libDeps hostPlatform);
154−
155− propagatedBuildInputs = [ targetPackages.stdenv.cc ]
156− ++ stdenv.lib.optional useLLVM llvmPackages.llvm;
157−
158− depsTargetTarget = map stdenv.lib.getDev (libDeps targetPlatform);
159− depsTargetTargetPropagated = map (stdenv.lib.getOutput "out") (libDeps targetPlatform);
160−
161− postPatch = "patchShebangs .";
162−
163− src = fetchurl { inherit (src-spec) url sha256; };
164−
165− # GHC is a bit confused on its cross terminology.
166− preConfigure = ''
167− for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
168− export "''${env#TARGET_}=''${!env}"
169− done
170− # GHC is a bit confused on its cross terminology, as these would normally be
171− # the *host* tools.
172− export CC="${targetCC}/bin/${targetCC.targetPrefix}cc"
173− export CXX="${targetCC}/bin/${targetCC.targetPrefix}cxx"
174− # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
175− export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${stdenv.lib.optionalString targetPlatform.isAarch32 ".gold"}"
176− export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as"
177− export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar"
178− export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm"
179− export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib"
180− export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf"
181− export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip"
182−
183− echo -n "${buildMK}" > mk/build.mk
184− sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
185− '' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
186− export NIX_LDFLAGS+=" -rpath $out/lib/${targetPrefix}ghc-${version}"
187− '' + stdenv.lib.optionalString stdenv.isDarwin ''
188− export NIX_LDFLAGS+=" -no_dtrace_dof"
189− '' + stdenv.lib.optionalString targetPlatform.useAndroidPrebuilt ''
190− 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
191− '' + stdenv.lib.optionalString targetPlatform.isMusl ''
192− echo "patching llvm-targets for musl targets..."
193− echo "Cloning these existing '*-linux-gnu*' targets:"
194− grep linux-gnu llvm-targets | sed 's/^/ /'
195− echo "(go go gadget sed)"
196− sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets
197− echo "llvm-targets now contains these '*-linux-musl*' targets:"
198− grep linux-musl llvm-targets | sed 's/^/ /'
199−
200− echo "And now patching to preserve '-musleabi' as done with '-gnueabi'"
201− # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen)
202− for x in configure aclocal.m4; do
203− substituteInPlace $x \
204− --replace '*-android*|*-gnueabi*)' \
205− '*-android*|*-gnueabi*|*-musleabi*)'
206− done
207− '';
208−
209− configurePlatforms = [ "build" "host" "target" ];
210− # `--with` flags for libraries needed for RTS linker
211− configureFlags = [
212− "--datadir=$doc/share/doc/ghc"
213− "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
214− ] ++ stdenv.lib.optionals (targetLibffi != null) ["--with-system-libffi" "--with-ffi-includes=${targetLibffi.dev}/include" "--with-ffi-libraries=${targetLibffi.out}/lib"
215− ] ++ stdenv.lib.optional (!enableIntegerSimple) [
216− "--with-gmp-includes=${targetGmp.dev}/include" "--with-gmp-libraries=${targetGmp.out}/lib"
217− ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
218− "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
219− ] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [
220− "--enable-bootstrap-with-devel-snapshot"
221− ] ++ stdenv.lib.optionals (disableLargeAddressSpace) [
222− "--disable-large-address-space"
223− ] ++ stdenv.lib.optionals (targetPlatform.isAarch32) [
224− "CFLAGS=-fuse-ld=gold"
225− "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
226− "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
227− ] ;
228−
229− outputs = [ "out" ];
230− phases = [ "unpackPhase" "patchPhase" ]
231− ++ stdenv.lib.optional (ghc-patches != []) "autoreconfPhase"
232− ++ [ "configurePhase" "installPhase" ];
233− installPhase = "cp -r . $out";
234− });
235−
236− drv =stdenv.mkDerivation (rec {
134+ configured-src = import ./configured-src {
135+ stdenv fetchurl
136+ ghc-version ghc-patches src-spec
137+ targetPrefix
138+ targetPlatform hostPlatform
139+ targetPackages
140+ perl autoconf automake m4 python3 sphinx ghc bootPkgs
141+ autoreconfHook toolsForTarget bash
142+ libDeps
143+ useLLVM llvmPackages
144+ targetCC
145+ enableIntegerSimple targetGmp
146+ ncurses targetLibffi libiconv
147+ disableLargeAddressSpace
148+ };
149+in
150+stdenv.mkDerivation (rec {
237151 version = ghc-version;
238152 name = "${targetPrefix}ghc-${version}";
239153
@@ -368,15 +282,15 @@ in let configured-src = stdenv.mkDerivation (rec {
368282 if [[ ! -f "$out/bin/${targetPrefix}ghc-pkg" ]]; then
369283 echo "ERROR: Missing file $out/bin/${targetPrefix}ghc-pkg"
370284 exit 0
371− fi
285+ fi
372286 if [[ ! -d "$out/lib/${targetPrefix}ghc-${version}" ]]; then
373287 echo "ERROR: Missing directory $out/lib/${targetPrefix}ghc-${version}"
374288 exit 0
375− fi
289+ fi
376290 if (( $(ls -1 "$out/lib/${targetPrefix}ghc-${version}" | wc -l) < 30 )); then
377291 echo "ERROR: Expected more files in $out/lib/${targetPrefix}ghc-${version}"
378292 exit 0
379− fi
293+ fi
380294 '';
381295
382296 passthru = {
@@ -405,6 +319,4 @@ in let configured-src = stdenv.mkDerivation (rec {
405319 dontStrip = true;
406320 dontPatchELF = true;
407321 noAuditTmpdir = true;
408−});
409−
410−in drv
322+});