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