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