Build program executables directly in inplace/bin.
[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 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 = 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 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 appendCcArgs :: [String] -> Args
212 appendCcArgs xs = do
213 mconcat [ stagedBuilder Gcc ? append xs
214 , stagedBuilder GccM ? append xs
215 , builder GhcCabal ? appendSub "--configure-option=CFLAGS" xs
216 , builder GhcCabal ? appendSub "--gcc-options" xs ]
217
218 needDll0 :: Stage -> Package -> Action Bool
219 needDll0 stage pkg = do
220 windows <- windowsHost
221 return $ windows && pkg == compiler && stage == Stage1
222
223 -- This is a positional argument, hence:
224 -- * if it is empty, we need to emit one empty string argument;
225 -- * otherwise, we must collapse it into one space-separated string.
226 dll0Args :: Args
227 dll0Args = do
228 stage <- getStage
229 pkg <- getPackage
230 dll0 <- lift $ needDll0 stage pkg
231 withGhci <- lift ghcWithInterpreter
232 arg . unwords . concat $ [ modules | dll0 ]
233 ++ [ ghciModules | dll0 && withGhci ] -- see #9552
234 where
235 modules = [ "Annotations"
236 , "ApiAnnotation"
237 , "Avail"
238 , "Bag"
239 , "BasicTypes"
240 , "Binary"
241 , "BooleanFormula"
242 , "BreakArray"
243 , "BufWrite"
244 , "Class"
245 , "CmdLineParser"
246 , "CmmType"
247 , "CoAxiom"
248 , "ConLike"
249 , "Coercion"
250 , "Config"
251 , "Constants"
252 , "CoreArity"
253 , "CoreFVs"
254 , "CoreSubst"
255 , "CoreSyn"
256 , "CoreTidy"
257 , "CoreUnfold"
258 , "CoreUtils"
259 , "CoreSeq"
260 , "CoreStats"
261 , "CostCentre"
262 , "Ctype"
263 , "DataCon"
264 , "Demand"
265 , "Digraph"
266 , "DriverPhases"
267 , "DynFlags"
268 , "Encoding"
269 , "ErrUtils"
270 , "Exception"
271 , "ExtsCompat46"
272 , "FamInstEnv"
273 , "FastFunctions"
274 , "FastMutInt"
275 , "FastString"
276 , "FastTypes"
277 , "Fingerprint"
278 , "FiniteMap"
279 , "ForeignCall"
280 , "Hooks"
281 , "HsBinds"
282 , "HsDecls"
283 , "HsDoc"
284 , "HsExpr"
285 , "HsImpExp"
286 , "HsLit"
287 , "PlaceHolder"
288 , "HsPat"
289 , "HsSyn"
290 , "HsTypes"
291 , "HsUtils"
292 , "HscTypes"
293 , "IOEnv"
294 , "Id"
295 , "IdInfo"
296 , "IfaceSyn"
297 , "IfaceType"
298 , "InstEnv"
299 , "Kind"
300 , "Lexeme"
301 , "Lexer"
302 , "ListSetOps"
303 , "Literal"
304 , "Maybes"
305 , "MkCore"
306 , "MkId"
307 , "Module"
308 , "MonadUtils"
309 , "Name"
310 , "NameEnv"
311 , "NameSet"
312 , "OccName"
313 , "OccurAnal"
314 , "OptCoercion"
315 , "OrdList"
316 , "Outputable"
317 , "PackageConfig"
318 , "Packages"
319 , "Pair"
320 , "Panic"
321 , "PatSyn"
322 , "PipelineMonad"
323 , "Platform"
324 , "PlatformConstants"
325 , "PprCore"
326 , "PrelNames"
327 , "PrelRules"
328 , "Pretty"
329 , "PrimOp"
330 , "RdrName"
331 , "Rules"
332 , "Serialized"
333 , "SrcLoc"
334 , "StaticFlags"
335 , "StringBuffer"
336 , "TcEvidence"
337 , "TcRnTypes"
338 , "TcType"
339 , "TrieMap"
340 , "TyCon"
341 , "Type"
342 , "TypeRep"
343 , "TysPrim"
344 , "TysWiredIn"
345 , "Unify"
346 , "UniqFM"
347 , "UniqSet"
348 , "UniqSupply"
349 , "Unique"
350 , "Util"
351 , "Var"
352 , "VarEnv"
353 , "VarSet" ]
354 ghciModules = [ "Bitmap"
355 , "BlockId"
356 , "ByteCodeAsm"
357 , "ByteCodeInstr"
358 , "ByteCodeItbls"
359 , "CLabel"
360 , "Cmm"
361 , "CmmCallConv"
362 , "CmmExpr"
363 , "CmmInfo"
364 , "CmmMachOp"
365 , "CmmNode"
366 , "CmmSwitch"
367 , "CmmUtils"
368 , "CodeGen.Platform"
369 , "CodeGen.Platform.ARM"
370 , "CodeGen.Platform.ARM64"
371 , "CodeGen.Platform.NoRegs"
372 , "CodeGen.Platform.PPC"
373 , "CodeGen.Platform.PPC_Darwin"
374 , "CodeGen.Platform.SPARC"
375 , "CodeGen.Platform.X86"
376 , "CodeGen.Platform.X86_64"
377 , "FastBool"
378 , "Hoopl"
379 , "Hoopl.Dataflow"
380 , "InteractiveEvalTypes"
381 , "MkGraph"
382 , "PprCmm"
383 , "PprCmmDecl"
384 , "PprCmmExpr"
385 , "Reg"
386 , "RegClass"
387 , "SMRep"
388 , "StgCmmArgRep"
389 , "StgCmmClosure"
390 , "StgCmmEnv"
391 , "StgCmmLayout"
392 , "StgCmmMonad"
393 , "StgCmmProf"
394 , "StgCmmTicky"
395 , "StgCmmUtils"
396 , "StgSyn"
397 , "Stream" ]