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