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