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