2017-09-10 19:36:48 +00:00
|
|
|
{ stdenv, targetPackages
|
|
|
|
, buildPlatform, hostPlatform, targetPlatform
|
2017-01-15 22:31:52 +00:00
|
|
|
, selfPkgs, cross ? null
|
2017-01-24 23:00:54 +00:00
|
|
|
|
2017-09-10 19:36:48 +00:00
|
|
|
# build-tools
|
|
|
|
, bootPkgs, alex, happy
|
|
|
|
, autoconf, automake, coreutils, fetchgit, perl, python3
|
|
|
|
|
|
|
|
, libiconv ? null, ncurses
|
|
|
|
|
|
|
|
, # If enabled, GHC will be built with the GPL-free but slower integer-simple
|
2017-01-24 23:00:54 +00:00
|
|
|
# library instead of the faster but GPLed integer-gmp library.
|
2017-09-10 19:36:48 +00:00
|
|
|
enableIntegerSimple ? false, gmp ? null
|
|
|
|
|
2017-12-09 10:52:13 +00:00
|
|
|
, version ? "8.5.20171209"
|
2015-12-16 18:18:29 +00:00
|
|
|
}:
|
2015-01-16 18:31:34 +00:00
|
|
|
|
2017-09-10 19:36:48 +00:00
|
|
|
assert !enableIntegerSimple -> gmp != null;
|
|
|
|
|
2016-02-21 18:15:04 +00:00
|
|
|
let
|
|
|
|
inherit (bootPkgs) ghc;
|
|
|
|
|
2017-12-09 10:52:13 +00:00
|
|
|
rev = "4335c07ca7e64624819b22644d7591853826bd75";
|
2016-11-15 21:59:09 +00:00
|
|
|
|
2017-09-10 19:36:48 +00:00
|
|
|
# TODO(@Ericson2314) Make unconditional
|
|
|
|
targetPrefix = stdenv.lib.optionalString
|
|
|
|
(targetPlatform != hostPlatform)
|
|
|
|
"${targetPlatform.config}-";
|
|
|
|
|
|
|
|
commonBuildInputs = [ ghc perl autoconf automake happy alex python3 ];
|
2016-11-15 21:59:09 +00:00
|
|
|
commonPreConfigure = ''
|
2017-01-07 03:10:29 +00:00
|
|
|
echo ${version} >VERSION
|
|
|
|
echo ${rev} >GIT_COMMIT_ID
|
|
|
|
./boot
|
2016-11-15 21:59:09 +00:00
|
|
|
sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
|
|
|
|
'' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
|
|
|
|
export NIX_LDFLAGS="$NIX_LDFLAGS -rpath $out/lib/ghc-${version}"
|
|
|
|
'' + stdenv.lib.optionalString stdenv.isDarwin ''
|
|
|
|
export NIX_LDFLAGS+=" -no_dtrace_dof"
|
2017-01-24 23:00:54 +00:00
|
|
|
'' + stdenv.lib.optionalString enableIntegerSimple ''
|
|
|
|
echo "INTEGER_LIBRARY=integer-simple" > mk/build.mk
|
2016-11-15 21:59:09 +00:00
|
|
|
'';
|
2017-09-10 19:36:48 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation (rec {
|
2017-01-07 03:10:29 +00:00
|
|
|
inherit version rev;
|
2017-05-09 15:59:28 +00:00
|
|
|
name = "ghc-${version}";
|
2011-08-08 19:47:31 +00:00
|
|
|
|
2015-02-12 20:18:06 +00:00
|
|
|
src = fetchgit {
|
|
|
|
url = "git://git.haskell.org/ghc.git";
|
|
|
|
inherit rev;
|
2017-12-09 10:52:13 +00:00
|
|
|
sha256 = "19csad94sk0bw2nj97ppmnwh4c193jg0jmg5w2sx9rqm9ih4yg85";
|
2010-09-28 13:48:22 +00:00
|
|
|
};
|
|
|
|
|
2016-12-24 17:37:58 +00:00
|
|
|
postPatch = "patchShebangs .";
|
|
|
|
|
2017-01-07 03:10:29 +00:00
|
|
|
preConfigure = commonPreConfigure;
|
2015-02-03 23:34:08 +00:00
|
|
|
|
2016-11-15 21:59:09 +00:00
|
|
|
buildInputs = commonBuildInputs;
|
2010-09-28 13:48:22 +00:00
|
|
|
|
2015-12-16 18:18:29 +00:00
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
2014-12-18 16:31:37 +00:00
|
|
|
configureFlags = [
|
2016-11-15 23:30:26 +00:00
|
|
|
"CC=${stdenv.cc}/bin/cc"
|
2016-02-01 17:16:50 +00:00
|
|
|
"--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
|
2017-06-17 19:13:01 +00:00
|
|
|
"--datadir=$doc/share/doc/ghc"
|
2017-01-24 23:00:54 +00:00
|
|
|
] ++ stdenv.lib.optional (! enableIntegerSimple) [
|
|
|
|
"--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
|
2015-12-16 18:18:29 +00:00
|
|
|
] ++ stdenv.lib.optional stdenv.isDarwin [
|
|
|
|
"--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
|
2014-12-18 16:31:37 +00:00
|
|
|
];
|
|
|
|
|
2010-09-28 13:48:22 +00:00
|
|
|
# required, because otherwise all symbols from HSffi.o are stripped, and
|
|
|
|
# that in turn causes GHCi to abort
|
2017-09-10 19:36:48 +00:00
|
|
|
stripDebugFlags = [ "-S" ] ++ stdenv.lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols";
|
2010-09-28 13:48:22 +00:00
|
|
|
|
2016-12-24 17:37:04 +00:00
|
|
|
checkTarget = "test";
|
|
|
|
|
2015-12-16 18:18:29 +00:00
|
|
|
postInstall = ''
|
2017-09-10 19:36:48 +00:00
|
|
|
paxmark m $out/lib/${name}/bin/${if targetPlatform != hostPlatform then "ghc" else "{ghc,haddock}"}
|
2016-12-15 00:25:58 +00:00
|
|
|
|
2015-12-16 18:18:29 +00:00
|
|
|
# Install the bash completion file.
|
2017-09-10 19:36:48 +00:00
|
|
|
install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc
|
2015-12-16 18:18:29 +00:00
|
|
|
|
|
|
|
# Patch scripts to include "readelf" and "cat" in $PATH.
|
|
|
|
for i in "$out/bin/"*; do
|
|
|
|
test ! -h $i || continue
|
|
|
|
egrep --quiet '^#!' <(head -n 1 $i) || continue
|
2017-10-18 18:05:39 +00:00
|
|
|
sed -i -e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ targetPackages.stdenv.cc.bintools coreutils ]}"' $i
|
2015-12-16 18:18:29 +00:00
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2017-06-22 18:52:35 +00:00
|
|
|
outputs = [ "out" "doc" ];
|
|
|
|
|
2016-02-21 18:15:04 +00:00
|
|
|
passthru = {
|
2017-09-10 19:36:48 +00:00
|
|
|
inherit bootPkgs targetPrefix;
|
2017-01-15 22:31:52 +00:00
|
|
|
} // stdenv.lib.optionalAttrs (targetPlatform != buildPlatform) {
|
2016-11-18 15:44:53 +00:00
|
|
|
crossCompiler = selfPkgs.ghc.override {
|
2017-01-15 22:31:52 +00:00
|
|
|
cross = targetPlatform;
|
2016-11-18 15:44:53 +00:00
|
|
|
bootPkgs = selfPkgs;
|
|
|
|
};
|
2016-02-21 18:15:04 +00:00
|
|
|
};
|
|
|
|
|
2010-09-28 13:48:22 +00:00
|
|
|
meta = {
|
2017-08-01 20:03:30 +00:00
|
|
|
homepage = http://haskell.org/ghc;
|
2010-09-28 13:48:22 +00:00
|
|
|
description = "The Glasgow Haskell Compiler";
|
2016-05-16 20:30:20 +00:00
|
|
|
maintainers = with stdenv.lib.maintainers; [ marcweber andres peti ];
|
2013-03-23 12:05:43 +00:00
|
|
|
inherit (ghc.meta) license platforms;
|
2010-09-28 13:48:22 +00:00
|
|
|
};
|
|
|
|
|
2016-11-15 21:59:09 +00:00
|
|
|
} // stdenv.lib.optionalAttrs (cross != null) {
|
|
|
|
name = "${cross.config}-ghc-${version}";
|
|
|
|
|
|
|
|
preConfigure = commonPreConfigure + ''
|
2017-01-23 23:37:15 +00:00
|
|
|
sed 's|#BuildFlavour = quick-cross|BuildFlavour = perf-cross|' mk/build.mk.sample > mk/build.mk
|
2016-11-15 21:59:09 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
configureFlags = [
|
2017-05-31 00:17:10 +00:00
|
|
|
"CC=${stdenv.cc}/bin/${cross.config}-cc"
|
2017-09-10 19:36:48 +00:00
|
|
|
"LD=${stdenv.cc.bintools}/bin/${cross.config}-ld"
|
|
|
|
"AR=${stdenv.cc.bintools}/bin/${cross.config}-ar"
|
|
|
|
"NM=${stdenv.cc.bintools}/bin/${cross.config}-nm"
|
|
|
|
"RANLIB=${stdenv.cc.bintools}/bin/${cross.config}-ranlib"
|
2016-11-15 21:59:09 +00:00
|
|
|
"--target=${cross.config}"
|
2016-11-18 15:44:53 +00:00
|
|
|
"--enable-bootstrap-with-devel-snapshot"
|
2017-02-25 22:45:40 +00:00
|
|
|
] ++
|
|
|
|
# fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
|
2017-09-10 19:36:48 +00:00
|
|
|
stdenv.lib.optional (cross.config or null == "aarch64-apple-darwin14") "--disable-large-address-space";
|
2016-11-15 21:59:09 +00:00
|
|
|
|
2017-05-31 00:17:10 +00:00
|
|
|
buildInputs = commonBuildInputs;
|
2016-11-15 21:59:09 +00:00
|
|
|
|
2017-04-26 04:06:11 +00:00
|
|
|
configurePlatforms = [];
|
2016-11-18 15:44:53 +00:00
|
|
|
|
|
|
|
passthru = {
|
|
|
|
inherit bootPkgs cross;
|
2017-05-31 00:17:10 +00:00
|
|
|
cc = "${stdenv.cc}/bin/${cross.config}-cc";
|
|
|
|
ld = "${stdenv.cc}/bin/${cross.config}-ld";
|
2016-11-18 15:44:53 +00:00
|
|
|
};
|
2016-11-15 21:59:09 +00:00
|
|
|
})
|