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