Build hp2ps utility.
[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 , stage0 ? 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 ghci <- lift ghcWithInterpreter
45 append [ if vanilla `elem` ways
46 then "--enable-library-vanilla"
47 else "--disable-library-vanilla"
48 , if vanilla `elem` ways && ghci && 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 = do
81 path <- getSetting GhcSourcePath
82 arg $ "--package-db=" ++ path -/- "libraries/bootstrapping.conf"
83
84 packageConstraints :: Args
85 packageConstraints = stage0 ? do
86 constraints <- lift . readFileLines $ bootPackageConstraints
87 append $ concat [ ["--constraint", c] | c <- constraints ]
88
89 -- TODO: should be in a different file
90 -- TODO: put all validating options together in one file
91 ccArgs :: Args
92 ccArgs = validating ? ccWarnings
93
94 -- TODO: should be in a different file
95 ccWarnings :: Args
96 ccWarnings = do
97 let gccGe46 = notM $ (flag GccIsClang ||^ flag GccLt46)
98 mconcat [ arg "-Werror"
99 , arg "-Wall"
100 , flag GccIsClang ? arg "-Wno-unknown-pragmas"
101 , gccGe46 ? notM windowsHost ? arg "-Werror=unused-but-set-variable"
102 , gccGe46 ? arg "-Wno-error=inline" ]
103
104 ldArgs :: Args
105 ldArgs = mempty
106
107 ghcIncludeDirs :: [FilePath]
108 ghcIncludeDirs = [ "includes", "includes/dist"
109 , "includes/dist-derivedconstants/header"
110 , "includes/dist-ghcconstants/header" ]
111
112 cppArgs :: Args
113 cppArgs = append $ map ("-I" ++) ghcIncludeDirs
114
115 -- TODO: Is this needed?
116 -- ifeq "$(GMP_PREFER_FRAMEWORK)" "YES"
117 -- libraries/integer-gmp_CONFIGURE_OPTS += --with-gmp-framework-preferred
118 -- endif
119
120 -- TODO: move this somewhere
121 customPackageArgs :: Args
122 customPackageArgs = do
123 nextStage <- fmap succ getStage
124 rtsWays <- getRtsWays
125 mconcat
126 [ package integerGmp ?
127 mconcat [ windowsHost ? builder GhcCabal ?
128 arg "--configure-option=--with-intree-gmp"
129 , appendCcArgs ["-I" ++ pkgPath integerGmp -/- "gmp"] ]
130
131 , package base ?
132 builder GhcCabal ?
133 arg ("--flags=" ++ takeFileName (pkgPath integerLibrary))
134
135 , package ghcPrim ?
136 builder GhcCabal ? arg "--flag=include-ghc-prim"
137
138 , package compiler ?
139 builder GhcCabal ?
140 mconcat [ arg $ "--ghc-option=-DSTAGE=" ++ show nextStage
141 , arg $ "--flags=stage" ++ show nextStage
142 , arg "--disable-library-for-ghci"
143 , anyTargetOs ["openbsd"] ? arg "--ld-options=-E"
144 , flag GhcUnregisterised ? arg "--ghc-option=-DNO_REGS"
145 , notM ghcWithSMP ? arg "--ghc-option=-DNOSMP"
146 , notM ghcWithSMP ? arg "--ghc-option=-optc-DNOSMP"
147 , (threaded `elem` rtsWays) ?
148 notStage0 ? arg "--ghc-option=-optc-DTHREADED_RTS"
149 , ghcWithNativeCodeGen ? arg "--flags=ncg"
150 , ghcWithInterpreter ?
151 notStage0 ? arg "--flags=ghci"
152 , ghcWithInterpreter ?
153 ghcEnableTablesNextToCode ?
154 notM (flag GhcUnregisterised) ?
155 notStage0 ? arg "--ghc-option=-DGHCI_TABLES_NEXT_TO_CODE"
156 , ghcWithInterpreter ?
157 ghciWithDebugger ?
158 notStage0 ? arg "--ghc-option=-DDEBUGGER"
159 , ghcProfiled ?
160 notStage0 ? arg "--ghc-pkg-option=--force"
161 ]
162 , package ghc ?
163 builder GhcCabal ?
164 mconcat [ arg $ "--flags=stage" ++ show nextStage
165 , ghcWithInterpreter ?
166 notStage0 ? arg "--flags=ghci"
167 ]
168 , package haddock ?
169 builder GhcCabal ? append ["--flag", "in-ghc-tree"]
170 ]
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 path <- getBuilderPath b
188 lift $ needBuilder laxDependencies b
189 append [withBuilderKey b ++ path]
190
191 withStaged :: (Stage -> Builder) -> Args
192 withStaged sb = (with . sb) =<< getStage
193
194 argM :: Action String -> Args
195 argM = (arg =<<) . lift
196
197 argSetting :: Setting -> Args
198 argSetting = argM . setting
199
200 argSettingList :: SettingList -> Args
201 argSettingList = (append =<<) . lift . settingList
202
203 argStagedSettingList :: (Stage -> SettingList) -> Args
204 argStagedSettingList ss = (argSettingList . ss) =<< getStage
205
206 argStagedBuilderPath :: (Stage -> Builder) -> Args
207 argStagedBuilderPath sb = (argM . builderPath . sb) =<< getStage
208
209 -- Pass arguments to Gcc and corresponding lists of sub-arguments of GhcCabal
210 appendCcArgs :: [String] -> Args
211 appendCcArgs xs = do
212 mconcat [ stagedBuilder Gcc ? append xs
213 , stagedBuilder GccM ? append xs
214 , builder GhcCabal ? appendSub "--configure-option=CFLAGS" xs
215 , builder GhcCabal ? appendSub "--gcc-options" xs ]
216
217 needDll0 :: Stage -> Package -> Action Bool
218 needDll0 stage pkg = do
219 windows <- windowsHost
220 return $ windows && pkg == compiler && stage == Stage1
221
222 -- This is a positional argument, hence:
223 -- * if it is empty, we need to emit one empty string argument;
224 -- * otherwise, we must collapse it into one space-separated string.
225 dll0Args :: Args
226 dll0Args = do
227 stage <- getStage
228 pkg <- getPackage
229 dll0 <- lift $ needDll0 stage pkg
230 ghci <- lift ghcWithInterpreter
231 arg . unwords . concat $ [ modules | dll0 ]
232 ++ [ ghciModules | dll0 && ghci ] -- see #9552
233 where
234 modules = [ "Annotations"
235 , "ApiAnnotation"
236 , "Avail"
237 , "Bag"
238 , "BasicTypes"
239 , "Binary"
240 , "BooleanFormula"
241 , "BreakArray"
242 , "BufWrite"
243 , "Class"
244 , "CmdLineParser"
245 , "CmmType"
246 , "CoAxiom"
247 , "ConLike"
248 , "Coercion"
249 , "Config"
250 , "Constants"
251 , "CoreArity"
252 , "CoreFVs"
253 , "CoreSubst"
254 , "CoreSyn"
255 , "CoreTidy"
256 , "CoreUnfold"
257 , "CoreUtils"
258 , "CoreSeq"
259 , "CoreStats"
260 , "CostCentre"
261 , "Ctype"
262 , "DataCon"
263 , "Demand"
264 , "Digraph"
265 , "DriverPhases"
266 , "DynFlags"
267 , "Encoding"
268 , "ErrUtils"
269 , "Exception"
270 , "ExtsCompat46"
271 , "FamInstEnv"
272 , "FastFunctions"
273 , "FastMutInt"
274 , "FastString"
275 , "FastTypes"
276 , "Fingerprint"
277 , "FiniteMap"
278 , "ForeignCall"
279 , "Hooks"
280 , "HsBinds"
281 , "HsDecls"
282 , "HsDoc"
283 , "HsExpr"
284 , "HsImpExp"
285 , "HsLit"
286 , "PlaceHolder"
287 , "HsPat"
288 , "HsSyn"
289 , "HsTypes"
290 , "HsUtils"
291 , "HscTypes"
292 , "IOEnv"
293 , "Id"
294 , "IdInfo"
295 , "IfaceSyn"
296 , "IfaceType"
297 , "InstEnv"
298 , "Kind"
299 , "Lexeme"
300 , "Lexer"
301 , "ListSetOps"
302 , "Literal"
303 , "Maybes"
304 , "MkCore"
305 , "MkId"
306 , "Module"
307 , "MonadUtils"
308 , "Name"
309 , "NameEnv"
310 , "NameSet"
311 , "OccName"
312 , "OccurAnal"
313 , "OptCoercion"
314 , "OrdList"
315 , "Outputable"
316 , "PackageConfig"
317 , "Packages"
318 , "Pair"
319 , "Panic"
320 , "PatSyn"
321 , "PipelineMonad"
322 , "Platform"
323 , "PlatformConstants"
324 , "PprCore"
325 , "PrelNames"
326 , "PrelRules"
327 , "Pretty"
328 , "PrimOp"
329 , "RdrName"
330 , "Rules"
331 , "Serialized"
332 , "SrcLoc"
333 , "StaticFlags"
334 , "StringBuffer"
335 , "TcEvidence"
336 , "TcRnTypes"
337 , "TcType"
338 , "TrieMap"
339 , "TyCon"
340 , "Type"
341 , "TypeRep"
342 , "TysPrim"
343 , "TysWiredIn"
344 , "Unify"
345 , "UniqFM"
346 , "UniqSet"
347 , "UniqSupply"
348 , "Unique"
349 , "Util"
350 , "Var"
351 , "VarEnv"
352 , "VarSet" ]
353 ghciModules = [ "Bitmap"
354 , "BlockId"
355 , "ByteCodeAsm"
356 , "ByteCodeInstr"
357 , "ByteCodeItbls"
358 , "CLabel"
359 , "Cmm"
360 , "CmmCallConv"
361 , "CmmExpr"
362 , "CmmInfo"
363 , "CmmMachOp"
364 , "CmmNode"
365 , "CmmSwitch"
366 , "CmmUtils"
367 , "CodeGen.Platform"
368 , "CodeGen.Platform.ARM"
369 , "CodeGen.Platform.ARM64"
370 , "CodeGen.Platform.NoRegs"
371 , "CodeGen.Platform.PPC"
372 , "CodeGen.Platform.PPC_Darwin"
373 , "CodeGen.Platform.SPARC"
374 , "CodeGen.Platform.X86"
375 , "CodeGen.Platform.X86_64"
376 , "FastBool"
377 , "Hoopl"
378 , "Hoopl.Dataflow"
379 , "InteractiveEvalTypes"
380 , "MkGraph"
381 , "PprCmm"
382 , "PprCmmDecl"
383 , "PprCmmExpr"
384 , "Reg"
385 , "RegClass"
386 , "SMRep"
387 , "StgCmmArgRep"
388 , "StgCmmClosure"
389 , "StgCmmEnv"
390 , "StgCmmLayout"
391 , "StgCmmMonad"
392 , "StgCmmProf"
393 , "StgCmmTicky"
394 , "StgCmmUtils"
395 , "StgSyn"
396 , "Stream" ]