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