Improve code consistency, simplify, fix comments
[hadrian.git] / src / Settings / Builders / GhcCabal.hs
1 module Settings.Builders.GhcCabal (
2 ghcCabalBuilderArgs, ghcCabalHsColourBuilderArgs, bootPackageDatabaseArgs, buildDll0
3 ) where
4
5 import Base
6 import Context
7 import Flavour
8 import GHC
9 import Oracles.Config.Flag
10 import Oracles.Config.Setting
11 import Oracles.WindowsPath
12 import Predicate
13 import Settings
14 import Settings.Builders.Common
15 import Settings.Paths
16
17 ghcCabalBuilderArgs :: Args
18 ghcCabalBuilderArgs = builder GhcCabal ? do
19 verbosity <- lift $ getVerbosity
20 mconcat [ arg "configure"
21 , arg =<< getPackagePath
22 , arg =<< getContextDirectory
23 , dll0Args
24 , withStaged $ Ghc CompileHs
25 , withStaged GhcPkg
26 , bootPackageDatabaseArgs
27 , libraryArgs
28 , with HsColour
29 , configureArgs
30 , packageConstraints
31 , withStaged $ Cc CompileC
32 , notStage0 ? with Ld
33 , with Ar
34 , with Alex
35 , with Happy
36 , verbosity < Chatty ? append [ "-v0", "--configure-option=--quiet"
37 , "--configure-option=--disable-option-checking" ] ]
38
39 ghcCabalHsColourBuilderArgs :: Args
40 ghcCabalHsColourBuilderArgs = builder GhcCabalHsColour ? do
41 path <- getPackagePath
42 dir <- getContextDirectory
43 append [ "hscolour", path, dir ]
44
45 -- TODO: Isn't vanilla always built? If yes, some conditions are redundant.
46 -- TODO: Need compiler_stage1_CONFIGURE_OPTS += --disable-library-for-ghci?
47 libraryArgs :: Args
48 libraryArgs = do
49 ways <- getLibraryWays
50 withGhci <- lift ghcWithInterpreter
51 append [ if vanilla `elem` ways
52 then "--enable-library-vanilla"
53 else "--disable-library-vanilla"
54 , if vanilla `elem` ways && withGhci && not (dynamicGhcPrograms flavour)
55 then "--enable-library-for-ghci"
56 else "--disable-library-for-ghci"
57 , if profiling `elem` ways
58 then "--enable-library-profiling"
59 else "--disable-library-profiling"
60 , if dynamic `elem` ways
61 then "--enable-shared"
62 else "--disable-shared" ]
63
64 -- TODO: LD_OPTS?
65 configureArgs :: Args
66 configureArgs = do
67 top <- getTopDirectory
68 let conf key = appendSubD $ "--configure-option=" ++ key
69 cFlags = mconcat [ cArgs
70 , remove ["-Werror"]
71 , argStagedSettingList ConfCcArgs
72 , arg $ "-I" ++ top -/- generatedPath ]
73 ldFlags = ldArgs <> (argStagedSettingList ConfGccLinkerArgs)
74 cppFlags = cppArgs <> (argStagedSettingList ConfCppArgs)
75 mconcat
76 [ conf "CFLAGS" cFlags
77 , conf "LDFLAGS" ldFlags
78 , conf "CPPFLAGS" cppFlags
79 , appendSubD "--gcc-options" $ cFlags <> ldFlags
80 , conf "--with-iconv-includes" $ argSetting IconvIncludeDir
81 , conf "--with-iconv-libraries" $ argSetting IconvLibDir
82 , conf "--with-gmp-includes" $ argSetting GmpIncludeDir
83 , conf "--with-gmp-libraries" $ argSetting GmpLibDir
84 , crossCompiling ? (conf "--host" $ argSetting TargetPlatformFull)
85 , conf "--with-cc" $ argStagedBuilderPath (Cc CompileC) ]
86
87 bootPackageDatabaseArgs :: Args
88 bootPackageDatabaseArgs = do
89 stage <- getStage
90 lift $ need [packageDbStamp stage]
91 stage0 ? do
92 path <- getTopDirectory
93 prefix <- ifM (builder Ghc) (return "-package-db ") (return "--package-db=")
94 arg $ prefix ++ path -/- packageDbDirectory Stage0
95
96 packageConstraints :: Args
97 packageConstraints = stage0 ? do
98 constraints <- lift . readFileLines $ bootPackageConstraints
99 append $ concat [ ["--constraint", c] | c <- constraints ]
100
101 cppArgs :: Args
102 cppArgs = arg $ "-I" ++ generatedPath
103
104 withBuilderKey :: Builder -> String
105 withBuilderKey b = case b of
106 Ar -> "--with-ar="
107 Ld -> "--with-ld="
108 Cc _ _ -> "--with-gcc="
109 Ghc _ _ -> "--with-ghc="
110 Alex -> "--with-alex="
111 Happy -> "--with-happy="
112 GhcPkg _ -> "--with-ghc-pkg="
113 HsColour -> "--with-hscolour="
114 _ -> error $ "withBuilderKey: not supported builder " ++ show b
115
116 -- Expression 'with Alex' appends "--with-alex=/path/to/alex" and needs Alex.
117 with :: Builder -> Args
118 with b = specified b ? do
119 top <- getTopDirectory
120 path <- getBuilderPath b
121 lift $ needBuilder b
122 arg $ withBuilderKey b ++ unifyPath (top </> path)
123
124 withStaged :: (Stage -> Builder) -> Args
125 withStaged sb = with . sb =<< getStage
126
127 buildDll0 :: Context -> Action Bool
128 buildDll0 Context {..} = do
129 windows <- windowsHost
130 return $ windows && stage == Stage1 && package == compiler
131
132 -- This is a positional argument, hence:
133 -- * if it is empty, we need to emit one empty string argument;
134 -- * otherwise, we must collapse it into one space-separated string.
135 dll0Args :: Args
136 dll0Args = do
137 context <- getContext
138 dll0 <- lift $ buildDll0 context
139 withGhci <- lift ghcWithInterpreter
140 arg . unwords . concat $ [ modules | dll0 ]
141 ++ [ ghciModules | dll0 && withGhci ] -- see #9552
142 where
143 modules = [ "Annotations"
144 , "ApiAnnotation"
145 , "Avail"
146 , "Bag"
147 , "BasicTypes"
148 , "Binary"
149 , "BooleanFormula"
150 , "BreakArray"
151 , "BufWrite"
152 , "Class"
153 , "CmdLineParser"
154 , "CmmType"
155 , "CoAxiom"
156 , "ConLike"
157 , "Coercion"
158 , "Config"
159 , "Constants"
160 , "CoreArity"
161 , "CoreFVs"
162 , "CoreSubst"
163 , "CoreSyn"
164 , "CoreTidy"
165 , "CoreUnfold"
166 , "CoreUtils"
167 , "CoreSeq"
168 , "CoreStats"
169 , "CostCentre"
170 , "Ctype"
171 , "DataCon"
172 , "Demand"
173 , "Digraph"
174 , "DriverPhases"
175 , "DynFlags"
176 , "Encoding"
177 , "ErrUtils"
178 , "Exception"
179 , "ExtsCompat46"
180 , "FamInstEnv"
181 , "FastFunctions"
182 , "FastMutInt"
183 , "FastString"
184 , "FastTypes"
185 , "Fingerprint"
186 , "FiniteMap"
187 , "ForeignCall"
188 , "Hooks"
189 , "HsBinds"
190 , "HsDecls"
191 , "HsDoc"
192 , "HsExpr"
193 , "HsImpExp"
194 , "HsLit"
195 , "PlaceHolder"
196 , "HsPat"
197 , "HsSyn"
198 , "HsTypes"
199 , "HsUtils"
200 , "HscTypes"
201 , "IOEnv"
202 , "Id"
203 , "IdInfo"
204 , "IfaceSyn"
205 , "IfaceType"
206 , "InstEnv"
207 , "Kind"
208 , "Lexeme"
209 , "Lexer"
210 , "ListSetOps"
211 , "Literal"
212 , "Maybes"
213 , "MkCore"
214 , "MkId"
215 , "Module"
216 , "MonadUtils"
217 , "Name"
218 , "NameEnv"
219 , "NameSet"
220 , "OccName"
221 , "OccurAnal"
222 , "OptCoercion"
223 , "OrdList"
224 , "Outputable"
225 , "PackageConfig"
226 , "Packages"
227 , "Pair"
228 , "Panic"
229 , "PatSyn"
230 , "PipelineMonad"
231 , "Platform"
232 , "PlatformConstants"
233 , "PprCore"
234 , "PrelNames"
235 , "PrelRules"
236 , "Pretty"
237 , "PrimOp"
238 , "RdrName"
239 , "Rules"
240 , "Serialized"
241 , "SrcLoc"
242 , "StaticFlags"
243 , "StringBuffer"
244 , "TcEvidence"
245 , "TcRnTypes"
246 , "TcType"
247 , "TrieMap"
248 , "TyCon"
249 , "Type"
250 , "TypeRep"
251 , "TysPrim"
252 , "TysWiredIn"
253 , "Unify"
254 , "UniqFM"
255 , "UniqSet"
256 , "UniqSupply"
257 , "Unique"
258 , "Util"
259 , "Var"
260 , "VarEnv"
261 , "VarSet" ]
262 ghciModules = [ "Bitmap"
263 , "BlockId"
264 , "ByteCodeAsm"
265 , "ByteCodeInstr"
266 , "ByteCodeItbls"
267 , "CLabel"
268 , "Cmm"
269 , "CmmCallConv"
270 , "CmmExpr"
271 , "CmmInfo"
272 , "CmmMachOp"
273 , "CmmNode"
274 , "CmmSwitch"
275 , "CmmUtils"
276 , "CodeGen.Platform"
277 , "CodeGen.Platform.ARM"
278 , "CodeGen.Platform.ARM64"
279 , "CodeGen.Platform.NoRegs"
280 , "CodeGen.Platform.PPC"
281 , "CodeGen.Platform.PPC_Darwin"
282 , "CodeGen.Platform.SPARC"
283 , "CodeGen.Platform.X86"
284 , "CodeGen.Platform.X86_64"
285 , "FastBool"
286 , "Hoopl"
287 , "Hoopl.Dataflow"
288 , "InteractiveEvalTypes"
289 , "MkGraph"
290 , "PprCmm"
291 , "PprCmmDecl"
292 , "PprCmmExpr"
293 , "Reg"
294 , "RegClass"
295 , "SMRep"
296 , "StgCmmArgRep"
297 , "StgCmmClosure"
298 , "StgCmmEnv"
299 , "StgCmmLayout"
300 , "StgCmmMonad"
301 , "StgCmmProf"
302 , "StgCmmTicky"
303 , "StgCmmUtils"
304 , "StgSyn"
305 , "Stream" ]