Re-export Expression from Predicates
[hadrian.git] / src / Settings / Builders / GhcCabal.hs
1 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
2 module Settings.Builders.GhcCabal (
3 ghcCabalBuilderArgs, ghcCabalHsColourBuilderArgs, bootPackageDbArgs,
4 PackageDbKey (..), cppArgs, needDll0
5 ) where
6
7 import Base
8 import Builder
9 import GHC
10 import Oracles.Config.Flag
11 import Oracles.Config.Setting
12 import Predicates hiding (stage)
13 import Settings
14 import Settings.Builders.Common
15
16 ghcCabalBuilderArgs :: Args
17 ghcCabalBuilderArgs = builder GhcCabal ? do
18 path <- getPackagePath
19 dir <- getContextDirectory
20 mconcat [ arg "configure"
21 , arg path
22 , arg dir
23 , dll0Args
24 , withStaged $ Ghc Compile
25 , withStaged GhcPkg
26 , bootPackageDbArgs
27 , libraryArgs
28 , with HsColour
29 , configureArgs
30 , packageConstraints
31 , withStaged $ Cc Compile
32 , notStage0 ? with Ld
33 , with Ar
34 , with Alex
35 , with Happy ]
36
37 ghcCabalHsColourBuilderArgs :: Args
38 ghcCabalHsColourBuilderArgs = builder GhcCabalHsColour ? do
39 path <- getPackagePath
40 dir <- getContextDirectory
41 mconcat [ arg "hscolour"
42 , arg path
43 , arg dir ]
44
45 -- TODO: Isn't vanilla always built? If yes, some conditions are redundant.
46 -- TODO: Need compiler_stage1_CONFIGURE_OPTS += --disable-library-for-ghci?
47 libraryArgs :: Args
48 libraryArgs = do
49 ways <- getLibraryWays
50 withGhci <- lift ghcWithInterpreter
51 append [ if vanilla `elem` ways
52 then "--enable-library-vanilla"
53 else "--disable-library-vanilla"
54 , if vanilla `elem` ways && withGhci && not dynamicGhcPrograms
55 then "--enable-library-for-ghci"
56 else "--disable-library-for-ghci"
57 , if profiling `elem` ways
58 then "--enable-library-profiling"
59 else "--disable-library-profiling"
60 , if dynamic `elem` ways
61 then "--enable-shared"
62 else "--disable-shared" ]
63
64 -- TODO: LD_OPTS?
65 -- TODO: WARNING: unrecognized options: --with-compiler, --with-gmp-libraries, --with-cc
66 configureArgs :: Args
67 configureArgs = do
68 let conf key = appendSubD $ "--configure-option=" ++ key
69 cFlags = mconcat [ cArgs
70 , remove ["-Werror"]
71 , argStagedSettingList ConfCcArgs ]
72 ldFlags = ldArgs <> (argStagedSettingList ConfGccLinkerArgs)
73 cppFlags = cppArgs <> (argStagedSettingList ConfCppArgs)
74 mconcat
75 [ conf "CFLAGS" cFlags
76 , conf "LDFLAGS" ldFlags
77 , conf "CPPFLAGS" cppFlags
78 , appendSubD "--gcc-options" $ cFlags <> ldFlags
79 , conf "--with-iconv-includes" $ argSetting IconvIncludeDir
80 , conf "--with-iconv-libraries" $ argSetting IconvLibDir
81 , conf "--with-gmp-includes" $ argSetting GmpIncludeDir
82 , conf "--with-gmp-libraries" $ argSetting GmpLibDir
83 , crossCompiling ? (conf "--host" $ argSetting TargetPlatformFull)
84 , conf "--with-cc" $ argStagedBuilderPath (Cc Compile) ]
85
86 newtype PackageDbKey = PackageDbKey Stage
87 deriving (Show, Typeable, Eq, Hashable, Binary, NFData)
88
89 initialisePackageDb :: Stage -> Action ()
90 initialisePackageDb stage = askOracle $ PackageDbKey stage
91
92 bootPackageDbArgs :: Args
93 bootPackageDbArgs = do
94 stage <- getStage
95 lift $ initialisePackageDb stage
96 stage0 ? do
97 path <- getTopDirectory
98 prefix <- ifM (builder Ghc) (return "-package-db ") (return "--package-db=")
99 arg $ prefix ++ path -/- packageDbDirectory Stage0
100
101 packageConstraints :: Args
102 packageConstraints = stage0 ? do
103 constraints <- lift . readFileLines $ bootPackageConstraints
104 append $ concat [ ["--constraint", c] | c <- constraints ]
105
106 cppArgs :: Args
107 cppArgs = includesArgs
108
109 withBuilderKey :: Builder -> String
110 withBuilderKey b = case b of
111 Ar -> "--with-ar="
112 Ld -> "--with-ld="
113 Cc _ _ -> "--with-gcc="
114 Ghc _ _ -> "--with-ghc="
115 Alex -> "--with-alex="
116 Happy -> "--with-happy="
117 GhcPkg _ -> "--with-ghc-pkg="
118 HsColour -> "--with-hscolour="
119 _ -> error "withBuilderKey: not supported builder"
120
121 -- Expression 'with Alex' appends "--with-alex=/path/to/alex" and needs Alex.
122 with :: Builder -> Args
123 with b = specified b ? do
124 top <- getTopDirectory
125 path <- getBuilderPath b
126 lift $ needBuilder b
127 arg $ withBuilderKey b ++ unifyPath (top </> path)
128
129 withStaged :: (Stage -> Builder) -> Args
130 withStaged sb = with . sb =<< getStage
131
132 needDll0 :: Stage -> Package -> Action Bool
133 needDll0 stage pkg = do
134 windows <- windowsHost
135 return $ windows && pkg == compiler && stage == Stage1
136
137 -- This is a positional argument, hence:
138 -- * if it is empty, we need to emit one empty string argument;
139 -- * otherwise, we must collapse it into one space-separated string.
140 dll0Args :: Args
141 dll0Args = do
142 stage <- getStage
143 pkg <- getPackage
144 dll0 <- lift $ needDll0 stage pkg
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" ]