Drop mkUserGuidePart
[ghc.git] / src / GHC.hs
1 {-# OPTIONS_GHC -fno-warn-missing-signatures #-}
2 module GHC (
3 -- * GHC packages
4 array, base, binary, bytestring, cabal, checkApiAnnotations, compareSizes,
5 compiler, containers, deepseq, deriveConstants, directory, dllSplit, filepath,
6 genapply, genprimopcode, ghc, ghcBoot, ghcBootTh, ghcCabal, ghcCompact, ghci,
7 ghcPkg, ghcPrim, ghcTags, ghcSplit, haddock, haskeline, hsc2hs, hp2ps,
8 hpc, hpcBin, integerGmp, integerSimple, iservBin, libffi, mtl, parsec,
9 parallel, pretty, primitive, process, rts, runGhc, stm, templateHaskell,
10 terminfo, text, time, touchy, transformers, unlit, unix, win32, xhtml,
11 defaultKnownPackages,
12
13 -- * Package information
14 builderProvenance, programName, nonCabalContext, nonHsMainPackage, autogenPath,
15
16 -- * Miscellaneous
17 systemBuilderPath, ghcSplitPath, stripCmdPath, inplaceInstallPath, buildDll0
18 ) where
19
20 import Hadrian.Oracles.Path
21 import Hadrian.Oracles.TextFile
22
23 import Base
24 import Context
25 import Oracles.Setting
26
27 -- | These are all GHC packages we know about. Build rules will be generated for
28 -- all of them. However, not all of these packages will be built. For example,
29 -- package 'win32' is built only on Windows. "Settings.Default" defines default
30 -- conditions for building each package, which can be overridden in
31 -- @hadrian/src/UserSettings.hs@.
32 defaultKnownPackages :: [Package]
33 defaultKnownPackages =
34 [ array, base, binary, bytestring, cabal, checkApiAnnotations, compareSizes
35 , compiler, containers, deepseq, deriveConstants, directory, dllSplit
36 , filepath, genapply, genprimopcode, ghc, ghcBoot, ghcBootTh, ghcCabal
37 , ghcCompact, ghci, ghcPkg, ghcPrim, ghcTags, haddock, haskeline, hsc2hs
38 , hp2ps, hpc, hpcBin, integerGmp, integerSimple, iservBin, libffi
39 , mtl, parsec, parallel, pretty, primitive, process, rts, runGhc, stm
40 , templateHaskell, terminfo, text, time, touchy, transformers, unlit, unix
41 , win32, xhtml ]
42
43 -- | Package definitions, see 'Package'.
44 array = lib "array"
45 base = lib "base"
46 binary = lib "binary"
47 bytestring = lib "bytestring"
48 cabal = lib "Cabal" `setPath` "libraries/Cabal/Cabal"
49 checkApiAnnotations = util "check-api-annotations"
50 compareSizes = util "compareSizes" `setPath` "utils/compare_sizes"
51 compiler = top "ghc" `setPath` "compiler"
52 containers = lib "containers"
53 deepseq = lib "deepseq"
54 deriveConstants = util "deriveConstants"
55 directory = lib "directory"
56 dllSplit = util "dll-split"
57 filepath = lib "filepath"
58 genapply = util "genapply"
59 genprimopcode = util "genprimopcode"
60 ghc = prg "ghc-bin" `setPath` "ghc"
61 ghcBoot = lib "ghc-boot"
62 ghcBootTh = lib "ghc-boot-th"
63 ghcCabal = util "ghc-cabal"
64 ghcCompact = lib "ghc-compact"
65 ghci = lib "ghci"
66 ghcPkg = util "ghc-pkg"
67 ghcPrim = lib "ghc-prim"
68 ghcTags = util "ghctags"
69 ghcSplit = util "ghc-split"
70 haddock = util "haddock"
71 haskeline = lib "haskeline"
72 hsc2hs = util "hsc2hs"
73 hp2ps = util "hp2ps"
74 hpc = lib "hpc"
75 hpcBin = util "hpc-bin" `setPath` "utils/hpc"
76 integerGmp = lib "integer-gmp"
77 integerSimple = lib "integer-simple"
78 iservBin = prg "iserv-bin" `setPath` "iserv"
79 libffi = top "libffi"
80 mtl = lib "mtl"
81 parsec = lib "parsec"
82 parallel = lib "parallel"
83 pretty = lib "pretty"
84 primitive = lib "primitive"
85 process = lib "process"
86 rts = top "rts"
87 runGhc = util "runghc"
88 stm = lib "stm"
89 templateHaskell = lib "template-haskell"
90 terminfo = lib "terminfo"
91 text = lib "text"
92 time = lib "time"
93 touchy = util "touchy"
94 transformers = lib "transformers"
95 unlit = util "unlit"
96 unix = lib "unix"
97 win32 = lib "Win32"
98 xhtml = lib "xhtml"
99
100 -- | Construct a library package, e.g. @array@.
101 lib :: PackageName -> Package
102 lib name = library name ("libraries" -/- name)
103
104 -- | Construct a top-level library package, e.g. @compiler@.
105 top :: PackageName -> Package
106 top name = library name name
107
108 -- | Construct a top-level program package, e.g. @ghc@.
109 prg :: PackageName -> Package
110 prg name = program name name
111
112 -- | Construct a utility package, e.g. @haddock@.
113 util :: PackageName -> Package
114 util name = program name ("utils" -/- name)
115
116 -- | Amend a package path if it doesn't conform to a typical pattern.
117 setPath :: Package -> FilePath -> Package
118 setPath pkg path | isLibrary pkg = library (pkgName pkg) path
119 | otherwise = program (pkgName pkg) path
120
121 -- | Some builders are built by this very build system, in which case
122 -- 'builderProvenance' returns the corresponding build 'Context' (which includes
123 -- 'Stage' and GHC 'Package').
124 builderProvenance :: Builder -> Maybe Context
125 builderProvenance = \case
126 DeriveConstants -> context Stage0 deriveConstants
127 GenApply -> context Stage0 genapply
128 GenPrimopCode -> context Stage0 genprimopcode
129 Ghc _ Stage0 -> Nothing
130 Ghc _ stage -> context (pred stage) ghc
131 GhcCabal -> context Stage0 ghcCabal
132 GhcCabalHsColour -> builderProvenance $ GhcCabal
133 GhcPkg _ Stage0 -> Nothing
134 GhcPkg _ _ -> context Stage0 ghcPkg
135 Haddock -> context Stage2 haddock
136 Hpc -> context Stage1 hpcBin
137 Hsc2Hs -> context Stage0 hsc2hs
138 Unlit -> context Stage0 unlit
139 _ -> Nothing
140 where
141 context s p = Just $ vanillaContext s p
142
143 -- | Determine the location of a system 'Builder'.
144 systemBuilderPath :: Builder -> Action FilePath
145 systemBuilderPath builder = case builder of
146 Alex -> fromKey "alex"
147 Ar Stage0 -> fromKey "system-ar"
148 Ar _ -> fromKey "ar"
149 Cc _ Stage0 -> fromKey "system-cc"
150 Cc _ _ -> fromKey "cc"
151 -- We can't ask configure for the path to configure!
152 Configure _ -> return "sh configure"
153 Ghc _ Stage0 -> fromKey "system-ghc"
154 GhcPkg _ Stage0 -> fromKey "system-ghc-pkg"
155 Happy -> fromKey "happy"
156 HsColour -> fromKey "hscolour"
157 HsCpp -> fromKey "hs-cpp"
158 Ld -> fromKey "ld"
159 Make _ -> fromKey "make"
160 Nm -> fromKey "nm"
161 Objdump -> fromKey "objdump"
162 Patch -> fromKey "patch"
163 Perl -> fromKey "perl"
164 Ranlib -> fromKey "ranlib"
165 Tar -> fromKey "tar"
166 _ -> error $ "No entry for " ++ show builder ++ inCfg
167 where
168 inCfg = " in " ++ quote configFile ++ " file."
169 fromKey key = do
170 let unpack = fromMaybe . error $ "Cannot find path to builder "
171 ++ quote key ++ inCfg ++ " Did you skip configure?"
172 path <- unpack <$> lookupValue configFile key
173 if null path
174 then do
175 unless (isOptional builder) . error $ "Non optional builder "
176 ++ quote key ++ " is not specified" ++ inCfg
177 return "" -- TODO: Use a safe interface.
178 else fixAbsolutePathOnWindows =<< lookupInPath path
179
180 -- | Given a 'Context', compute the name of the program that is built in it
181 -- assuming that the corresponding package's type is 'Program'. For example, GHC
182 -- built in 'Stage0' is called @ghc-stage1@. If the given package is a
183 -- 'Library', the function simply returns its name.
184 programName :: Context -> String
185 programName Context {..}
186 | package == ghc = "ghc-stage" ++ show (fromEnum stage + 1)
187 | package == hpcBin = "hpc"
188 | package == runGhc = "runhaskell"
189 | package == iservBin = "ghc-iserv"
190 | otherwise = pkgName package
191
192 -- | Some contexts are special: their packages do not have @.cabal@ metadata or
193 -- we cannot run @ghc-cabal@ on them, e.g. because the latter hasn't been built
194 -- yet (this is the case with the 'ghcCabal' package in 'Stage0').
195 nonCabalContext :: Context -> Bool
196 nonCabalContext Context {..} = (package `elem` [hp2ps, rts, touchy, unlit])
197 || package == ghcCabal && stage == Stage0
198
199 -- | Some program packages should not be linked with Haskell main function.
200 nonHsMainPackage :: Package -> Bool
201 nonHsMainPackage = (`elem` [ghc, hp2ps, iservBin, touchy, unlit])
202
203 -- | Path to the autogen directory generated by @ghc-cabal@ of a given 'Context'.
204 autogenPath :: Context -> Action FilePath
205 autogenPath context@Context {..}
206 | isLibrary package = autogen "build"
207 | package == ghc = autogen "build/ghc"
208 | package == hpcBin = autogen "build/hpc"
209 | package == iservBin = autogen "build/iserv"
210 | otherwise = autogen $ "build" -/- pkgName package
211 where
212 autogen dir = buildPath context <&> (-/- dir -/- "autogen")
213
214 -- | Given a 'Package', return the path where the corresponding program is
215 -- installed. Most programs are installed in 'programInplacePath'.
216 inplaceInstallPath :: Package -> FilePath
217 inplaceInstallPath pkg
218 | pkg == touchy = inplaceLibBinPath
219 | pkg == unlit = inplaceLibBinPath
220 | pkg == iservBin = inplaceLibBinPath
221 | otherwise = inplaceBinPath
222
223 -- | @ghc-split@ is a Perl script used by GHC with @-split-objs@ flag. It is
224 -- generated in "Rules.Generators.GhcSplit".
225 ghcSplitPath :: FilePath
226 ghcSplitPath = inplaceLibBinPath -/- "ghc-split"
227
228 -- ref: mk/config.mk
229 -- | Command line tool for stripping.
230 stripCmdPath :: Action FilePath
231 stripCmdPath = do
232 targetPlatform <- setting TargetPlatform
233 top <- topDirectory
234 case targetPlatform of
235 "x86_64-unknown-mingw32" ->
236 return (top -/- "inplace/mingw/bin/strip.exe")
237 "arm-unknown-linux" ->
238 return ":" -- HACK: from the make-based system, see the ref above
239 _ -> return "strip"
240
241 buildDll0 :: Context -> Action Bool
242 buildDll0 Context {..} = do
243 windows <- windowsHost
244 return $ windows && stage == Stage1 && package == compiler