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