cec876acdb43e0d878bed96c3b3ec79fa191208b
[hadrian.git] / src / Settings / Builders / GhcCabal.hs
1 module Settings.Builders.GhcCabal (
2 cabalArgs, ghcCabalHsColourArgs, ghcIncludeDirs, bootPackageDbArgs,
3 customPackageArgs, ccArgs, cppArgs, ccWarnings, argStagedSettingList, needDll0
4 ) where
5
6 import Expression
7 import Predicates hiding (stage)
8 import Settings
9
10 cabalArgs :: Args
11 cabalArgs = builder GhcCabal ? do
12 path <- getPackagePath
13 dir <- getTargetDirectory
14 mconcat [ arg "configure"
15 , arg path
16 , arg dir
17 , dll0Args
18 , withStaged Ghc
19 , withStaged GhcPkg
20 , bootPackageDbArgs
21 , libraryArgs
22 , with HsColour
23 , configureArgs
24 , packageConstraints
25 , withStaged Gcc
26 , notStage0 ? with Ld
27 , with Ar
28 , with Alex
29 , with Happy ]
30
31 ghcCabalHsColourArgs :: Args
32 ghcCabalHsColourArgs = builder GhcCabalHsColour ? do
33 path <- getPackagePath
34 dir <- getTargetDirectory
35 mconcat [ arg "hscolour"
36 , arg path
37 , arg dir ]
38
39 -- TODO: Isn't vanilla always built? If yes, some conditions are redundant.
40 -- TODO: Need compiler_stage1_CONFIGURE_OPTS += --disable-library-for-ghci?
41 libraryArgs :: Args
42 libraryArgs = do
43 ways <- getWays
44 withGhci <- lift ghcWithInterpreter
45 append [ if vanilla `elem` ways
46 then "--enable-library-vanilla"
47 else "--disable-library-vanilla"
48 , if vanilla `elem` ways && withGhci && not dynamicGhcPrograms
49 then "--enable-library-for-ghci"
50 else "--disable-library-for-ghci"
51 , if profiling `elem` ways
52 then "--enable-library-profiling"
53 else "--disable-library-profiling"
54 , if dynamic `elem` ways
55 then "--enable-shared"
56 else "--disable-shared" ]
57
58 -- TODO: LD_OPTS?
59 configureArgs :: Args
60 configureArgs = do
61 let conf key = appendSubD $ "--configure-option=" ++ key
62 cFlags = mconcat [ ccArgs
63 , remove ["-Werror"]
64 , argStagedSettingList ConfCcArgs ]
65 ldFlags = ldArgs <> (argStagedSettingList ConfGccLinkerArgs)
66 cppFlags = cppArgs <> (argStagedSettingList ConfCppArgs)
67 mconcat
68 [ conf "CFLAGS" cFlags
69 , conf "LDFLAGS" ldFlags
70 , conf "CPPFLAGS" cppFlags
71 , appendSubD "--gcc-options" $ cFlags <> ldFlags
72 , conf "--with-iconv-includes" $ argSettingList IconvIncludeDirs
73 , conf "--with-iconv-libraries" $ argSettingList IconvLibDirs
74 , conf "--with-gmp-includes" $ argSettingList GmpIncludeDirs
75 , conf "--with-gmp-libraries" $ argSettingList GmpLibDirs
76 , crossCompiling ? (conf "--host" $ argSetting TargetPlatformFull)
77 , conf "--with-cc" $ argStagedBuilderPath Gcc ]
78
79 bootPackageDbArgs :: Args
80 bootPackageDbArgs = stage0 ? do
81 path <- getSetting GhcSourcePath
82 lift $ need [bootstrappingConfInitialised]
83 isGhc <- stagedBuilder Ghc ||^ stagedBuilder GhcM
84 let prefix = if isGhc then "-package-db " else "--package-db="
85 arg $ prefix ++ path -/- bootstrappingConf
86
87 packageConstraints :: Args
88 packageConstraints = stage0 ? do
89 constraints <- lift . readFileLines $ bootPackageConstraints
90 append $ concat [ ["--constraint", c] | c <- constraints ]
91
92 -- TODO: should be in a different file
93 -- TODO: put all validating options together in one file
94 ccArgs :: Args
95 ccArgs = validating ? ccWarnings
96
97 -- TODO: should be in a different file
98 ccWarnings :: Args
99 ccWarnings = do
100 let gccGe46 = notM $ (flag GccIsClang ||^ flag GccLt46)
101 mconcat [ turnWarningsIntoErrors ? arg "-Werror"
102 , arg "-Wall"
103 , flag GccIsClang ? arg "-Wno-unknown-pragmas"
104 , gccGe46 ? notM windowsHost ? arg "-Werror=unused-but-set-variable"
105 , gccGe46 ? arg "-Wno-error=inline" ]
106
107 ldArgs :: Args
108 ldArgs = mempty
109
110 ghcIncludeDirs :: [FilePath]
111 ghcIncludeDirs = [ "includes", "includes/dist"
112 , "includes/dist-derivedconstants/header"
113 , "includes/dist-ghcconstants/header" ]
114
115 cppArgs :: Args
116 cppArgs = append $ map ("-I" ++) ghcIncludeDirs
117
118 -- TODO: Is this needed?
119 -- ifeq "$(GMP_PREFER_FRAMEWORK)" "YES"
120 -- libraries/integer-gmp_CONFIGURE_OPTS += --with-gmp-framework-preferred
121 -- endif
122
123 -- TODO: move this somewhere
124 customPackageArgs :: Args
125 customPackageArgs = do
126 stage <- getStage
127 rtsWays <- getRtsWays
128 mconcat
129 [ package integerGmp ?
130 mconcat [ windowsHost ? builder GhcCabal ?
131 arg "--configure-option=--with-intree-gmp"
132 , appendCcArgs ["-I" ++ pkgPath integerGmp -/- "gmp"] ]
133
134 , package base ?
135 builder GhcCabal ?
136 arg ("--flags=" ++ takeFileName (pkgPath integerLibrary))
137
138 , package ghcPrim ?
139 builder GhcCabal ? arg "--flag=include-ghc-prim"
140
141 , package compiler ?
142 builder GhcCabal ?
143 mconcat [ arg $ "--ghc-option=-DSTAGE=" ++ show (fromEnum stage + 1)
144 , arg "--disable-library-for-ghci"
145 , anyTargetOs ["openbsd"] ? arg "--ld-options=-E"
146 , flag GhcUnregisterised ? arg "--ghc-option=-DNO_REGS"
147 , notM ghcWithSMP ? arg "--ghc-option=-DNOSMP"
148 , notM ghcWithSMP ? arg "--ghc-option=-optc-DNOSMP"
149 , (threaded `elem` rtsWays) ?
150 notStage0 ? arg "--ghc-option=-optc-DTHREADED_RTS"
151 , ghcWithNativeCodeGen ? arg "--flags=ncg"
152 , ghcWithInterpreter ?
153 notStage0 ? arg "--flags=ghci"
154 , ghcWithInterpreter ?
155 ghcEnableTablesNextToCode ?
156 notM (flag GhcUnregisterised) ?
157 notStage0 ? arg "--ghc-option=-DGHCI_TABLES_NEXT_TO_CODE"
158 , ghcWithInterpreter ?
159 ghciWithDebugger ?
160 notStage0 ? arg "--ghc-option=-DDEBUGGER"
161 , ghcProfiled ?
162 notStage0 ? arg "--ghc-pkg-option=--force" ]
163
164 , package ghc ?
165 builder GhcCabal ?
166 mconcat [ ghcWithInterpreter ?
167 notStage0 ? arg "--flags=ghci" ]
168
169 , package haddock ?
170 builder GhcCabal ? append ["--flag", "in-ghc-tree"] ]
171
172 withBuilderKey :: Builder -> String
173 withBuilderKey b = case b of
174 Ar -> "--with-ar="
175 Ld -> "--with-ld="
176 Gcc _ -> "--with-gcc="
177 Ghc _ -> "--with-ghc="
178 Alex -> "--with-alex="
179 Happy -> "--with-happy="
180 GhcPkg _ -> "--with-ghc-pkg="
181 HsColour -> "--with-hscolour="
182 _ -> error "withBuilderKey: not supported builder"
183
184 -- Expression 'with Gcc' appends "--with-gcc=/path/to/gcc" and needs Gcc.
185 with :: Builder -> Args
186 with b = specified b ? do
187 top <- getSetting GhcSourcePath
188 path <- getBuilderPath b
189 lift $ needBuilder laxDependencies b
190 append [withBuilderKey b ++ top -/- path]
191
192 withStaged :: (Stage -> Builder) -> Args
193 withStaged sb = (with . sb) =<< getStage
194
195 argM :: Action String -> Args
196 argM = (arg =<<) . lift
197
198 argSetting :: Setting -> Args
199 argSetting = argM . setting
200
201 argSettingList :: SettingList -> Args
202 argSettingList = (append =<<) . lift . settingList
203
204 argStagedSettingList :: (Stage -> SettingList) -> Args
205 argStagedSettingList ss = (argSettingList . ss) =<< getStage
206
207 argStagedBuilderPath :: (Stage -> Builder) -> Args
208 argStagedBuilderPath sb = (argM . builderPath . sb) =<< getStage
209
210 -- Pass arguments to Gcc and corresponding lists of sub-arguments of GhcCabal
211 -- TODO: simplify
212 appendCcArgs :: [String] -> Args
213 appendCcArgs xs = do
214 mconcat [ stagedBuilder Gcc ? append xs
215 , stagedBuilder GccM ? append xs
216 , builder GhcCabal ? appendSub "--configure-option=CFLAGS" xs
217 , builder GhcCabal ? appendSub "--gcc-options" xs ]
218
219 needDll0 :: Stage -> Package -> Action Bool
220 needDll0 stage pkg = do
221 windows <- windowsHost
222 return $ windows && pkg == compiler && stage == Stage1
223
224 -- This is a positional argument, hence:
225 -- * if it is empty, we need to emit one empty string argument;
226 -- * otherwise, we must collapse it into one space-separated string.
227 dll0Args :: Args
228 dll0Args = do
229 stage <- getStage
230 pkg <- getPackage
231 dll0 <- lift $ needDll0 stage pkg
232 withGhci <- lift ghcWithInterpreter
233 arg . unwords . concat $ [ modules | dll0 ]
234 ++ [ ghciModules | dll0 && withGhci ] -- see #9552
235 where
236 modules = [ "Annotations"
237 , "ApiAnnotation"
238 , "Avail"
239 , "Bag"
240 , "BasicTypes"
241 , "Binary"
242 , "BooleanFormula"
243 , "BreakArray"
244 , "BufWrite"
245 , "Class"
246 , "CmdLineParser"
247 , "CmmType"
248 , "CoAxiom"
249 , "ConLike"
250 , "Coercion"
251 , "Config"
252 , "Constants"
253 , "CoreArity"
254 , "CoreFVs"
255 , "CoreSubst"
256 , "CoreSyn"
257 , "CoreTidy"
258 , "CoreUnfold"
259 , "CoreUtils"
260 , "CoreSeq"
261 , "CoreStats"
262 , "CostCentre"
263 , "Ctype"
264 , "DataCon"
265 , "Demand"
266 , "Digraph"
267 , "DriverPhases"
268 , "DynFlags"
269 , "Encoding"
270 , "ErrUtils"
271 , "Exception"
272 , "ExtsCompat46"
273 , "FamInstEnv"
274 , "FastFunctions"
275 , "FastMutInt"
276 , "FastString"
277 , "FastTypes"
278 , "Fingerprint"
279 , "FiniteMap"
280 , "ForeignCall"
281 , "Hooks"
282 , "HsBinds"
283 , "HsDecls"
284 , "HsDoc"
285 , "HsExpr"
286 , "HsImpExp"
287 , "HsLit"
288 , "PlaceHolder"
289 , "HsPat"
290 , "HsSyn"
291 , "HsTypes"
292 , "HsUtils"
293 , "HscTypes"
294 , "IOEnv"
295 , "Id"
296 , "IdInfo"
297 , "IfaceSyn"
298 , "IfaceType"
299 , "InstEnv"
300 , "Kind"
301 , "Lexeme"
302 , "Lexer"
303 , "ListSetOps"
304 , "Literal"
305 , "Maybes"
306 , "MkCore"
307 , "MkId"
308 , "Module"
309 , "MonadUtils"
310 , "Name"
311 , "NameEnv"
312 , "NameSet"
313 , "OccName"
314 , "OccurAnal"
315 , "OptCoercion"
316 , "OrdList"
317 , "Outputable"
318 , "PackageConfig"
319 , "Packages"
320 , "Pair"
321 , "Panic"
322 , "PatSyn"
323 , "PipelineMonad"
324 , "Platform"
325 , "PlatformConstants"
326 , "PprCore"
327 , "PrelNames"
328 , "PrelRules"
329 , "Pretty"
330 , "PrimOp"
331 , "RdrName"
332 , "Rules"
333 , "Serialized"
334 , "SrcLoc"
335 , "StaticFlags"
336 , "StringBuffer"
337 , "TcEvidence"
338 , "TcRnTypes"
339 , "TcType"
340 , "TrieMap"
341 , "TyCon"
342 , "Type"
343 , "TypeRep"
344 , "TysPrim"
345 , "TysWiredIn"
346 , "Unify"
347 , "UniqFM"
348 , "UniqSet"
349 , "UniqSupply"
350 , "Unique"
351 , "Util"
352 , "Var"
353 , "VarEnv"
354 , "VarSet" ]
355 ghciModules = [ "Bitmap"
356 , "BlockId"
357 , "ByteCodeAsm"
358 , "ByteCodeInstr"
359 , "ByteCodeItbls"
360 , "CLabel"
361 , "Cmm"
362 , "CmmCallConv"
363 , "CmmExpr"
364 , "CmmInfo"
365 , "CmmMachOp"
366 , "CmmNode"
367 , "CmmSwitch"
368 , "CmmUtils"
369 , "CodeGen.Platform"
370 , "CodeGen.Platform.ARM"
371 , "CodeGen.Platform.ARM64"
372 , "CodeGen.Platform.NoRegs"
373 , "CodeGen.Platform.PPC"
374 , "CodeGen.Platform.PPC_Darwin"
375 , "CodeGen.Platform.SPARC"
376 , "CodeGen.Platform.X86"
377 , "CodeGen.Platform.X86_64"
378 , "FastBool"
379 , "Hoopl"
380 , "Hoopl.Dataflow"
381 , "InteractiveEvalTypes"
382 , "MkGraph"
383 , "PprCmm"
384 , "PprCmmDecl"
385 , "PprCmmExpr"
386 , "Reg"
387 , "RegClass"
388 , "SMRep"
389 , "StgCmmArgRep"
390 , "StgCmmClosure"
391 , "StgCmmEnv"
392 , "StgCmmLayout"
393 , "StgCmmMonad"
394 , "StgCmmProf"
395 , "StgCmmTicky"
396 , "StgCmmUtils"
397 , "StgSyn"
398 , "Stream" ]