summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Trofimovich <slyfox@gentoo.org>2017-07-23 12:15:24 +0100
committerSergei Trofimovich <slyfox@gentoo.org>2017-07-23 12:15:34 +0100
commit08a41d2dff99645af6ac5a7bb4774f5f193b6f20 (patch)
tree1ef5b2cb1239a7cbbe9779d776bfd17e6fd01f70 /dev-lang/ghc
parentmedia-gfx/cura: Version bump (diff)
downloadgentoo-08a41d2dff99645af6ac5a7bb4774f5f193b6f20.tar.gz
gentoo-08a41d2dff99645af6ac5a7bb4774f5f193b6f20.tar.bz2
gentoo-08a41d2dff99645af6ac5a7bb4774f5f193b6f20.zip
dev-lang/ghc: bump up to 8.2.1 with x86 and amd64 binaries, no KEYWORDS yet
Package-Manager: Portage-2.3.6, Repoman-2.3.3
Diffstat (limited to 'dev-lang/ghc')
-rw-r--r--dev-lang/ghc/Manifest3
-rw-r--r--dev-lang/ghc/files/ghc-8.2.1_rc1-cgen-constify.patch378
-rw-r--r--dev-lang/ghc/files/ghc-8.2.1_rc1-ghci-cross.patch60
-rw-r--r--dev-lang/ghc/files/ghc-8.2.1_rc1-hp2ps-cross.patch104
-rw-r--r--dev-lang/ghc/files/ghc-8.2.1_rc1-stage2-cross.patch81
-rw-r--r--dev-lang/ghc/files/ghc-8.2.1_rc1-staged-cross.patch43
-rw-r--r--dev-lang/ghc/files/ghc-8.2.1_rc1-unphased-cross.patch30
-rw-r--r--dev-lang/ghc/files/ghc-8.2.1_rc1-win32-cross-1.patch124
-rw-r--r--dev-lang/ghc/files/ghc-8.2.1_rc1-win32-cross-2-hack.patch144
-rw-r--r--dev-lang/ghc/files/ghc-8.2.1_rc2-O2-unreg.patch35
-rw-r--r--dev-lang/ghc/files/ghc-8.2.1_rc3-any-vendor.patch44
-rw-r--r--dev-lang/ghc/files/ghc-8.2.1_rc3-stginit-data.patch27
-rw-r--r--dev-lang/ghc/ghc-8.2.1.ebuild770
13 files changed, 1843 insertions, 0 deletions
diff --git a/dev-lang/ghc/Manifest b/dev-lang/ghc/Manifest
index bbffd0869519..1e20c41e6825 100644
--- a/dev-lang/ghc/Manifest
+++ b/dev-lang/ghc/Manifest
@@ -3,6 +3,7 @@ DIST ghc-7.10.3-src.tar.bz2 13281867 SHA256 3e29a56a74ed6a74d3ee2a6db9389f246283
DIST ghc-7.8.4-ia64-CLOSUREs-regenerated.patch.gz 13268 SHA256 3bdff22e654aee6f942d43edf1bf6cf70404c0152c4fcf89276f10d2c4c5b4b9 SHA512 a655713e06324b56f0041edf70837487e296d28e6f3ee35fe116b9938765aaf3469d25e92645e0940655ed3607dff27d3826fe0f995c84e81b51bfc956816e7d WHIRLPOOL d2cb53bdc6debc0278d554168ea3ab22b0fd8314adac81444637278a92d21b766280fedfb4b7d1b4540c7381c7962dec6b13a799ab2fee4d456fe2875d5c6a5b
DIST ghc-7.8.4-src.tar.bz2 10600755 SHA256 59e3bd514a1820cc1c03e1808282205c0b8518369acae12645ceaf839e6f114b SHA512 079a53891d8ebd8d9b88da96170e60981608a619f8282e4b7948f35244e99bd87277649ac7fcebc227a61a4d21960db8d5e5b9e92f2c69c82d8d68d7fd0a41d3 WHIRLPOOL a9be7641adbd237ed6e0f644c312e655e98be9566097aee5e2c0022e8756d5b2236e42dd86d76c638a001b5ca3f67307e89ec0cd003a92cd112a5d6d3e3d8467
DIST ghc-8.0.2-src.tar.xz 10687760 SHA256 11625453e1d0686b3fa6739988f70ecac836cadc30b9f0c8b49ef9091d6118b1 SHA512 58ea3853cd93b556ecdc4abd0be079b2621171b8491f59004ea4e036a4cba4470aaafe6591b942e0a50a64bdc47540e01fe6900212a1ef7087850112d9bfc5ef WHIRLPOOL 5ffd94f797c32c87d9d818acbb1a41f2c140d6f1da169854aab6eece7a41499b55fc573f9a4fbcccf09dcfc92e460d8c91be5efd8650837e8bfba009b04261b1
+DIST ghc-8.2.1-src.tar.xz 10736016 SHA256 cfc2d496708dacea3ea7dde4c6a4b921b97a7f550ee2acea44cfa535840593f0 SHA512 d9aa2aa7f9414db8f4e51d6c275694b46df515e68331a1a2b6018256333a2c63ebd877b75ee90407ecce5be672ec9afc6bebd62aadbf8ae06b94f1760d1736be WHIRLPOOL ecbdf8e3f330ef329fab21865c5f063763a2320e03063aeb8777f6c4769a86b33504c0548df9c6ce859028277851e6e7482b7c3b62986c6186745f894e7567d9
DIST ghc-bin-7.10.3-alpha.tbz2 183558856 SHA256 780ac45b9b38fb40f08eeb7dae741649ac19dce2271df4bc764cac9be6c5c225 SHA512 08709fe9b4036ab41715c9a637a2a160104e3ab9e0ed9efaaf73428e3cfe19619e50c42b72c60bbbd27be2b9c2ea68f63d72c1a27d4519756e7c0d909f724230 WHIRLPOOL f488ecc945c6100ba86b9ae25eb6a472693556be0205a6c8634f2c235e779fe17b391ced7fec5d89c0c6c3d21583fe9f9b80bf628f3307890becf3f3ffb57a96
DIST ghc-bin-7.10.3-amd64.tbz2 112040431 SHA256 c3c71aff288f7de2785d1c3d54f0fd636144eb3dcb590bdda087b0775203e517 SHA512 e1554b3944edbe8e16537de5a29132dc6a22d780d9a700cdc9b76387b94191164398d6f2242bf8199527802572e2bb02545569d4f0930a0ee0dbfdeb25978558 WHIRLPOOL c2497a9565abf7d37e7928f508f7bf7241dd529aa252da708517f9f067e3d016341b7a73cac34888b99c9b84a8d01fd9e8d76f2b332d53e0d708b078f20ee807
DIST ghc-bin-7.10.3-ia64.tbz2 238680956 SHA256 0da9b5966f0920341f4cf041b814817e1ed06060e8a491481ab19a68153767db SHA512 3694011aec8a6dc37889418b318993cb82f9b46a5175dd837713f396c8f59a19a920e0b0669fe3b4ec37d5bd8837c115264c0a8fc97c5a4ce06a3bdd52fcfce5 WHIRLPOOL 9e059a953607b6477ea7c27bf55175d838c6aa3c57fcf92f13fa6112e9e728037073047be300a5a757395d759d30545546cb46816ec879a2d31c3c0a78868e42
@@ -24,5 +25,7 @@ DIST ghc-bin-8.0.2-ia64.tbz2 250237654 SHA256 f3e74db697900d031c4d405310c3bf3f40
DIST ghc-bin-8.0.2-ppc.tbz2 144760090 SHA256 a261dd97df396296d1a94c311c757040f74284b812634d97734557915d0a44ca SHA512 bc6bf8998064ffc1692c3bb83c44d1787760a3f4a1e6b79dedaefda5fe32b9052049a60f0ddd3c0b0bd24a722fb35e310e0189b3511721ff89d4d02b3d7c14bb WHIRLPOOL b070acb230dccc2faed66002f4384c8c9b17ce58655b5861766582558a66236136b1d02ab6226c7de5c74960c7d2d37c3c0069e38dfa980730043f623df4baa6
DIST ghc-bin-8.0.2-ppc64.tbz2 117432068 SHA256 f2eb278c4d40d92233767d48149ec96a6c6097159ec846a984152c99a559803a SHA512 0eaff0557b68649a15bbeb2019f46fa9e9e7b8a916aa210ab56888090a5b887d20d818e7987177bc6a8e7fde503de560026e6bb55fe39679b8b1ee13c6b7c4f9 WHIRLPOOL 8a4ba955183cb7c94ecb59f62eab18a4ee75aa422d3c6e7172d347112b8445dccf86c718fcd84d3271dcb1f35fee0451fece184840403a02f7ed8bb39785075e
DIST ghc-bin-8.0.2-x86.tbz2 133372061 SHA256 5e56bff6831a9c151d5d6f82db49b21d33bea05f05cdf74fca5adc423d546711 SHA512 020ce0e597e2907550c080f1bb0f863dbf83d5d45df2b3f44173506475bc4ef5423c5a060fdacd87614c3ec398ad94c2dcab9cff0376a54a2c54c2eb1e2f657d WHIRLPOOL 221eae08caff5c2157fae7df901c94d6d1393be3ab0526bb9d8a80d4304af4c4a420fcc2fe62926bf01c3bb02f161f1eb61c7eb47d3c6801cfacb25c1a33e983
+DIST ghc-bin-8.2.1-i686-pc-linux-gnu.tbz2 96157437 SHA256 2a05584fd51a4e9040a3611a0687d814b62b28c5ccd4102b00cf8bbfecadeec9 SHA512 e891e76557fa61853e28829b8bedc4a6abb92954f90cc1ebcf22a13cc137556bbe9262e7398b7e1aedbabeb997916b008bf1561a52f16a569f3d58ea9404f41e WHIRLPOOL c955dbc501b6c3effe08a91ba8b6584e74b224427c56232744c4ddedad72039e2cdb2f3ea1193e6ae2e7fd8a46a947cf7a835399c81f5dd5568c3ce1ad8a5adc
+DIST ghc-bin-8.2.1-x86_64-pc-linux-gnu.tbz2 97490496 SHA256 b67f4f7518a4e2ec5cfc0434dde0365cbfe37c4c7e164e9e8e38199bb6f083cd SHA512 52630a185d0eab56bce0469a612a54109895bfee041ec362ced59a9b35ba3b9c185e86bc7dbf0a5939081d3626baa19fbb3306e36d1857530248a7b9bfc100bb WHIRLPOOL 7998e0c351bd6943bd351909f5e9af0146a3e08f04141fc54807ebea994e4bbcec44247c885865eaa5af8786dfb514eed4fffc35ffaabe81f2d7f8a856ed10d9
DIST hoopl-3.10.2.0.tar.gz 241940 SHA256 6740814c774e51815e8260ae1b4ac8af6ab69f02e112904450f689c4792f1121 SHA512 083baa8a5eb53247aff8d5b9b2144e0f63adb9400934297bbd80bfcec607dd90a34def4301045a60472ef10b0fb90ab84692fc08f786e7f806c28afdab1ef66a WHIRLPOOL 761e7440d2bc32b594ab55ea967c5b075bb638b2fdba6606beaf9c31a90e20031e914146828004b3d11203668210a6994be9fabc3b0ebb428d516b57cae9ee68
DIST transformers-0.4.3.0.tar.gz 28632 SHA256 b3d0a797e815ca50d411e20c02f781efe7751308007d880af7f0b5c4365c3a9d SHA512 c3ec0893ebba4fbd6087c3202e919552c4a9bff3350b5c0589e7ebb18751a515d98b8cac15b0a3252906ea72b5a0eb09b7fe88c8da88b09d6ce4fbf0f50b2780 WHIRLPOOL 89591781926b1d025056dedcfc5de61705056c1e3a8eba72f2e89789e78d2ed4d8909f84d6560dfc66bc0b360f98cb3dc3835f3a05c2325f747498373c88aa4b
diff --git a/dev-lang/ghc/files/ghc-8.2.1_rc1-cgen-constify.patch b/dev-lang/ghc/files/ghc-8.2.1_rc1-cgen-constify.patch
new file mode 100644
index 000000000000..2e1ef932b454
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-8.2.1_rc1-cgen-constify.patch
@@ -0,0 +1,378 @@
+From 7e00046772e053c63ac93630a60b0f396e32a2d7 Mon Sep 17 00:00:00 2001
+From: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Sun, 16 Apr 2017 10:43:38 +0100
+Subject: [PATCH] compiler/cmm/PprC.hs: constify labels in .rodata
+
+Summary:
+Consider one-line module
+ module B (v) where v = "hello"
+in -fvia-C mode it generates code like
+ static char gibberish_str[] = "hello";
+
+It resides in data section (precious resource on ia64!).
+The patch switches genrator to emit:
+ static const char gibberish_str[] = "hello";
+
+Other types if symbols that gained 'const' qualifier are:
+
+- info tables (from haskell and CMM)
+- static reference tables (from haskell and CMM)
+
+Cleanups along the way:
+
+- fixed info tables defined in .cmm to reside in .rodata
+- split out closure declaration into 'IC_' / 'EC_'
+- added label declaration (based on label type) right before
+ each label definition (based on section type) so that C
+ compiler could check if declaration and definition matches
+ at definition site.
+
+Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+Test Plan: ran testsuite on unregisterised x86_64 compiler
+
+Reviewers: simonmar, ezyang, austin, bgamari, erikd
+
+Subscribers: rwbarton, thomie
+
+GHC Trac Issues: #8996
+
+Differential Revision: https://phabricator.haskell.org/D3481
+---
+ compiler/cmm/CLabel.hs | 24 ++++++++++++++
+ compiler/cmm/Cmm.hs | 13 ++++++++
+ compiler/cmm/CmmInfo.hs | 2 +-
+ compiler/cmm/PprC.hs | 62 +++++++++++++++++++++++-------------
+ compiler/llvmGen/LlvmCodeGen/Data.hs | 12 -------
+ includes/Stg.h | 22 +++++++++----
+ includes/rts/storage/InfoTables.h | 2 +-
+ includes/stg/MiscClosures.h | 14 ++++----
+ 8 files changed, 102 insertions(+), 49 deletions(-)
+
+diff --git a/compiler/cmm/CLabel.hs b/compiler/cmm/CLabel.hs
+index 3ba4f7647a..62c8037e9c 100644
+--- a/compiler/cmm/CLabel.hs
++++ b/compiler/cmm/CLabel.hs
+@@ -89,6 +89,8 @@ module CLabel (
+ foreignLabelStdcallInfo,
+ isBytesLabel,
+ isForeignLabel,
++ isSomeRODataLabel,
++ isStaticClosureLabel,
+ mkCCLabel, mkCCSLabel,
+
+ DynamicLinkerLabelInfo(..),
+@@ -575,6 +577,28 @@ isForeignLabel :: CLabel -> Bool
+ isForeignLabel (ForeignLabel _ _ _ _) = True
+ isForeignLabel _lbl = False
+
++-- | Whether label is a static closure label (can come from haskell or cmm)
++isStaticClosureLabel :: CLabel -> Bool
++-- Closure defined in haskell (.hs)
++isStaticClosureLabel (IdLabel _ _ Closure) = True
++-- Closure defined in cmm
++isStaticClosureLabel (CmmLabel _ _ CmmClosure) = True
++isStaticClosureLabel _lbl = False
++
++-- | Whether label is a .rodata label
++isSomeRODataLabel :: CLabel -> Bool
++-- info table defined in haskell (.hs)
++isSomeRODataLabel (IdLabel _ _ ClosureTable) = True
++isSomeRODataLabel (IdLabel _ _ ConInfoTable) = True
++isSomeRODataLabel (IdLabel _ _ InfoTable) = True
++isSomeRODataLabel (IdLabel _ _ LocalInfoTable) = True
++-- static reference tables defined in haskell (.hs)
++isSomeRODataLabel (IdLabel _ _ SRT) = True
++isSomeRODataLabel (SRTLabel _) = True
++-- info table defined in cmm (.cmm)
++isSomeRODataLabel (CmmLabel _ _ CmmInfo) = True
++isSomeRODataLabel _lbl = False
++
+ -- | Get the label size field from a ForeignLabel
+ foreignLabelStdcallInfo :: CLabel -> Maybe Int
+ foreignLabelStdcallInfo (ForeignLabel _ info _ _) = info
+diff --git a/compiler/cmm/Cmm.hs b/compiler/cmm/Cmm.hs
+index d2ee531686..bab20f3fdd 100644
+--- a/compiler/cmm/Cmm.hs
++++ b/compiler/cmm/Cmm.hs
+@@ -9,6 +9,7 @@ module Cmm (
+ CmmBlock,
+ RawCmmDecl, RawCmmGroup,
+ Section(..), SectionType(..), CmmStatics(..), CmmStatic(..),
++ isSecConstant,
+
+ -- ** Blocks containing lists
+ GenBasicBlock(..), blockId,
+@@ -167,6 +168,18 @@ data SectionType
+ | OtherSection String
+ deriving (Show)
+
++-- | Should a data in this section be considered constant
++isSecConstant :: Section -> Bool
++isSecConstant (Section t _) = case t of
++ Text -> True
++ ReadOnlyData -> True
++ RelocatableReadOnlyData -> True
++ ReadOnlyData16 -> True
++ CString -> True
++ Data -> False
++ UninitialisedData -> False
++ (OtherSection _) -> False
++
+ data Section = Section SectionType CLabel
+
+ data CmmStatic
+diff --git a/compiler/cmm/CmmInfo.hs b/compiler/cmm/CmmInfo.hs
+index b5e800a977..35e3a1888d 100644
+--- a/compiler/cmm/CmmInfo.hs
++++ b/compiler/cmm/CmmInfo.hs
+@@ -133,7 +133,7 @@ mkInfoTable dflags proc@(CmmProc infos entry_lbl live blocks)
+ --
+ return (top_decls ++
+ [CmmProc mapEmpty entry_lbl live blocks,
+- mkDataLits (Section Data info_lbl) info_lbl
++ mkRODataLits info_lbl
+ (CmmLabel entry_lbl : rel_std_info ++ rel_extra_bits)])
+
+ --
+diff --git a/compiler/cmm/PprC.hs b/compiler/cmm/PprC.hs
+index 56de94079f..21ed6f6516 100644
+--- a/compiler/cmm/PprC.hs
++++ b/compiler/cmm/PprC.hs
+@@ -83,12 +83,13 @@ pprC tops = vcat $ intersperse blankLine $ map pprTop tops
+ -- top level procs
+ --
+ pprTop :: RawCmmDecl -> SDoc
+-pprTop (CmmProc infos clbl _ graph) =
++pprTop (CmmProc infos clbl _in_live_regs graph) =
+
+ (case mapLookup (g_entry graph) infos of
+ Nothing -> empty
+- Just (Statics info_clbl info_dat) -> pprDataExterns info_dat $$
+- pprWordArray info_clbl info_dat) $$
++ Just (Statics info_clbl info_dat) ->
++ pprDataExterns info_dat $$
++ pprWordArray info_is_in_rodata info_clbl info_dat) $$
+ (vcat [
+ blankLine,
+ extern_decls,
+@@ -99,6 +100,8 @@ pprTop (CmmProc infos clbl _ graph) =
+ rbrace ]
+ )
+ where
++ -- info tables are always in .rodata
++ info_is_in_rodata = True
+ blocks = toBlockListEntryFirst graph
+ (temp_decls, extern_decls) = pprTempAndExternDecls blocks
+
+@@ -107,21 +110,23 @@ pprTop (CmmProc infos clbl _ graph) =
+
+ -- We only handle (a) arrays of word-sized things and (b) strings.
+
+-pprTop (CmmData _section (Statics lbl [CmmString str])) =
++pprTop (CmmData section (Statics lbl [CmmString str])) =
++ pprExternDecl lbl $$
+ hcat [
+- pprLocalness lbl, text "char ", ppr lbl,
++ pprLocalness lbl, pprConstness (isSecConstant section), text "char ", ppr lbl,
+ text "[] = ", pprStringInCStyle str, semi
+ ]
+
+-pprTop (CmmData _section (Statics lbl [CmmUninitialised size])) =
++pprTop (CmmData section (Statics lbl [CmmUninitialised size])) =
++ pprExternDecl lbl $$
+ hcat [
+- pprLocalness lbl, text "char ", ppr lbl,
++ pprLocalness lbl, pprConstness (isSecConstant section), text "char ", ppr lbl,
+ brackets (int size), semi
+ ]
+
+-pprTop (CmmData _section (Statics lbl lits)) =
++pprTop (CmmData section (Statics lbl lits)) =
+ pprDataExterns lits $$
+- pprWordArray lbl lits
++ pprWordArray (isSecConstant section) lbl lits
+
+ -- --------------------------------------------------------------------------
+ -- BasicBlocks are self-contained entities: they always end in a jump.
+@@ -141,10 +146,12 @@ pprBBlock block =
+ -- Info tables. Just arrays of words.
+ -- See codeGen/ClosureInfo, and nativeGen/PprMach
+
+-pprWordArray :: CLabel -> [CmmStatic] -> SDoc
+-pprWordArray lbl ds
++pprWordArray :: Bool -> CLabel -> [CmmStatic] -> SDoc
++pprWordArray is_ro lbl ds
+ = sdocWithDynFlags $ \dflags ->
+- hcat [ pprLocalness lbl, text "StgWord"
++ -- TODO: align closures only
++ pprExternDecl lbl $$
++ hcat [ pprLocalness lbl, pprConstness is_ro, text "StgWord"
+ , space, ppr lbl, text "[]"
+ -- See Note [StgWord alignment]
+ , pprAlignment (wordWidth dflags)
+@@ -180,6 +187,10 @@ pprLocalness :: CLabel -> SDoc
+ pprLocalness lbl | not $ externallyVisibleCLabel lbl = text "static "
+ | otherwise = empty
+
++pprConstness :: Bool -> SDoc
++pprConstness is_ro | is_ro = text "const "
++ | otherwise = empty
++
+ -- --------------------------------------------------------------------------
+ -- Statements.
+ --
+@@ -984,31 +995,38 @@ is_cishCC JavaScriptCallConv = False
+ pprTempAndExternDecls :: [CmmBlock] -> (SDoc{-temps-}, SDoc{-externs-})
+ pprTempAndExternDecls stmts
+ = (pprUFM (getUniqSet temps) (vcat . map pprTempDecl),
+- vcat (map (pprExternDecl False{-ToDo-}) (Map.keys lbls)))
++ vcat (map pprExternDecl (Map.keys lbls)))
+ where (temps, lbls) = runTE (mapM_ te_BB stmts)
+
+ pprDataExterns :: [CmmStatic] -> SDoc
+ pprDataExterns statics
+- = vcat (map (pprExternDecl False{-ToDo-}) (Map.keys lbls))
++ = vcat (map pprExternDecl (Map.keys lbls))
+ where (_, lbls) = runTE (mapM_ te_Static statics)
+
+ pprTempDecl :: LocalReg -> SDoc
+ pprTempDecl l@(LocalReg _ rep)
+ = hcat [ machRepCType rep, space, pprLocalReg l, semi ]
+
+-pprExternDecl :: Bool -> CLabel -> SDoc
+-pprExternDecl _in_srt lbl
++pprExternDecl :: CLabel -> SDoc
++pprExternDecl lbl
+ -- do not print anything for "known external" things
+ | not (needsCDecl lbl) = empty
+ | Just sz <- foreignLabelStdcallInfo lbl = stdcall_decl sz
+ | otherwise =
+- hcat [ visibility, label_type lbl,
+- lparen, ppr lbl, text ");" ]
++ hcat [ visibility, label_type lbl , lparen, ppr lbl, text ");"
++ -- occasionally useful to see label type
++ -- , text "/* ", pprDebugCLabel lbl, text " */"
++ ]
+ where
+- label_type lbl | isBytesLabel lbl = text "B_"
+- | isForeignLabel lbl && isCFunctionLabel lbl = text "FF_"
+- | isCFunctionLabel lbl = text "F_"
+- | otherwise = text "I_"
++ label_type lbl | isBytesLabel lbl = text "B_"
++ | isForeignLabel lbl && isCFunctionLabel lbl
++ = text "FF_"
++ | isCFunctionLabel lbl = text "F_"
++ | isStaticClosureLabel lbl = text "C_"
++ -- generic .rodata labels
++ | isSomeRODataLabel lbl = text "RO_"
++ -- generic .data labels (common case)
++ | otherwise = text "RW_"
+
+ visibility
+ | externallyVisibleCLabel lbl = char 'E'
+diff --git a/compiler/llvmGen/LlvmCodeGen/Data.hs b/compiler/llvmGen/LlvmCodeGen/Data.hs
+index 9bb5a75bda..adb86d312d 100644
+--- a/compiler/llvmGen/LlvmCodeGen/Data.hs
++++ b/compiler/llvmGen/LlvmCodeGen/Data.hs
+@@ -56,18 +56,6 @@ genLlvmData (sec, Statics lbl xs) = do
+
+ return ([globDef], [tyAlias])
+
+--- | Should a data in this section be considered constant
+-isSecConstant :: Section -> Bool
+-isSecConstant (Section t _) = case t of
+- Text -> True
+- ReadOnlyData -> True
+- RelocatableReadOnlyData -> True
+- ReadOnlyData16 -> True
+- CString -> True
+- Data -> False
+- UninitialisedData -> False
+- (OtherSection _) -> False
+-
+ -- | Format the section type part of a Cmm Section
+ llvmSectionType :: Platform -> SectionType -> FastString
+ llvmSectionType p t = case t of
+diff --git a/includes/Stg.h b/includes/Stg.h
+index 619984d8e5..b1b3190307 100644
+--- a/includes/Stg.h
++++ b/includes/Stg.h
+@@ -223,13 +223,23 @@ typedef StgInt I_;
+ typedef StgWord StgWordArray[];
+ typedef StgFunPtr F_;
+
+-#define EB_(X) extern char X[]
+-#define IB_(X) static char X[]
+-#define EI_(X) extern StgWordArray (X) GNU_ATTRIBUTE(aligned (8))
+-#define II_(X) static StgWordArray (X) GNU_ATTRIBUTE(aligned (8))
++/* byte arrays (and strings): */
++#define EB_(X) extern const char X[]
++#define IB_(X) static const char X[]
++/* static (non-heap) closures (requires alignment for pointer tagging): */
++#define EC_(X) extern StgWordArray (X) GNU_ATTRIBUTE(aligned (8))
++#define IC_(X) static StgWordArray (X) GNU_ATTRIBUTE(aligned (8))
++/* writable data (does not require alignment): */
++#define ERW_(X) extern StgWordArray (X)
++#define IRW_(X) static StgWordArray (X)
++/* read-only data (does not require alignment): */
++#define ERO_(X) extern const StgWordArray (X)
++#define IRO_(X) static const StgWordArray (X)
++/* stg-native functions: */
+ #define IF_(f) static StgFunPtr GNUC3_ATTRIBUTE(used) f(void)
+-#define FN_(f) StgFunPtr f(void)
+-#define EF_(f) StgFunPtr f(void) /* External Cmm functions */
++#define FN_(f) StgFunPtr f(void)
++#define EF_(f) StgFunPtr f(void) /* External Cmm functions */
++/* foreign functions: */
+ #define EFF_(f) void f() /* See Note [External function prototypes] */
+
+ /* Note [External function prototypes] See Trac #8965, #11395
+diff --git a/includes/rts/storage/InfoTables.h b/includes/rts/storage/InfoTables.h
+index 307aac371c..163f1d1c87 100644
+--- a/includes/rts/storage/InfoTables.h
++++ b/includes/rts/storage/InfoTables.h
+@@ -266,7 +266,7 @@ typedef struct {
+ } StgFunInfoTable;
+
+ // canned bitmap for each arg type, indexed by constants in FunTypes.h
+-extern StgWord stg_arg_bitmaps[];
++extern const StgWord stg_arg_bitmaps[];
+
+ /* -----------------------------------------------------------------------------
+ Return info tables
+diff --git a/includes/stg/MiscClosures.h b/includes/stg/MiscClosures.h
+index 9d907ab3ba..b604f1c42b 100644
+--- a/includes/stg/MiscClosures.h
++++ b/includes/stg/MiscClosures.h
+@@ -21,10 +21,10 @@
+ #define STGMISCCLOSURES_H
+
+ #if IN_STG_CODE
+-# define RTS_RET_INFO(i) extern W_(i)[]
+-# define RTS_FUN_INFO(i) extern W_(i)[]
+-# define RTS_THUNK_INFO(i) extern W_(i)[]
+-# define RTS_INFO(i) extern W_(i)[]
++# define RTS_RET_INFO(i) extern const W_(i)[]
++# define RTS_FUN_INFO(i) extern const W_(i)[]
++# define RTS_THUNK_INFO(i) extern const W_(i)[]
++# define RTS_INFO(i) extern const W_(i)[]
+ # define RTS_CLOSURE(i) extern W_(i)[]
+ # define RTS_FUN_DECL(f) extern DLL_IMPORT_RTS StgFunPtr f(void)
+ #else
+@@ -489,9 +489,9 @@ extern StgWord RTS_VAR(sched_mutex);
+
+ // Apply.cmm
+ // canned bitmap for each arg type
+-extern StgWord stg_arg_bitmaps[];
+-extern StgWord stg_ap_stack_entries[];
+-extern StgWord stg_stack_save_entries[];
++extern const StgWord stg_arg_bitmaps[];
++extern const StgWord stg_ap_stack_entries[];
++extern const StgWord stg_stack_save_entries[];
+
+ // Storage.c
+ extern unsigned int RTS_VAR(g0);
+--
+2.12.2
+
diff --git a/dev-lang/ghc/files/ghc-8.2.1_rc1-ghci-cross.patch b/dev-lang/ghc/files/ghc-8.2.1_rc1-ghci-cross.patch
new file mode 100644
index 000000000000..dbba18e85c7f
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-8.2.1_rc1-ghci-cross.patch
@@ -0,0 +1,60 @@
+commit 732b3dbbff194eb8650c75afd79d892801afa0dc
+Author: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Thu Apr 6 22:48:13 2017 +0100
+
+ add $(CrossCompilePrefix) to 'runghc' and 'ghci'
+
+ When Stage1Only=YES install mode is used one of rare tools
+ that lack $(CrossCompilePrefix) prefix are 'runghc' and 'ghci'.
+
+ This causes file collisions when multiple GHC crosscompilers
+ are installed in system.
+
+ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+diff --git a/driver/ghci/ghc.mk b/driver/ghci/ghc.mk
+index 41d1f15c17..0f31884080 100644
+--- a/driver/ghci/ghc.mk
++++ b/driver/ghci/ghc.mk
+@@ -16,16 +16,16 @@ ifneq "$(Windows_Host)" "YES"
+ install: install_driver_ghci
+
+ .PHONY: install_driver_ghci
+-install_driver_ghci: WRAPPER=$(DESTDIR)$(bindir)/ghci-$(ProjectVersion)
++install_driver_ghci: WRAPPER=$(DESTDIR)$(bindir)/$(CrossCompilePrefix)ghci-$(ProjectVersion)
+ install_driver_ghci:
+ $(INSTALL_DIR) "$(DESTDIR)$(bindir)"
+ $(call removeFiles, "$(WRAPPER)")
+ $(CREATE_SCRIPT) "$(WRAPPER)"
+ echo '#!$(SHELL)' >> "$(WRAPPER)"
+- echo 'exec "$(bindir)/ghc-$(ProjectVersion)" --interactive "$$@"' >> "$(WRAPPER)"
++ echo 'exec "$(bindir)/$(CrossCompilePrefix)ghc-$(ProjectVersion)" --interactive "$$@"' >> "$(WRAPPER)"
+ $(EXECUTABLE_FILE) "$(WRAPPER)"
+- $(call removeFiles,"$(DESTDIR)$(bindir)/ghci")
+- $(LN_S) ghci-$(ProjectVersion) "$(DESTDIR)$(bindir)/ghci"
++ $(call removeFiles,"$(DESTDIR)$(bindir)/$(CrossCompilePrefix)ghci")
++ $(LN_S) $(CrossCompilePrefix)ghci-$(ProjectVersion) "$(DESTDIR)$(bindir)/$(CrossCompilePrefix)ghci"
+
+ else # Windows_Host...
+
+diff --git a/utils/runghc/ghc.mk b/utils/runghc/ghc.mk
+index 9169ca21bd..50b11a612e 100644
+--- a/utils/runghc/ghc.mk
++++ b/utils/runghc/ghc.mk
+@@ -34,11 +34,11 @@ install: install_runhaskell
+ .PHONY: install_runhaskell
+ ifeq "$(Windows_Host)" "YES"
+ install_runhaskell: install_bins
+- "$(CP)" $(DESTDIR)$(bindir)/runghc$(exeext1) $(DESTDIR)$(bindir)/runhaskell$(exeext1)
++ "$(CP)" $(DESTDIR)$(bindir)/$(CrossCompilePrefix)runghc$(exeext1) $(DESTDIR)$(bindir)/$(CrossCompilePrefix)runhaskell$(exeext1)
+ else
+ install_runhaskell:
+- $(call removeFiles,"$(DESTDIR)$(bindir)/runhaskell")
+- $(LN_S) runghc "$(DESTDIR)$(bindir)/runhaskell"
+- $(call removeFiles,"$(DESTDIR)$(bindir)/runghc")
+- $(LN_S) runghc-$(ProjectVersion) "$(DESTDIR)$(bindir)/runghc"
++ $(call removeFiles,"$(DESTDIR)$(bindir)/$(CrossCompilePrefix)runhaskell")
++ $(LN_S) $(CrossCompilePrefix)runghc "$(DESTDIR)$(bindir)/$(CrossCompilePrefix)runhaskell"
++ $(call removeFiles,"$(DESTDIR)$(bindir)/$(CrossCompilePrefix)runghc")
++ $(LN_S) $(CrossCompilePrefix)runghc-$(ProjectVersion) "$(DESTDIR)$(bindir)/$(CrossCompilePrefix)runghc"
+ endif
diff --git a/dev-lang/ghc/files/ghc-8.2.1_rc1-hp2ps-cross.patch b/dev-lang/ghc/files/ghc-8.2.1_rc1-hp2ps-cross.patch
new file mode 100644
index 000000000000..26382b3cf44c
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-8.2.1_rc1-hp2ps-cross.patch
@@ -0,0 +1,104 @@
+commit ff84d052850b637b03bbb98cf05202e44886257d
+Author: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Sat Apr 8 10:02:34 2017 +0100
+
+ cross-build 'unlit' and 'hp2ps' for stage2 install
+
+ In navive build case it does not matter much if we build
+ 'unlit' and 'hp2ps' tools with ghc-stage0 or ghc-stage1:
+ both GHCs are native compilers and both tools are written
+ in C (have no haskell code).
+
+ But in cross-case the difference is substantial:
+ In Stag1Only=YES case we need to install native tools built
+ by ghc-stage0/${host}-cc.
+ In Stag1Only=NO case we need to install cross-built tools
+ built by ghc-stage1/${target}-cc.
+
+ Before this change GHC did not have a rule to build cross-built
+ 'unlit' and 'hp2ps'.
+
+ The change adds cross-built 'unlit' and 'hp2ps' as 'dist-install'
+ targets.
+
+ 'inplace/lib/bin/unlit.bin' target is unchanged and still contains
+ native binary.
+
+ As a result this change allows cross-building and packaging whole
+ GHC for target platform!
+
+ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+diff --git a/utils/hp2ps/ghc.mk b/utils/hp2ps/ghc.mk
+index f6e01ec6c1..21ce87dcfa 100644
+--- a/utils/hp2ps/ghc.mk
++++ b/utils/hp2ps/ghc.mk
+@@ -10,6 +10,7 @@
+ #
+ # -----------------------------------------------------------------------------
+
++# stage0
+ utils/hp2ps_dist_C_SRCS = AreaBelow.c Curves.c Error.c Main.c \
+ Reorder.c TopTwenty.c AuxFile.c Deviation.c \
+ HpFile.c Marks.c Scale.c TraceElement.c \
+@@ -17,11 +18,27 @@ utils/hp2ps_dist_C_SRCS = AreaBelow.c Curves.c Error.c Main.c \
+ Utilities.c
+ utils/hp2ps_dist_EXTRA_LIBRARIES = m
+ utils/hp2ps_dist_PROGNAME = hp2ps
+-utils/hp2ps_dist_INSTALL = YES
+ utils/hp2ps_dist_INSTALL_INPLACE = YES
+ utils/hp2ps_dist_SHELL_WRAPPER = YES
+ utils/hp2ps_dist_INSTALL_SHELL_WRAPPER_NAME = hp2ps
+
+ utils/hp2ps_CC_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
+
++# stage 1
++utils/hp2ps_dist-install_C_SRCS = $(utils/hp2ps_dist_C_SRCS)
++utils/hp2ps_dist-install_EXTRA_LIBRARIES = $(utils/hp2ps_dist_EXTRA_LIBRARIES)
++utils/hp2ps_dist-install_PROGNAME = $(utils/hp2ps_dist_PROGNAME)
++utils/hp2ps_dist-install_INSTALL_INPLACE = NO
++utils/hp2ps_dist-install_SHELL_WRAPPER = YES
++utils/hp2ps_dist-install_INSTALL_SHELL_WRAPPER_NAME = $(utils/hp2ps_dist_INSTALL_SHELL_WRAPPER_NAME)
++
++ifeq "$(Stage1Only)" "YES"
++utils/hp2ps_dist_INSTALL = YES
++utils/hp2ps_dist-install_INSTALL = NO
++else
++utils/hp2ps_dist_INSTALL = NO
++utils/hp2ps_dist-install_INSTALL = YES
++endif
++
+ $(eval $(call build-prog,utils/hp2ps,dist,0))
++$(eval $(call build-prog,utils/hp2ps,dist-install,1))
+diff --git a/utils/unlit/ghc.mk b/utils/unlit/ghc.mk
+index e947989b5e..8911f4e856 100644
+--- a/utils/unlit/ghc.mk
++++ b/utils/unlit/ghc.mk
+@@ -10,11 +10,25 @@
+ #
+ # -----------------------------------------------------------------------------
+
++# built by ghc-stage0
+ utils/unlit_dist_C_SRCS = unlit.c
+ utils/unlit_dist_PROGNAME = unlit
+ utils/unlit_dist_TOPDIR = YES
+-utils/unlit_dist_INSTALL = YES
+ utils/unlit_dist_INSTALL_INPLACE = YES
+
+-$(eval $(call build-prog,utils/unlit,dist,0))
++# built by ghc-stage1
++utils/unlit_dist-install_C_SRCS = $(utils/unlit_dist_C_SRCS)
++utils/unlit_dist-install_PROGNAME = $(utils/unlit_dist_PROGNAME)
++utils/unlit_dist-install_TOPDIR = $(utils/unlit_dist_TOPDIR)
++utils/unlit_dist-install_INSTALL_INPLACE = NO
++
++ifeq "$(Stage1Only)" "YES"
++utils/unlit_dist_INSTALL = YES
++utils/unlit_dist-install_INSTALL = NO
++else
++utils/unlit_dist_INSTALL = NO
++utils/unlit_dist-install_INSTALL = YES
++endif
+
++$(eval $(call build-prog,utils/unlit,dist,0))
++$(eval $(call build-prog,utils/unlit,dist-install,1))
diff --git a/dev-lang/ghc/files/ghc-8.2.1_rc1-stage2-cross.patch b/dev-lang/ghc/files/ghc-8.2.1_rc1-stage2-cross.patch
new file mode 100644
index 000000000000..1439d722fef4
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-8.2.1_rc1-stage2-cross.patch
@@ -0,0 +1,81 @@
+commit 54895c90440cb81f18657537b91f2aa35bd54173
+Author: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Fri Apr 7 10:08:58 2017 +0100
+
+ fix 'make install' for cross-stage2
+
+ When cross-built GHC is being installed one of
+ latest steps is to register installed libraries
+ with 'ghc-pkg'.
+
+ GHC uses freshly installed 'ghc-pkg' and 'ghc-stage2'
+ for that.
+
+ Tested as:
+ ./configure --target=aarch64-unknown-linux-gnu
+ make install DESTDIR=$(pwd)/__s2 STRIP_CMD=:
+
+ Before the change install failed on ghc-pkg execution phase:
+
+ ".../ghc-cross/__s2/usr/local/lib/ghc-8.3.20170406/bin/ghc-pkg" \
+ --force \
+ --global-package-db \
+ ".../ghc-cross/__s2/usr/local/lib/ghc-8.3.20170406/package.conf.d" \
+ update rts/dist/package.conf.install
+ /bin/sh: .../ghc-cross/__s2/usr/local/lib/ghc-8.3.20170406/bin/ghc-pkg: \
+ No such file or directory
+
+ To avoid breakage we use 'ghc' and 'ghc-pkg' built by stage0.
+
+ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+ Test Plan: run 'make install' on stage2 crosscompiler
+
+ Reviewers: rwbarton, austin, bgamari
+
+ Subscribers: thomie, snowleopard
+
+ Differential Revision: https://phabricator.haskell.org/D3432
+
+diff --git a/ghc.mk b/ghc.mk
+index caa6c38fbb..8971f25981 100644
+--- a/ghc.mk
++++ b/ghc.mk
+@@ -962,6 +962,12 @@ endif
+
+ INSTALLED_PACKAGE_CONF=$(DESTDIR)$(topdir)/package.conf.d
+
++ifeq "$(CrossCompiling)" "YES"
++# when installing ghc-stage2 we can't run target's
++# 'ghc-pkg' and 'ghc-stage2' but those are needed for registration.
++INSTALLED_GHC_REAL=$(TOP)/inplace/bin/ghc-stage1
++INSTALLED_GHC_PKG_REAL=$(TOP)/$(ghc-pkg_DIST_BINARY)
++else # CrossCompiling
+ # Install packages in the right order, so that ghc-pkg doesn't complain.
+ # Also, install ghc-pkg first.
+ ifeq "$(Windows_Host)" "NO"
+@@ -971,6 +977,7 @@ else
+ INSTALLED_GHC_REAL=$(DESTDIR)$(bindir)/ghc.exe
+ INSTALLED_GHC_PKG_REAL=$(DESTDIR)$(bindir)/ghc-pkg.exe
+ endif
++endif # CrossCompiling
+
+ # Set the INSTALL_DISTDIR_p for each package; compiler is special
+ $(foreach p,$(filter-out compiler,$(INSTALL_PACKAGES)),\
+diff --git a/utils/ghc-pkg/ghc.mk b/utils/ghc-pkg/ghc.mk
+index 002c8122f2..4d5ef4e108 100644
+--- a/utils/ghc-pkg/ghc.mk
++++ b/utils/ghc-pkg/ghc.mk
+@@ -49,6 +49,12 @@ utils/ghc-pkg_dist_PROGNAME = ghc-pkg
+ utils/ghc-pkg_dist_SHELL_WRAPPER = YES
+ utils/ghc-pkg_dist_INSTALL_INPLACE = YES
+
++# When cross-built ghc-stage2 is installed 'make install' needs to call
++# native ghc-pkg (not the cross-built one) to register installed packages
++# 'ghc-pkg_DIST_BINARY' variable only refer to native binary.
++ghc-pkg_DIST_BINARY_NAME = ghc-pkg$(exeext0)
++ghc-pkg_DIST_BINARY = utils/ghc-pkg/dist/build/tmp/$(ghc-pkg_DIST_BINARY_NAME)
++
+ # See Note [Stage1Only vs stage=1] in mk/config.mk.in.
+ ifeq "$(Stage1Only)" "YES"
+ # Install the copy of ghc-pkg from the dist directory when running 'make
diff --git a/dev-lang/ghc/files/ghc-8.2.1_rc1-staged-cross.patch b/dev-lang/ghc/files/ghc-8.2.1_rc1-staged-cross.patch
new file mode 100644
index 000000000000..7e4ea7a9f610
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-8.2.1_rc1-staged-cross.patch
@@ -0,0 +1,43 @@
+commit f2685df3b10e13f142736f28835e9064334bc143
+Author: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Wed Apr 5 22:31:37 2017 +0100
+
+ avoid $(CrossCompilerPrefix) for stage2 install
+
+ Suppose we are crossbuilding ghc (when ghc-stage2
+ is a normal compiler for $target):
+
+ For this case 'make install' should install unprefixed
+ stage2 'ghc' and not '$(CorssCompilePrefix)-ghc'.
+
+ That way cross-built ghc is installable and
+ usable on target as if it would be built natively
+ on a target.
+
+ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+diff --git a/mk/config.mk.in b/mk/config.mk.in
+index 4d5d82aa80..5e274bb71f 100644
+--- a/mk/config.mk.in
++++ b/mk/config.mk.in
+@@ -530,7 +530,7 @@ SUPPORTS_THIS_UNIT_ID = @SUPPORTS_THIS_UNIT_ID@
+ # needs to know which gcc you're using in order to perform its tests.
+
+ GccVersion = @GccVersion@
+-CrossCompilePrefix = @CrossCompilePrefix@
++
+ # TargetPlatformFull retains the string passed to configure so we have it in
+ # the necessary format to pass to libffi's configure.
+ TargetPlatformFull = @TargetPlatformFull@
+@@ -567,6 +567,11 @@ CrossCompiling = @CrossCompiling@
+ # See Note [Stage1Only vs stage=1]
+ Stage1Only = NO
+
++# Installed tools prefix:
++# we add prefix to crosscompiler GHC only (ghc-stage1),
++# not cross-built GHC (not ghc-stage2).
++CrossCompilePrefix = $(if $(filter YES,$(Stage1Only)),@CrossCompilePrefix@,)
++
+ # Install stage 2 by default, or stage 1 in the cross compiler
+ # case. Can be changed to 3
+ INSTALL_GHC_STAGE= $(if $(filter YES,$(Stage1Only)),1,2)
diff --git a/dev-lang/ghc/files/ghc-8.2.1_rc1-unphased-cross.patch b/dev-lang/ghc/files/ghc-8.2.1_rc1-unphased-cross.patch
new file mode 100644
index 000000000000..a5528956de14
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-8.2.1_rc1-unphased-cross.patch
@@ -0,0 +1,30 @@
+commit 6ff98b962db15d18eb1d082fe344cef692ecef8e
+Author: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Thu Apr 6 08:55:56 2017 +0100
+
+ config.mk.in: remove phase=0 hack for CrossCompilePrefix
+
+ $(CrossCompilePrefix) is used only in 'make install'
+ target filenames in $(DESTDIR). None of inplace (or boot)
+ files contain $(CrossCompilePrefix).
+
+ Thus we don't need to worry about phases.
+
+ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+diff --git a/mk/config.mk.in b/mk/config.mk.in
+index 4e61eea821..4d5d82aa80 100644
+--- a/mk/config.mk.in
++++ b/mk/config.mk.in
+@@ -530,11 +530,7 @@ SUPPORTS_THIS_UNIT_ID = @SUPPORTS_THIS_UNIT_ID@
+ # needs to know which gcc you're using in order to perform its tests.
+
+ GccVersion = @GccVersion@
+-ifeq "$(phase)" "0"
+-CrossCompilePrefix =
+-else
+ CrossCompilePrefix = @CrossCompilePrefix@
+-endif
+ # TargetPlatformFull retains the string passed to configure so we have it in
+ # the necessary format to pass to libffi's configure.
+ TargetPlatformFull = @TargetPlatformFull@
diff --git a/dev-lang/ghc/files/ghc-8.2.1_rc1-win32-cross-1.patch b/dev-lang/ghc/files/ghc-8.2.1_rc1-win32-cross-1.patch
new file mode 100644
index 000000000000..79751e1ecbda
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-8.2.1_rc1-win32-cross-1.patch
@@ -0,0 +1,124 @@
+commit a691f6a7a191a268380805481d8e63134764a4a1
+Author: Sergei Trofimovich <slyfox@inbox.ru>
+Date: Sat Apr 29 22:02:24 2017 +0100
+
+ add basic cross-compilation support (#87)
+
+ * fix include case: s/#include <Lmcons.h>/#include <lmcons.h>
+
+ Noticed when cross-compiling win32 on linux to i686-w64-mingw32-gcc.
+ i686-w64-mingw32 provides all headers in lowercase.
+
+ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+ * Pen.hsc: don't use c99-style comments in enum declarations
+
+ Ths change workarounds hsc2hs bug in cross-compile mode:
+ https://ghc.haskell.org/trac/ghc/ticket/13619
+
+ To reproduce the build failure it's enough to run
+ $ cabal configure --hsc2hs-options='--cross-safe --cross-compile'
+ $ cabal build --hsc2hs-options='--cross-safe --cross-compile'
+
+ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+ * SimpleMAPI.hsc: don't use #ifdef in enum declarations
+
+ This change workarounds hsc2hs bug in cross-compile mode:
+ https://ghc.haskell.org/trac/ghc/ticket/13620
+
+ To reproduce the build failure it's enough to run
+ $ cabal configure --hsc2hs-options='--cross-safe --cross-compile'
+ $ cabal build --hsc2hs-options='--cross-safe --cross-compile'
+
+ Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+
+diff --git a/Graphics/Win32/GDI/Pen.hsc b/Graphics/Win32/GDI/Pen.hsc
+index c880170..8d8df5d 100644
+--- a/Graphics/Win32/GDI/Pen.hsc
++++ b/Graphics/Win32/GDI/Pen.hsc
+@@ -56,7 +56,7 @@ foreign import WINDOWS_CCONV unsafe "windows.h DeleteObject"
+
+ type PenStyle = INT
+
+-#{enum PenStyle, // Pick one of these
++#{enum PenStyle,
+ , pS_SOLID = PS_SOLID // default
+ , pS_DASH = PS_DASH // -------
+ , pS_DOT = PS_DOT // .......
+@@ -69,14 +69,14 @@ type PenStyle = INT
+ , pS_STYLE_MASK = PS_STYLE_MASK // all the above
+ }
+
+-#{enum PenStyle , // "or" with one of these
++#{enum PenStyle,
+ , pS_ENDCAP_ROUND = PS_ENDCAP_ROUND // default
+ , pS_ENDCAP_SQUARE = PS_ENDCAP_SQUARE
+ , pS_ENDCAP_FLAT = PS_ENDCAP_FLAT
+ , pS_ENDCAP_MASK = PS_ENDCAP_MASK // all the above
+ }
+
+-#{enum PenStyle, // "or" with one of these
++#{enum PenStyle,
+ , pS_JOIN_ROUND = PS_JOIN_ROUND // default
+ , pS_JOIN_BEVEL = PS_JOIN_BEVEL
+ , pS_JOIN_MITER = PS_JOIN_MITER
+@@ -87,7 +87,7 @@ If PS_JOIN_MASK is not defined with your GNU Windows32 header files,
+ you'll have to define it.
+ -}
+
+-#{enum PenStyle, // "or" with one of these
++#{enum PenStyle,
+ , pS_COSMETIC = PS_COSMETIC // default
+ , pS_GEOMETRIC = PS_GEOMETRIC
+ , pS_TYPE_MASK = PS_TYPE_MASK // all the above
+diff --git a/System/Win32/Info/Computer.hsc b/System/Win32/Info/Computer.hsc
+index bb2eb72..65ae8dc 100644
+--- a/System/Win32/Info/Computer.hsc
++++ b/System/Win32/Info/Computer.hsc
+@@ -65,7 +65,7 @@ import System.Win32.Utils ( tryWithoutNull )
+ import System.Win32.Word ( DWORD, LPDWORD )
+
+ #include <windows.h>
+-#include <Lmcons.h>
++#include <lmcons.h>
+ #include "alignment.h"
+ ##include "windows_cconv.h"
+
+diff --git a/System/Win32/SimpleMAPI.hsc b/System/Win32/SimpleMAPI.hsc
+index 9727cfc..5ebf06b 100644
+--- a/System/Win32/SimpleMAPI.hsc
++++ b/System/Win32/SimpleMAPI.hsc
+@@ -53,12 +53,6 @@ type MapiFlag = ULONG
+ , mAPI_LOGON_UI = MAPI_LOGON_UI
+ , mAPI_NEW_SESSION = MAPI_NEW_SESSION
+ , mAPI_FORCE_DOWNLOAD = MAPI_FORCE_DOWNLOAD
+-#ifdef MAPI_LOGOFF_SHARED
+- , mAPI_LOGOFF_SHARED = MAPI_LOGOFF_SHARED
+-#endif
+-#ifdef MAPI_LOGOFF_UI
+- , mAPI_LOGOFF_UI = MAPI_LOGOFF_UI
+-#endif
+ , mAPI_DIALOG = MAPI_DIALOG
+ , mAPI_UNREAD_ONLY = MAPI_UNREAD_ONLY
+ , mAPI_LONG_MSGID = MAPI_LONG_MSGID
+@@ -74,6 +68,19 @@ type MapiFlag = ULONG
+ , mAPI_RECEIPT_REQUESTED = MAPI_RECEIPT_REQUESTED
+ , mAPI_SENT = MAPI_SENT
+ }
++-- Have to define enum values outside previous declaration due to
++-- hsc2hs bug in --cross-compile mode:
++-- https://ghc.haskell.org/trac/ghc/ticket/13620
++#ifdef MAPI_LOGOFF_SHARED
++#{enum MapiFlag,
++ , mAPI_LOGOFF_SHARED = MAPI_LOGOFF_SHARED
++}
++#endif
++#ifdef MAPI_LOGOFF_UI
++#{enum MapiFlag,
++ , mAPI_LOGOFF_UI = MAPI_LOGOFF_UI
++}
++#endif
+
+ mapiErrors :: [(ULONG,String)]
+ mapiErrors =
diff --git a/dev-lang/ghc/files/ghc-8.2.1_rc1-win32-cross-2-hack.patch b/dev-lang/ghc/files/ghc-8.2.1_rc1-win32-cross-2-hack.patch
new file mode 100644
index 000000000000..6fdcf2d1278f
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-8.2.1_rc1-win32-cross-2-hack.patch
@@ -0,0 +1,144 @@
+hsc2hs can't detect values at compile-time if those are
+declared as pointers: https://github.com/haskell/win32/issues/88
+
+This patch is a huge hack: we encode absolute vaues from <windows.h>
+diff --git a/Graphics/Win32/GDI/Types.hsc b/Graphics/Win32/GDI/Types.hsc
+index c363530..8643cee 100644
+--- a/Graphics/Win32/GDI/Types.hsc
++++ b/Graphics/Win32/GDI/Types.hsc
+@@ -216,10 +216,10 @@ type HWND = HANDLE
+ type MbHWND = Maybe HWND
+
+ #{enum HWND, castUINTPtrToPtr
+- , hWND_BOTTOM = (UINT_PTR)HWND_BOTTOM
+- , hWND_NOTOPMOST = (UINT_PTR)HWND_NOTOPMOST
+- , hWND_TOP = (UINT_PTR)HWND_TOP
+- , hWND_TOPMOST = (UINT_PTR)HWND_TOPMOST
++ , hWND_BOTTOM = (UINT_PTR)(INT_PTR)(1)
++ , hWND_NOTOPMOST = (UINT_PTR)(INT_PTR)(-2)
++ , hWND_TOP = (UINT_PTR)(INT_PTR)(0)
++ , hWND_TOPMOST = (UINT_PTR)(INT_PTR)(-1)
+ }
+
+ type HMENU = HANDLE
+diff --git a/Graphics/Win32/Misc.hsc b/Graphics/Win32/Misc.hsc
+index 1248b5a..c791a20 100644
+--- a/Graphics/Win32/Misc.hsc
++++ b/Graphics/Win32/Misc.hsc
+@@ -67,23 +67,23 @@ foreign import WINDOWS_CCONV unsafe "windows.h LoadIconW"
+ c_LoadIcon :: HINSTANCE -> Icon -> IO HICON
+
+ #{enum Cursor, castUINTPtrToPtr
+- , iDC_ARROW = (UINT_PTR)IDC_ARROW
+- , iDC_IBEAM = (UINT_PTR)IDC_IBEAM
+- , iDC_WAIT = (UINT_PTR)IDC_WAIT
+- , iDC_CROSS = (UINT_PTR)IDC_CROSS
+- , iDC_UPARROW = (UINT_PTR)IDC_UPARROW
+- , iDC_SIZENWSE = (UINT_PTR)IDC_SIZENWSE
+- , iDC_SIZENESW = (UINT_PTR)IDC_SIZENESW
+- , iDC_SIZEWE = (UINT_PTR)IDC_SIZEWE
+- , iDC_SIZENS = (UINT_PTR)IDC_SIZENS
++ , iDC_ARROW = (UINT_PTR)(32512)
++ , iDC_IBEAM = (UINT_PTR)(32513)
++ , iDC_WAIT = (UINT_PTR)(32514)
++ , iDC_CROSS = (UINT_PTR)(32515)
++ , iDC_UPARROW = (UINT_PTR)(32516)
++ , iDC_SIZENWSE = (UINT_PTR)(32642)
++ , iDC_SIZENESW = (UINT_PTR)(32643)
++ , iDC_SIZEWE = (UINT_PTR)(32644)
++ , iDC_SIZENS = (UINT_PTR)(32645)
+ }
+
+ #{enum Icon, castUINTPtrToPtr
+- , iDI_APPLICATION = (UINT_PTR)IDI_APPLICATION
+- , iDI_HAND = (UINT_PTR)IDI_HAND
+- , iDI_QUESTION = (UINT_PTR)IDI_QUESTION
+- , iDI_EXCLAMATION = (UINT_PTR)IDI_EXCLAMATION
+- , iDI_ASTERISK = (UINT_PTR)IDI_ASTERISK
++ , iDI_APPLICATION = (UINT_PTR)(32512)
++ , iDI_HAND = (UINT_PTR)(32513)
++ , iDI_QUESTION = (UINT_PTR)(32514)
++ , iDI_EXCLAMATION = (UINT_PTR)(32515)
++ , iDI_ASTERISK = (UINT_PTR)(32516)
+ }
+
+ ----------------------------------------------------------------
+diff --git a/Graphics/Win32/Resource.hsc b/Graphics/Win32/Resource.hsc
+index e8ad565..ca58fa2 100644
+--- a/Graphics/Win32/Resource.hsc
++++ b/Graphics/Win32/Resource.hsc
+@@ -61,23 +61,23 @@ foreign import WINDOWS_CCONV unsafe "windows.h EndUpdateResourceW"
+ type ResourceType = LPCTSTR
+
+ #{enum ResourceType, castUINTPtrToPtr
+- , rT_ACCELERATOR = (UINT_PTR)RT_ACCELERATOR // Accelerator table
+- , rT_ANICURSOR = (UINT_PTR)RT_ANICURSOR // Animated cursor
+- , rT_ANIICON = (UINT_PTR)RT_ANIICON // Animated icon
+- , rT_BITMAP = (UINT_PTR)RT_BITMAP // Bitmap resource
+- , rT_CURSOR = (UINT_PTR)RT_CURSOR // Hardware-dependent cursor resource
+- , rT_DIALOG = (UINT_PTR)RT_DIALOG // Dialog box
+- , rT_FONT = (UINT_PTR)RT_FONT // Font resource
+- , rT_FONTDIR = (UINT_PTR)RT_FONTDIR // Font directory resource
+- , rT_GROUP_CURSOR = (UINT_PTR)RT_GROUP_CURSOR // Hardware-independent cursor resource
+- , rT_GROUP_ICON = (UINT_PTR)RT_GROUP_ICON // Hardware-independent icon resource
+- , rT_HTML = (UINT_PTR)RT_HTML // HTML document
+- , rT_ICON = (UINT_PTR)RT_ICON // Hardware-dependent icon resource
+- , rT_MENU = (UINT_PTR)RT_MENU // Menu resource
+- , rT_MESSAGETABLE = (UINT_PTR)RT_MESSAGETABLE // Message-table entry
+- , rT_RCDATA = (UINT_PTR)RT_RCDATA // Application-defined resource (raw data)
+- , rT_STRING = (UINT_PTR)RT_STRING // String-table entry
+- , rT_VERSION = (UINT_PTR)RT_VERSION // Version resource
++ , rT_ACCELERATOR = (UINT_PTR)(9)
++ , rT_ANICURSOR = (UINT_PTR)(21)
++ , rT_ANIICON = (UINT_PTR)(22)
++ , rT_BITMAP = (UINT_PTR)(2)
++ , rT_CURSOR = (UINT_PTR)(1)
++ , rT_DIALOG = (UINT_PTR)(5)
++ , rT_FONT = (UINT_PTR)(8)
++ , rT_FONTDIR = (UINT_PTR)(7)
++ , rT_GROUP_CURSOR = (UINT_PTR)(1 + DIFFERENCE)
++ , rT_GROUP_ICON = (UINT_PTR)(3 + DIFFERENCE)
++ , rT_HTML = (UINT_PTR)(23)
++ , rT_ICON = (UINT_PTR)(3)
++ , rT_MENU = (UINT_PTR)(4)
++ , rT_MESSAGETABLE = (UINT_PTR)(11)
++ , rT_RCDATA = (UINT_PTR)(10)
++ , rT_STRING = (UINT_PTR)(6)
++ , rT_VERSION = (UINT_PTR)(16)
+ }
+
+ findResource :: HMODULE -> String -> ResourceType -> IO HRSRC
+diff --git a/Graphics/Win32/Window/PostMessage.hsc b/Graphics/Win32/Window/PostMessage.hsc
+index 7f4c9f0..609f3f6 100644
+--- a/Graphics/Win32/Window/PostMessage.hsc
++++ b/Graphics/Win32/Window/PostMessage.hsc
+@@ -41,7 +41,7 @@ foreign import WINDOWS_CCONV "windows.h PostThreadMessageW"
+ c_PostThreadMessage :: DWORD -> WindowMessage -> WPARAM -> LPARAM -> IO BOOL
+
+ #{enum HWND, castUINTPtrToPtr
+- , hWND_BROADCAST = (UINT_PTR)HWND_BROADCAST
++ , hWND_BROADCAST = (UINT_PTR)(0xffff)
+ }
+
+ foreign import WINDOWS_CCONV "windows.h InSendMessage"
+diff --git a/System/Win32/Registry.hsc b/System/Win32/Registry.hsc
+index afbb011..c7edfc1 100644
+--- a/System/Win32/Registry.hsc
++++ b/System/Win32/Registry.hsc
+@@ -80,11 +80,11 @@ import System.Win32.Types (castUINTPtrToPtr, failUnlessSuccessOr, maybePtr)
+ #include <windows.h>
+
+ #{enum HKEY, (unsafePerformIO . newForeignHANDLE . castUINTPtrToPtr)
+- , hKEY_CLASSES_ROOT = (UINT_PTR)HKEY_CLASSES_ROOT
+- , hKEY_CURRENT_CONFIG = (UINT_PTR)HKEY_CURRENT_CONFIG
+- , hKEY_CURRENT_USER = (UINT_PTR)HKEY_CURRENT_USER
+- , hKEY_LOCAL_MACHINE = (UINT_PTR)HKEY_LOCAL_MACHINE
+- , hKEY_USERS = (UINT_PTR)HKEY_USERS
++ , hKEY_CLASSES_ROOT = (UINT_PTR)(0x80000000)
++ , hKEY_CURRENT_CONFIG = (UINT_PTR)(0x80000005)
++ , hKEY_CURRENT_USER = (UINT_PTR)(0x80000001)
++ , hKEY_LOCAL_MACHINE = (UINT_PTR)(0x80000002)
++ , hKEY_USERS = (UINT_PTR)(0x80000003)
+ }
+ -- , PKEYERFORMANCE_DATA NT only
+ -- , HKEY_DYN_DATA 95/98 only
diff --git a/dev-lang/ghc/files/ghc-8.2.1_rc2-O2-unreg.patch b/dev-lang/ghc/files/ghc-8.2.1_rc2-O2-unreg.patch
new file mode 100644
index 000000000000..00f9ca4fdff9
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-8.2.1_rc2-O2-unreg.patch
@@ -0,0 +1,35 @@
+ghc -O2 generates too large C files for unregisterised compiler.
+On ia64 it causes DynFlags to compile for 60 minutes (then assembler
+crashes).
+
+To decrease C code inflation we don't use -O2 in UNREG mode.
+diff --git a/mk/config.mk.in b/mk/config.mk.in
+index 4e61eea..15a56e9 100644
+--- a/mk/config.mk.in
++++ b/mk/config.mk.in
+@@ -72,11 +72,2 @@ GhcStage3HcOpts=-O2
+
+-# Disable -O2 optimization. Otherwise amount of generated C code
+-# makes things very slow to compile (~5 minutes on core-i7 for 'compiler/hsSyn/HsExpr.hs')
+-# and sometimes not compile at all (powerpc64 overflows something
+-# on 'compiler/hsSyn/HsExpr.hs').
+-ifeq "$(GhcUnregisterised)" "YES"
+-GhcStage1HcOpts=
+-GhcStage2HcOpts=
+-GhcStage3HcOpts=
+-endif
+
+@@ -904 +895,13 @@ CURSES_INCLUDE_DIRS = @CURSES_INCLUDE_DIRS@
+ CURSES_LIB_DIRS = @CURSES_LIB_DIRS@
++
++# Disable -O2 optimization. Otherwise amount of generated C code
++# makes things very slow to compile (~5 minutes on core-i7 for 'compiler/hsSyn/HsExpr.hs')
++# and sometimes not compile at all (powerpc64 overflows something
++# on 'compiler/hsSyn/HsExpr.hs').
++ifeq "$(GhcUnregisterised)" "YES"
++GhcStage1HcOpts=
++GhcStage2HcOpts=
++GhcStage3HcOpts=
++
++GhcLibHcOpts=
++endif
diff --git a/dev-lang/ghc/files/ghc-8.2.1_rc3-any-vendor.patch b/dev-lang/ghc/files/ghc-8.2.1_rc3-any-vendor.patch
new file mode 100644
index 000000000000..b55e37a8bf94
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-8.2.1_rc3-any-vendor.patch
@@ -0,0 +1,44 @@
+From c2303dff95aa174021a1950656fdf9a1cf983959 Mon Sep 17 00:00:00 2001
+From: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Sat, 8 Jul 2017 09:47:12 +0100
+Subject: [PATCH] aclocal.m4: allow arbitrary <vendor> string in toolchain
+ triplets
+
+Canonical triplets have a form of
+ <arch>-<vendor>-<os>[-<abi>]
+
+Checking for vendor is almost never correct as it's an
+arbitrary string.
+
+It's useful to have multiple "vendors" to denote
+otherwise the same (WRT <arch>, <os>, <abi>) target:
+ --target=x86_64-pc-linux-gnu
+ --target=x86_64-unknown-linux-gnu
+ --target=x86_64-ghc80-linux-gnu
+ --target=x86_64-ghchead-linux-gnu
+
+Do not fail unknown vendors. Only emit a warning.
+Ideally configure checks should never use "vendor".
+
+Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+---
+ aclocal.m4 | 3 +--
+ 1 file changed, 1 insertion(+), 2 deletions(-)
+
+diff --git a/aclocal.m4 b/aclocal.m4
+index 001f813dfc..1d9c09b0cd 100644
+--- a/aclocal.m4
++++ b/aclocal.m4
+@@ -230,8 +230,7 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
+ dec|none|unknown|hp|apple|next|sun|sgi|ibm|montavista|portbld)
+ ;;
+ *)
+- echo "Unknown vendor [$]1"
+- exit 1
++ AC_MSG_WARN([Unknown vendor [$]1])
+ ;;
+ esac
+ }
+--
+2.13.3
+
diff --git a/dev-lang/ghc/files/ghc-8.2.1_rc3-stginit-data.patch b/dev-lang/ghc/files/ghc-8.2.1_rc3-stginit-data.patch
new file mode 100644
index 000000000000..81e751d778c8
--- /dev/null
+++ b/dev-lang/ghc/files/ghc-8.2.1_rc3-stginit-data.patch
@@ -0,0 +1,27 @@
+Fix label type for __stginit_* labels: those are .data labels, not .text
+
+Noticed when was building --enable-unregisterised build for x86_64:
+
+/tmp/ghc22931_0/ghc_3.hc:5:9: error:
+ error: '__stginit_ghczmprim_GHCziTypes' redeclared as different kind of symbol
+ StgWord __stginit_ghczmprim_GHCziTypes[]__attribute__((aligned(8)))= {
+ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ |
+5 | StgWord __stginit_ghczmprim_GHCziTypes[]__attribute__((aligned(8)))= {
+ | ^
+
+In file included from /tmp/ghc22931_0/ghc_3.hc:3:0: error:
+
+/tmp/ghc22931_0/ghc_3.hc:4:5: error:
+ note: previous declaration of '__stginit_ghczmprim_GHCziTypes' was here
+ EF_(__stginit_ghczmprim_GHCziTypes);
+ ^
+diff --git a/compiler/cmm/CLabel.hs b/compiler/cmm/CLabel.hs
+index 77a889a..05d71ab 100644
+--- a/compiler/cmm/CLabel.hs
++++ b/compiler/cmm/CLabel.hs
+@@ -956,3 +956,3 @@ labelType (CaseLabel _ CaseReturnInfo) = DataLabel
+ labelType (CaseLabel _ _) = CodeLabel
+-labelType (PlainModuleInitLabel _) = CodeLabel
++labelType (PlainModuleInitLabel _) = DataLabel
+ labelType (SRTLabel _) = DataLabel
diff --git a/dev-lang/ghc/ghc-8.2.1.ebuild b/dev-lang/ghc/ghc-8.2.1.ebuild
new file mode 100644
index 000000000000..56c31c83f65d
--- /dev/null
+++ b/dev-lang/ghc/ghc-8.2.1.ebuild
@@ -0,0 +1,770 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=5
+
+# to make make a crosscompiler use crossdev and symlink ghc tree into
+# cross overlay. result would look like 'cross-sparc-unknown-linux-gnu/ghc'
+export CBUILD=${CBUILD:-${CHOST}}
+export CTARGET=${CTARGET:-${CHOST}}
+if [[ ${CTARGET} = ${CHOST} ]] ; then
+ if [[ ${CATEGORY/cross-} != ${CATEGORY} ]] ; then
+ export CTARGET=${CATEGORY/cross-}
+ fi
+fi
+
+inherit autotools bash-completion-r1 eutils flag-o-matic ghc-package
+inherit multilib pax-utils toolchain-funcs versionator prefix
+inherit check-reqs
+DESCRIPTION="The Glasgow Haskell Compiler"
+HOMEPAGE="http://www.haskell.org/ghc/"
+
+# we don't have any binaries yet
+arch_binaries=""
+
+# sorted!
+#arch_binaries="$arch_binaries alpha? ( http://code.haskell.org/~slyfox/ghc-alpha/ghc-bin-${PV}-alpha.tbz2 )"
+#arch_binaries="$arch_binaries arm? ( http://code.haskell.org/~slyfox/ghc-arm/ghc-bin-${PV}-armv7a-hardfloat-linux-gnueabi.tbz2 )"
+#arch_binaries="$arch_binaries arm64? ( http://code.haskell.org/~slyfox/ghc-arm64/ghc-bin-${PV}-aarch64-unknown-linux-gnu.tbz2 )"
+arch_binaries="$arch_binaries amd64? ( http://code.haskell.org/~slyfox/ghc-amd64/ghc-bin-${PV}-x86_64-pc-linux-gnu.tbz2 )"
+#arch_binaries="$arch_binaries ia64? ( http://code.haskell.org/~slyfox/ghc-ia64/ghc-bin-${PV}-ia64-fixed-fiw.tbz2 )"
+#arch_binaries="$arch_binaries ppc? ( http://code.haskell.org/~slyfox/ghc-ppc/ghc-bin-${PV}-ppc.tbz2 )"
+#arch_binaries="$arch_binaries ppc64? ( http://code.haskell.org/~slyfox/ghc-ppc64/ghc-bin-${PV}-ppc64.tbz2 )"
+#arch_binaries="$arch_binaries sparc? ( http://code.haskell.org/~slyfox/ghc-sparc/ghc-bin-${PV}-sparc.tbz2 )"
+arch_binaries="$arch_binaries x86? ( http://code.haskell.org/~slyfox/ghc-x86/ghc-bin-${PV}-i686-pc-linux-gnu.tbz2 )"
+
+# various ports:
+#arch_binaries="$arch_binaries x86-fbsd? ( http://code.haskell.org/~slyfox/ghc-x86-fbsd/ghc-bin-${PV}-x86-fbsd.tbz2 )"
+
+# 0 - yet
+yet_binary() {
+ case "${ARCH}" in
+ #alpha) return 0 ;;
+ #arm64) return 0 ;;
+ #arm) return 0 ;;
+ amd64) return 0 ;;
+ #ia64) return 0 ;;
+ #ppc) return 0 ;;
+ #ppc64) return 0 ;;
+ #sparc) return 0 ;;
+ x86) return 0 ;;
+ *) return 1 ;;
+ esac
+}
+
+GHC_PV=${PV}
+#GHC_PV=8.2.0.20170704 # uncomment only for -rc ebuilds
+GHC_P=${PN}-${GHC_PV} # using ${P} is almost never correct
+
+SRC_URI="!binary? ( http://downloads.haskell.org/~ghc/${PV/_rc/-rc}/${GHC_P}-src.tar.xz )"
+S="${WORKDIR}"/${GHC_P}
+
+[[ -n $arch_binaries ]] && SRC_URI+=" !ghcbootstrap? ( $arch_binaries )"
+
+BUMP_LIBRARIES=(
+ # "hackage-name hackage-version"
+)
+
+LICENSE="BSD"
+SLOT="0/${PV}"
+#KEYWORDS="~alpha ~amd64 ~x86 ~amd64-linux ~x86-linux"
+IUSE="doc ghcbootstrap ghcmakebinary +gmp profile"
+IUSE+=" binary"
+
+RDEPEND="
+ >=dev-lang/perl-5.6.1
+ dev-libs/gmp:0=
+ sys-libs/ncurses:0=[unicode]
+ !ghcmakebinary? ( virtual/libffi:= )
+"
+
+# This set of dependencies is needed to run
+# prebuilt ghc. We specifically avoid ncurses
+# dependency with:
+# utils/ghc-pkg_HC_OPTS += -DBOOTSTRAPPING
+PREBUILT_BINARY_DEPENDS="
+ !prefix? ( elibc_glibc? ( >=sys-libs/glibc-2.17 ) )
+"
+# This set of dependencies is needed to install
+# ghc[binary] in system. terminfo package is linked
+# against ncurses.
+PREBUILT_BINARY_RDEPENDS="${PREBUILT_BINARY_DEPENDS}
+ sys-libs/ncurses:0/6
+"
+
+RDEPEND+="binary? ( ${PREBUILT_BINARY_RDEPENDS} )"
+
+DEPEND="${RDEPEND}
+ doc? ( app-text/docbook-xml-dtd:4.2
+ app-text/docbook-xml-dtd:4.5
+ app-text/docbook-xsl-stylesheets
+ dev-python/sphinx
+ >=dev-libs/libxslt-1.1.2 )
+ !ghcbootstrap? ( ${PREBUILT_BINARY_DEPENDS} )"
+
+PDEPEND="!ghcbootstrap? ( =app-admin/haskell-updater-1.2* )"
+
+REQUIRED_USE="?? ( ghcbootstrap binary )"
+
+# haskell libraries built with cabal in configure mode, #515354
+QA_CONFIGURE_OPTIONS+=" --with-compiler --with-gcc"
+
+is_crosscompile() {
+ [[ ${CHOST} != ${CTARGET} ]]
+}
+
+is_native() {
+ [[ ${CHOST} == ${CBUILD} ]] && [[ ${CHOST} == ${CTARGET} ]]
+}
+
+# returns tool prefix for crosscompiler.
+# Example:
+# CTARGET=armv7a-unknown-linux-gnueabi
+# CHOST=x86_64-pc-linux-gnu
+# "armv7a-unknown-linux-gnueabi-"
+# CTARGET=${CHOST}
+# ""
+# Used in tools and library prefix:
+# "${ED}"/usr/bin/$(cross)haddock
+# "${ED}/usr/$(get_libdir)/$(cross)${GHC_P}/package.conf.d"
+
+cross() {
+ if is_crosscompile; then
+ echo "${CTARGET}-"
+ else
+ echo ""
+ fi
+}
+
+append-ghc-cflags() {
+ local persistent compile assemble link
+ local flag ghcflag
+
+ for flag in $*; do
+ case ${flag} in
+ persistent) persistent="yes";;
+ compile) compile="yes";;
+ assemble) assemble="yes";;
+ link) link="yes";;
+ *)
+ [[ ${compile} ]] && ghcflag="-optc${flag}" CFLAGS+=" ${flag}" && GHC_FLAGS+=" ${ghcflag}" &&
+ [[ ${persistent} ]] && GHC_PERSISTENT_FLAGS+=" ${ghcflag}"
+ [[ ${assemble} ]] && ghcflag="-opta${flag}" CFLAGS+=" ${flag}" && GHC_FLAGS+=" ${ghcflag}" &&
+ [[ ${persistent} ]] && GHC_PERSISTENT_FLAGS+=" ${ghcflag}"
+ [[ ${link} ]] && ghcflag="-optl${flag}" LDFLAGS+=" ${flag}" && GHC_FLAGS+=" ${ghcflag}" &&
+ [[ ${persistent} ]] && GHC_PERSISTENT_FLAGS+=" ${ghcflag}"
+ ;;
+ esac
+ done
+}
+
+# $1 - lib name (under libraries/)
+# $2 - lib version
+# example: bump_lib "transformers" "0.4.2.0"
+bump_lib() {
+ local pn=$1 pv=$2
+ local p=${pn}-${pv}
+ local f
+
+ einfo "Bumping ${pn} up to ${pv}"
+
+ for f in ghc.mk GNUmakefile; do
+ mv libraries/"${pn}"/$f "${WORKDIR}"/"${p}"/$f || die
+ done
+ mv libraries/"${pn}" "${WORKDIR}"/"${pn}".old || die
+ mv "${WORKDIR}"/"${p}" libraries/"${pn}" || die
+}
+
+update_SRC_URI() {
+ local p pn pv
+ for p in "${BUMP_LIBRARIES[@]}"; do
+ set -- $p
+ pn=$1 pv=$2
+
+ SRC_URI+=" mirror://hackage/package/${pn}/${pn}-${pv}.tar.gz"
+ done
+}
+
+update_SRC_URI
+
+bump_libs() {
+ local p pn pv
+ for p in "${BUMP_LIBRARIES[@]}"; do
+ set -- $p
+ pn=$1 pv=$2
+
+ bump_lib "${pn}" "${pv}"
+ done
+}
+
+ghc_setup_cflags() {
+ # TODO: plumb CFLAGS and BUILD_CFLAGS to respective CONF_CC_OPTS_STAGE<N>
+ if ! is_native; then
+ export CFLAGS=${GHC_CFLAGS-"-O2 -pipe"}
+ export LDFLAGS=${GHC_LDFLAGS-"-Wl,-O1"}
+ einfo "Crosscompiling mode:"
+ einfo " CHOST: ${CHOST}"
+ einfo " CTARGET: ${CTARGET}"
+ einfo " CFLAGS: ${CFLAGS}"
+ einfo " LDFLAGS: ${LDFLAGS}"
+ einfo " prefix: $(cross)"
+ return
+ fi
+ # We need to be very careful with the CFLAGS we ask ghc to pass through to
+ # gcc. There are plenty of flags which will make gcc produce output that
+ # breaks ghc in various ways. The main ones we want to pass through are
+ # -mcpu / -march flags. These are important for arches like alpha & sparc.
+ # We also use these CFLAGS for building the C parts of ghc, ie the rts.
+ strip-flags
+ strip-unsupported-flags
+
+ # Cmm can't parse line numbers #482086
+ replace-flags -ggdb[3-9] -ggdb2
+
+ GHC_FLAGS=""
+ GHC_PERSISTENT_FLAGS=""
+ for flag in ${CFLAGS}; do
+ case ${flag} in
+
+ # Ignore extra optimisation (ghc passes -O to gcc anyway)
+ # -O2 and above break on too many systems
+ -O*) ;;
+
+ # Arch and ABI flags are what we're really after
+ -m*) append-ghc-cflags compile assemble ${flag};;
+
+ # Sometimes it's handy to see backtrace of RTS
+ # to get an idea what happens there
+ -g*) append-ghc-cflags compile ${flag};;
+
+ # Ignore all other flags, including all -f* flags
+ esac
+ done
+
+ for flag in ${LDFLAGS}; do
+ append-ghc-cflags link ${flag}
+ done
+
+ # GHC uses ${CBUILD}-gcc, ${CHOST}-gcc and ${CTARGET}-gcc at a single build.
+ # Skip any gentoo-specific tweaks for cross-case to avoid passing unsupported
+ # options to gcc.
+ if is_native; then
+ # hardened-gcc needs to be disabled, because our prebuilt binaries/libraries
+ # are not built with fPIC, bug #606666
+ gcc-specs-pie && append-ghc-cflags persistent compile link -nopie
+ tc-is-gcc && version_is_at_least 6.3 $(gcc-version) && if ! use ghcbootstrap; then
+ # gcc-6.3 has support for -no-pie upstream, but spelling differs from
+ # gentoo-specific '-nopie'. We enable it in non-bootstrap to allow
+ # hardened users try '-pie' in USE=ghcbootstrap mode.
+ append-ghc-cflags compile link -no-pie
+ fi
+
+ # prevent from failing to build unregisterised ghc:
+ # http://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg171602.html
+ use ppc64 && append-ghc-cflags persistent compile -mminimal-toc
+ fi
+}
+
+# substitutes string $1 to $2 in files $3 $4 ...
+relocate_path() {
+ local from=$1
+ local to=$2
+ shift 2
+ local file=
+ for file in "$@"
+ do
+ sed -i -e "s|$from|$to|g" \
+ "$file" || die "path relocation failed for '$file'"
+ done
+}
+
+# changes hardcoded ghc paths and updates package index
+# $1 - new absolute root path
+relocate_ghc() {
+ local to=$1
+
+ # libdir for prebuilt binary and for current system may mismatch
+ # It does for prefix installation for example: bug #476998
+ local bin_ghc_prefix=${WORKDIR}/usr
+ local bin_libpath=$(echo "${bin_ghc_prefix}"/lib*)
+ local bin_libdir=${bin_libpath#${bin_ghc_prefix}/}
+
+ # backup original script to use it later after relocation
+ local gp_back="${T}/ghc-pkg-${GHC_PV}-orig"
+ cp "${WORKDIR}/usr/bin/ghc-pkg-${GHC_PV}" "$gp_back" || die "unable to backup ghc-pkg wrapper"
+
+ if [[ ${bin_libdir} != $(get_libdir) ]]; then
+ einfo "Relocating '${bin_libdir}' to '$(get_libdir)' (bug #476998)"
+ # moving the dir itself is not strictly needed
+ # but then USE=binary would result in installing
+ # in '${bin_libdir}'
+ mv "${bin_ghc_prefix}/${bin_libdir}" "${bin_ghc_prefix}/$(get_libdir)" || die
+
+ relocate_path "/usr/${bin_libdir}" "/usr/$(get_libdir)" \
+ "${WORKDIR}/usr/bin/ghc-${GHC_PV}" \
+ "${WORKDIR}/usr/bin/ghci-${GHC_PV}" \
+ "${WORKDIR}/usr/bin/ghc-pkg-${GHC_PV}" \
+ "${WORKDIR}/usr/bin/hsc2hs" \
+ "${WORKDIR}/usr/bin/runghc-${GHC_PV}" \
+ "$gp_back" \
+ "${WORKDIR}/usr/$(get_libdir)/${GHC_P}/package.conf.d/"*
+ fi
+
+ # Relocate from /usr to ${EPREFIX}/usr
+ relocate_path "/usr" "${to}/usr" \
+ "${WORKDIR}/usr/bin/ghc-${GHC_PV}" \
+ "${WORKDIR}/usr/bin/ghci-${GHC_PV}" \
+ "${WORKDIR}/usr/bin/ghc-pkg-${GHC_PV}" \
+ "${WORKDIR}/usr/bin/hsc2hs" \
+ "${WORKDIR}/usr/bin/runghc-${GHC_PV}" \
+ "${WORKDIR}/usr/$(get_libdir)/${GHC_P}/package.conf.d/"*
+
+ # this one we will use to regenerate cache
+ # so it should point to current tree location
+ relocate_path "/usr" "${WORKDIR}/usr" "$gp_back"
+
+ if use prefix; then
+ # and insert LD_LIBRARY_PATH entry to EPREFIX dir tree
+ # TODO: add the same for darwin's CHOST and it's DYLD_
+ local new_ldpath='LD_LIBRARY_PATH="'${EPREFIX}/$(get_libdir):${EPREFIX}/usr/$(get_libdir)'${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"\nexport LD_LIBRARY_PATH'
+ sed -i -e '2i'"$new_ldpath" \
+ "${WORKDIR}/usr/bin/ghc-${GHC_PV}" \
+ "${WORKDIR}/usr/bin/ghci-${GHC_PV}" \
+ "${WORKDIR}/usr/bin/ghc-pkg-${GHC_PV}" \
+ "${WORKDIR}/usr/bin/hsc2hs" \
+ "${WORKDIR}/usr/bin/runghc-${GHC_PV}" \
+ "$gp_back" \
+ || die "Adding LD_LIBRARY_PATH for wrappers failed"
+ hprefixify "${bin_libpath}"/${PN}*/settings
+ fi
+
+ # regenerate the binary package cache
+ "$gp_back" recache || die "failed to update cache after relocation"
+ rm "$gp_back"
+}
+
+ghc-check-reqs() {
+ # These are pessimistic values (slightly bigger than worst-case)
+ # Worst case is UNREG USE=profile ia64. See bug #611866 for some
+ # numbers on various arches.
+ CHECKREQS_DISK_BUILD=8G
+ CHECKREQS_DISK_USR=2G
+ # USE=binary roughly takes
+ use binary && CHECKREQS_DISK_BUILD=4G
+
+ "$@"
+}
+
+pkg_pretend() {
+ ghc-check-reqs check-reqs_pkg_pretend
+}
+
+pkg_setup() {
+ ghc-check-reqs check-reqs_pkg_setup
+
+ # quiet portage about prebuilt binaries
+ use binary && QA_PREBUILT="*"
+
+ [[ ${MERGE_TYPE} == binary ]] && return
+
+ if use ghcbootstrap; then
+ ewarn "You requested ghc bootstrapping, this is usually only used"
+ ewarn "by Gentoo developers to make binary .tbz2 packages."
+
+ [[ -z $(type -P ghc) ]] && \
+ die "Could not find a ghc to bootstrap with."
+ else
+ if ! yet_binary; then
+ eerror "Please try emerging with USE=ghcbootstrap and report build"
+ eerror "sucess or failure to the haskell team (haskell@gentoo.org)"
+ die "No binary available for '${ARCH}' arch yet, USE=ghcbootstrap"
+ fi
+ fi
+}
+
+src_unpack() {
+ # Create the ${S} dir if we're using the binary version
+ use binary && mkdir "${S}"
+
+ # the Solaris and Darwin binaries from ghc (maeder) need to be
+ # unpacked separately, so prevent them from being unpacked
+ local ONLYA=${A}
+ case ${CHOST} in
+ *-darwin* | *-solaris*) ONLYA=${GHC_P}-src.tar.bz2 ;;
+ esac
+ unpack ${ONLYA}
+}
+
+src_prepare() {
+ ghc_setup_cflags
+
+ if ! use ghcbootstrap && [[ ${CHOST} != *-darwin* && ${CHOST} != *-solaris* ]]; then
+ # Modify the wrapper script from the binary tarball to use GHC_PERSISTENT_FLAGS.
+ # See bug #313635.
+ sed -i -e "s|\"\$topdir\"|\"\$topdir\" ${GHC_PERSISTENT_FLAGS}|" \
+ "${WORKDIR}/usr/bin/ghc-${GHC_PV}"
+
+ # allow hardened users use vanilla binary to bootstrap ghc
+ # ghci uses mmap with rwx protection at it implements dynamic
+ # linking on it's own (bug #299709)
+ pax-mark -m "${WORKDIR}/usr/$(get_libdir)/${GHC_P}/bin/ghc"
+ fi
+
+ if use binary; then
+ if use prefix; then
+ relocate_ghc "${EPREFIX}"
+ fi
+
+ # Move unpacked files to the expected place
+ mv "${WORKDIR}/usr" "${S}"
+ else
+ if ! use ghcbootstrap; then
+ case ${CHOST} in
+ *-darwin* | *-solaris*)
+ # UPDATE ME for ghc-7
+ mkdir "${WORKDIR}"/ghc-bin-installer || die
+ pushd "${WORKDIR}"/ghc-bin-installer > /dev/null || die
+ use sparc-solaris && unpack ghc-6.10.4-sparc-sun-solaris2.tar.bz2
+ use x86-solaris && unpack ghc-7.0.3-i386-unknown-solaris2.tar.bz2
+ use x86-macos && unpack ghc-7.4.1-i386-apple-darwin.tar.bz2
+ use x64-macos && unpack ghc-7.4.1-x86_64-apple-darwin.tar.bz2
+ popd > /dev/null
+
+ pushd "${WORKDIR}"/ghc-bin-installer/ghc-[67].?*.? > /dev/null || die
+ # fix the binaries so they run, on Solaris we need an
+ # LD_LIBRARY_PATH which has our prefix libdirs, on
+ # Darwin we need to replace the frameworks with our libs
+ # from the prefix fix before installation, because some
+ # of the tools are actually used during configure/make
+ if [[ ${CHOST} == *-solaris* ]] ; then
+ export LD_LIBRARY_PATH="${EPREFIX}/$(get_libdir):${EPREFIX}/usr/$(get_libdir):${LD_LIBRARY_PATH}"
+ elif [[ ${CHOST} == *-darwin* ]] ; then
+ local readline_framework=GNUreadline.framework/GNUreadline
+ local gmp_framework=/opt/local/lib/libgmp.10.dylib
+ local ncurses_file=/opt/local/lib/libncurses.5.dylib
+ for binary in $(scanmacho -BRE MH_EXECUTE -F '%F' .) ; do
+ install_name_tool -change \
+ ${readline_framework} \
+ "${EPREFIX}"/lib/libreadline.dylib \
+ ${binary} || die
+ install_name_tool -change \
+ ${gmp_framework} \
+ "${EPREFIX}"/usr/lib/libgmp.dylib \
+ ${binary} || die
+ install_name_tool -change \
+ ${ncurses_file} \
+ "${EPREFIX}"/usr/lib/libncurses.dylib \
+ ${binary} || die
+ done
+ # we don't do frameworks!
+ sed -i \
+ -e 's/\(frameworks = \)\["GMP"\]/\1[]/g' \
+ -e 's/\(extraLibraries = \)\["m"\]/\1["m","gmp"]/g' \
+ rts/package.conf.in || die
+ fi
+
+ # it is autoconf, but we really don't want to give it too
+ # much arguments, in fact we do the make in-place anyway
+ ./configure --prefix="${WORKDIR}"/usr || die
+ make install || die
+ popd > /dev/null
+ ;;
+ *)
+ relocate_ghc "${WORKDIR}"
+ ;;
+ esac
+ fi
+
+ sed -i -e "s|\"\$topdir\"|\"\$topdir\" ${GHC_PERSISTENT_FLAGS}|" \
+ "${S}/ghc/ghc.wrapper"
+
+ cd "${S}" # otherwise epatch will break
+
+ epatch "${FILESDIR}"/${PN}-7.0.4-CHOST-prefix.patch
+
+ epatch "${FILESDIR}"/${PN}-8.2.1_rc1-cgen-constify.patch
+ epatch "${FILESDIR}"/${PN}-7.8.3-prim-lm.patch
+
+ epatch "${FILESDIR}"/${PN}-8.2.1_rc2-O2-unreg.patch
+
+ # a bunch of crosscompiler patches
+ epatch "${FILESDIR}"/${PN}-8.2.1_rc1-unphased-cross.patch
+ epatch "${FILESDIR}"/${PN}-8.2.1_rc1-staged-cross.patch
+ epatch "${FILESDIR}"/${PN}-8.2.1_rc1-ghci-cross.patch
+ epatch "${FILESDIR}"/${PN}-8.2.1_rc1-stage2-cross.patch
+ epatch "${FILESDIR}"/${PN}-8.2.1_rc1-hp2ps-cross.patch
+ epatch "${FILESDIR}"/${PN}-8.2.1_rc3-any-vendor.patch
+ epatch "${FILESDIR}"/${PN}-8.2.1_rc3-stginit-data.patch
+
+ # needs a new libffi release
+ epatch "${FILESDIR}"/${PN}-8.0.2-libffi-alpha.patch
+
+ # mingw32 target
+ pushd "${S}/libraries/Win32"
+ epatch "${FILESDIR}"/${PN}-8.2.1_rc1-win32-cross-1.patch # upstreamed, waits for merge to -HEAD
+ epatch "${FILESDIR}"/${PN}-8.2.1_rc1-win32-cross-2-hack.patch # bad workaround
+ popd
+
+ if use prefix; then
+ # Make configure find docbook-xsl-stylesheets from Prefix
+ sed -e '/^FP_DIR_DOCBOOK_XSL/s:\[.*\]:['"${EPREFIX}"'/usr/share/sgml/docbook/xsl-stylesheets/]:' \
+ -i utils/haddock/doc/configure.ac || die
+ fi
+
+ bump_libs
+
+ # as we have changed the build system
+ eautoreconf
+ fi
+}
+
+src_configure() {
+ if ! use binary; then
+ # initialize build.mk
+ echo '# Gentoo changes' > mk/build.mk
+
+ # Put docs into the right place, ie /usr/share/doc/ghc-${GHC_PV}
+ echo "docdir = ${EPREFIX}/usr/share/doc/$(cross)${P}" >> mk/build.mk
+ echo "htmldir = ${EPREFIX}/usr/share/doc/$(cross)${P}" >> mk/build.mk
+
+ # We also need to use the GHC_FLAGS flags when building ghc itself
+ echo "SRC_HC_OPTS+=${HCFLAGS} ${GHC_FLAGS}" >> mk/build.mk
+ echo "SRC_CC_OPTS+=${CFLAGS}" >> mk/build.mk
+ echo "SRC_LD_OPTS+=${LDFLAGS}" >> mk/build.mk
+ # Speed up initial Cabal bootstrap
+ echo "utils/ghc-cabal_dist_EXTRA_HC_OPTS+=$(ghc-make-args)" >> mk/build.mk
+
+ # We can't depend on haddock except when bootstrapping when we
+ # must build docs and include them into the binary .tbz2 package
+ # app-text/dblatex is not in portage, can not build PDF or PS
+ echo "BUILD_SPHINX_PDF = NO" >> mk/build.mk
+ echo "BUILD_SPHINX_HTML = $(usex doc YES NO)" >> mk/build.mk
+ echo "BUILD_MAN = $(usex doc YES NO)" >> mk/build.mk
+
+ # this controls presence on 'xhtml' and 'haddock' in final install
+ echo "HADDOCK_DOCS = YES" >> mk/build.mk
+
+ # not used outside of ghc's test
+ if [[ -n ${GHC_BUILD_DPH} ]]; then
+ echo "BUILD_DPH = YES" >> mk/build.mk
+ else
+ echo "BUILD_DPH = NO" >> mk/build.mk
+ fi
+
+ # Any non-native build has to skip as it needs
+ # target haddock binary to be runnabine.
+ if ! is_native; then
+ # disable docs generation as it requires running stage2
+ echo "HADDOCK_DOCS=NO" >> mk/build.mk
+ echo "BUILD_SPHINX_HTML=NO" >> mk/build.mk
+ echo "BUILD_SPHINX_PDF=NO" >> mk/build.mk
+ fi
+
+ if is_crosscompile; then
+ # Install ghc-stage1 crosscompiler instead of
+ # ghc-stage2 cross-built compiler.
+ echo "Stage1Only=YES" >> mk/build.mk
+ fi
+
+ # allows overriding build flavours for libraries:
+ # v - vanilla (static libs)
+ # p - profiled
+ # dyn - shared libraries
+ # example: GHC_LIBRARY_WAYS="v dyn"
+ if [[ -n ${GHC_LIBRARY_WAYS} ]]; then
+ echo "GhcLibWays=${GHC_LIBRARY_WAYS}" >> mk/build.mk
+ fi
+ echo "BUILD_PROF_LIBS = $(usex profile YES NO)" >> mk/build.mk
+
+ # Get ghc from the unpacked binary .tbz2
+ # except when bootstrapping we just pick ghc up off the path
+ if ! use ghcbootstrap; then
+ export PATH="${WORKDIR}/usr/bin:${PATH}"
+ fi
+
+ echo "INTEGER_LIBRARY = $(usex gmp integer-gmp integer-simple)" >> mk/build.mk
+
+ # don't strip anything. Very useful when stage2 SIGSEGVs on you
+ echo "STRIP_CMD = :" >> mk/build.mk
+
+ local econf_args=()
+
+ # GHC embeds toolchain it was built by and uses it later.
+ # Don't allow things like ccache or versioned binary slip.
+ # We use stable thing across gcc upgrades.
+ # User can use EXTRA_ECONF=CC=... to override this default.
+ econf_args+=(
+ AR=${CTARGET}-ar
+ CC=${CTARGET}-gcc
+ LD=${CTARGET}-ld
+ # these should be inferred by GHC but ghc defaults
+ # to using bundled tools on windows.
+ Windres=${CTARGET}-windres
+ DllWrap=${CTARGET}-dllwrap
+ )
+ if [[ ${CTARGET} == arm* ]] ; then
+ # ld.bfd-2.28 does not work for ghc. Force ld.gold
+ # instead. This should be removed once gentoo gets
+ # a fix for R_ARM_COPY bug: https://sourceware.org/PR16177
+ econf_args+=(LD=${CTARGET}-ld.gold)
+ fi
+
+ if [[ ${CBUILD} != ${CHOST} ]]; then
+ # GHC bug: ghc claims not to support cross-building.
+ # It does, but does not distinct --host= value
+ # for stage1 and stage2 compiler.
+ econf_args+=(--host=${CBUILD})
+ fi
+
+ if use ghcmakebinary; then
+ # When building booting libary we are trying to
+ # bundle or restrict most of external depends
+ # with unstable ABI:
+ # - embed libffi (default GHC behaviour)
+ # - disable ncurses support for ghci (via haskeline)
+ # https://bugs.gentoo.org/557478
+ # - disable ncurses support for ghc-pkg
+ echo "libraries/haskeline_CONFIGURE_OPTS += --flag=-terminfo" >> mk/build.mk
+ echo "utils/ghc-pkg_HC_OPTS += -DBOOTSTRAPPING" >> mk/build.mk
+ elif is_native; then
+ # using ${GTARGET}'s libffi is not supported yet:
+ # GHC embeds full path for ffi includes without /usr/${CTARGET} account.
+ econf_args+=(--with-system-libffi)
+ econf_args+=(--with-ffi-includes=$(pkg-config libffi --cflags-only-I | sed -e 's@^-I@@'))
+ fi
+
+ einfo "Final mk/build.mk:"
+ cat mk/build.mk || die
+
+ econf ${econf_args[@]} --enable-bootstrap-with-devel-snapshot
+
+ if [[ ${PV} == *9999* ]]; then
+ GHC_PV="$(grep 'S\[\"PACKAGE_VERSION\"\]' config.status | sed -e 's@^.*=\"\(.*\)\"@\1@')"
+ GHC_P=${PN}-${GHC_PV}
+ fi
+ fi # ! use binary
+}
+
+src_compile() {
+ if ! use binary; then
+ # Stage1Only crosscompiler does not build stage2
+ if ! is_crosscompile; then
+ # 1. build/pax-mark compiler binary first
+ emake ghc/stage2/build/tmp/ghc-stage2
+ # 2. pax-mark (bug #516430)
+ pax-mark -m ghc/stage2/build/tmp/ghc-stage2
+ # 2. build/pax-mark haddock using ghc-stage2
+ if is_native; then
+ # non-native build does not build haddock
+ # due to HADDOCK_DOCS=NO, but it could.
+ emake utils/haddock/dist/build/tmp/haddock
+ pax-mark -m utils/haddock/dist/build/tmp/haddock
+ fi
+ fi
+ # 3. and then all the rest
+ emake all
+ fi # ! use binary
+}
+
+src_install() {
+ if use binary; then
+ use prefix && mkdir -p "${ED}"
+ mv "${S}/usr" "${ED}"
+ else
+ [[ -f VERSION ]] || emake VERSION
+
+ # -j1 due to a rare race in install script:
+ # make --no-print-directory -f ghc.mk phase=final install
+ # /usr/lib/portage/python3.4/ebuild-helpers/xattr/install -c -m 755 \
+ # -d "/tmp/portage-tmpdir/portage/cross-armv7a-unknown-linux-gnueabi/ghc-9999/image/usr/lib64/armv7a-unknown-linux-gnueabi-ghc-8.3.20170404/include"
+ # /usr/lib/portage/python3.4/ebuild-helpers/xattr/install -c -m 644 utils/hsc2hs/template-hsc.h \
+ # "/tmp/portage-tmpdir/portage/cross-armv7a-unknown-linux-gnueabi/ghc-9999/image/usr/lib64/armv7a-unknown-linux-gnueabi-ghc-8.3.20170404"
+ # /usr/bin/install: cannot create regular file \
+ # '/tmp/portage-tmpdir/portage/cross-armv7a-unknown-linux-gnueabi/ghc-9999/image/usr/lib64/armv7a-unknown-linux-gnueabi-ghc-8.3.20170404': No such file or directory
+ emake -j1 install DESTDIR="${D}"
+
+ # Skip for cross-targets as they all share target location:
+ # /usr/share/doc/ghc-9999/
+ if ! is_crosscompile; then
+ dodoc "distrib/README" "ANNOUNCE" "LICENSE" "VERSION"
+ fi
+
+ # rename ghc-shipped files to avoid collision
+ # of external packages. Motivating example:
+ # user had installed:
+ # dev-lang/ghc-7.8.4-r0 (with transformers-0.3.0.0)
+ # dev-haskell/transformers-0.4.2.0
+ # then user tried to update to
+ # dev-lang/ghc-7.8.4-r1 (with transformers-0.4.2.0)
+ # this will lead to single .conf file collision.
+ local shipped_conf renamed_conf
+ local package_confdir="${ED}/usr/$(get_libdir)/$(cross)${GHC_P}/package.conf.d"
+ for shipped_conf in "${package_confdir}"/*.conf; do
+ # rename 'pkg-ver-id.conf' to 'pkg-ver-id-gentoo-${PF}.conf'
+ renamed_conf=${shipped_conf%.conf}-gentoo-${PF}.conf
+ mv "${shipped_conf}" "${renamed_conf}" || die
+ done
+
+ # remove link, but leave 'haddock-${GHC_P}'
+ rm -f "${ED}"/usr/bin/$(cross)haddock
+
+ if ! is_crosscompile; then
+ newbashcomp "${FILESDIR}"/ghc-bash-completion ghc-pkg
+ newbashcomp utils/completion/ghc.bash ghc
+ fi
+ fi
+
+ # path to the package.cache
+ local package_confdir="${ED}/usr/$(get_libdir)/$(cross)${GHC_P}/package.conf.d"
+ PKGCACHE="${package_confdir}"/package.cache
+ # copy the package.conf.d, including timestamp, save it so we can help
+ # users that have a broken package.conf.d
+ cp -pR "${package_confdir}"{,.initial} || die "failed to backup intial package.conf.d"
+
+ # copy the package.conf, including timestamp, save it so we later can put it
+ # back before uninstalling, or when upgrading.
+ cp -p "${PKGCACHE}"{,.shipped} \
+ || die "failed to copy package.conf.d/package.cache"
+}
+
+pkg_preinst() {
+ # have we got an earlier version of ghc installed?
+ if has_version "<${CATEGORY}/${PF}"; then
+ haskell_updater_warn="1"
+ fi
+}
+
+pkg_postinst() {
+ ghc-reregister
+
+ # path to the package.cache
+ PKGCACHE="${EROOT}/usr/$(get_libdir)/$(cross)${GHC_P}/package.conf.d/package.cache"
+
+ # give the cache a new timestamp, it must be as recent as
+ # the package.conf.d directory.
+ touch "${PKGCACHE}"
+
+ if [[ "${haskell_updater_warn}" == "1" ]]; then
+ ewarn
+ ewarn "\e[1;31m************************************************************************\e[0m"
+ ewarn
+ ewarn "You have just upgraded from an older version of GHC."
+ ewarn "You may have to run"
+ ewarn " 'haskell-updater'"
+ ewarn "to rebuild all ghc-based Haskell libraries."
+ ewarn
+ ewarn "\e[1;31m************************************************************************\e[0m"
+ ewarn
+ fi
+}
+
+pkg_prerm() {
+ PKGCACHE="${EROOT}/usr/$(get_libdir)/$(cross)${GHC_P}/package.conf.d/package.cache"
+ rm -rf "${PKGCACHE}"
+
+ cp -p "${PKGCACHE}"{.shipped,}
+}
+
+pkg_postrm() {
+ ghc-package_pkg_postrm
+}