hadrian: eliminate most of the remaining big rule enumerations
[ghc.git] / hadrian / src / Settings / Default.hs
1 module Settings.Default (
2 -- * Packages that are build by default and for the testsuite
3 defaultPackages, testsuitePackages, getPackageByPath,
4
5 -- * Default build ways
6 defaultLibraryWays, defaultRtsWays,
7
8 -- * Default command line arguments for various builders
9 SourceArgs (..), sourceArgs, defaultBuilderArgs, defaultPackageArgs,
10 defaultArgs,
11
12 -- * Default build flavour
13 defaultFlavour, defaultSplitObjects
14 ) where
15
16 import qualified Hadrian.Builder.Ar
17 import qualified Hadrian.Builder.Sphinx
18 import qualified Hadrian.Builder.Tar
19 import Hadrian.Haskell.Cabal.Type
20
21 import CommandLine
22 import Expression
23 import Flavour
24 import Oracles.Flag
25 import Oracles.Setting
26 import Packages
27 import Settings
28 import Settings.Builders.Alex
29 import Settings.Builders.DeriveConstants
30 import Settings.Builders.Cabal
31 import Settings.Builders.Cc
32 import Settings.Builders.Configure
33 import Settings.Builders.GenPrimopCode
34 import Settings.Builders.Ghc
35 import Settings.Builders.GhcPkg
36 import Settings.Builders.Haddock
37 import Settings.Builders.Happy
38 import Settings.Builders.Hsc2Hs
39 import Settings.Builders.HsCpp
40 import Settings.Builders.Ld
41 import Settings.Builders.Make
42 import Settings.Builders.RunTest
43 import Settings.Builders.Xelatex
44 import Settings.Packages
45 import Settings.Warnings
46
47 -- | Packages that are built by default. You can change this in "UserSettings".
48 defaultPackages :: Stage -> Action [Package]
49 defaultPackages Stage0 = stage0Packages
50 defaultPackages Stage1 = stage1Packages
51 defaultPackages Stage2 = stage2Packages
52 defaultPackages Stage3 = return []
53
54 -- | Packages built in 'Stage0' by default. You can change this in "UserSettings".
55 stage0Packages :: Action [Package]
56 stage0Packages = do
57 win <- windowsHost
58 cross <- flag CrossCompiling
59 return $ [ binary
60 , cabal
61 , compareSizes
62 , compiler
63 , deriveConstants
64 , genapply
65 , genprimopcode
66 , ghc
67 , ghcBoot
68 , ghcBootTh
69 , ghcHeap
70 , ghci
71 , ghcPkg
72 , hsc2hs
73 , hpc
74 , mtl
75 , parsec
76 , templateHaskell
77 , text
78 , transformers
79 , unlit ]
80 ++ [ terminfo | not win, not cross ]
81 ++ [ touchy | win ]
82
83 -- | Packages built in 'Stage1' by default. You can change this in "UserSettings".
84 stage1Packages :: Action [Package]
85 stage1Packages = do
86 win <- windowsHost
87 intLib <- integerLibrary =<< flavour
88 libraries0 <- filter isLibrary <$> stage0Packages
89 cross <- flag CrossCompiling
90 return $ libraries0 -- Build all Stage0 libraries in Stage1
91 ++ [ array
92 , base
93 , bytestring
94 , containers
95 , deepseq
96 , directory
97 , filepath
98 , ghc
99 , ghcCompact
100 , ghcPkg
101 , ghcPrim
102 , haskeline
103 , hsc2hs
104 , intLib
105 , pretty
106 , process
107 , rts
108 , stm
109 , time
110 , unlit
111 , xhtml ]
112 ++ [ hpcBin | not cross ]
113 ++ [ iserv | not win, not cross ]
114 ++ [ libiserv | not win, not cross ]
115 ++ [ runGhc | not cross ]
116 ++ [ touchy | win ]
117 ++ [ unix | not win ]
118 ++ [ win32 | win ]
119
120 -- | Packages built in 'Stage2' by default. You can change this in "UserSettings".
121 stage2Packages :: Action [Package]
122 stage2Packages = do
123 cross <- flag CrossCompiling
124 return $ [ ghcTags ]
125 ++ [ haddock | not cross ]
126
127 -- | Packages that are built only for the testsuite.
128 testsuitePackages :: Action [Package]
129 testsuitePackages = do
130 win <- windowsHost
131 return $ [ checkApiAnnotations
132 , checkPpr
133 , ghci
134 , ghcCompact
135 , ghcPkg
136 , hp2ps
137 , hsc2hs
138 , iserv
139 , parallel
140 , runGhc
141 , unlit ] ++
142 [ timeout | win ]
143
144 getPackageByPath :: FilePath -> Action Package
145 getPackageByPath pkgpath = do
146 case filter (\p -> pkgPath p == pkgpath) knownPackages of
147 (p:_) -> return p
148 _ -> error $
149 "getPackageByPath: couldn't find a package with path: " ++ pkgpath
150
151 -- | Default build ways for library packages:
152 -- * We always build 'vanilla' way.
153 -- * We build 'profiling' way when stage > Stage0.
154 -- * We build 'dynamic' way when stage > Stage0 and the platform supports it.
155 defaultLibraryWays :: Ways
156 defaultLibraryWays = mconcat
157 [ pure [vanilla]
158 , notStage0 ? pure [profiling]
159 , notStage0 ? platformSupportsSharedLibs ? pure [dynamic]
160 ]
161
162 -- | Default build ways for the RTS.
163 defaultRtsWays :: Ways
164 defaultRtsWays = mconcat
165 [ pure [vanilla, threaded]
166 , notStage0 ? pure
167 [ profiling, threadedProfiling, debugProfiling, threadedDebugProfiling
168 , logging, threadedLogging
169 , debug, threadedDebug
170 ]
171 , notStage0 ? platformSupportsSharedLibs ? pure
172 [ dynamic, threadedDynamic, debugDynamic, loggingDynamic
173 , threadedDebugDynamic, threadedLoggingDynamic
174 ]
175 ]
176
177 -- TODO: Move C source arguments here
178 -- | Default and package-specific source arguments.
179 data SourceArgs = SourceArgs
180 { hsDefault :: Args
181 , hsLibrary :: Args
182 , hsCompiler :: Args
183 , hsGhc :: Args }
184
185 -- | Concatenate source arguments in appropriate order.
186 sourceArgs :: SourceArgs -> Args
187 sourceArgs SourceArgs {..} = builder Ghc ? mconcat
188 [ hsDefault
189 , getContextData hcOpts
190 , libraryPackage ? hsLibrary
191 , package compiler ? hsCompiler
192 , package ghc ? hsGhc ]
193
194 -- | All default command line arguments.
195 defaultArgs :: Args
196 defaultArgs = mconcat
197 [ defaultBuilderArgs
198 , sourceArgs defaultSourceArgs
199 , defaultPackageArgs ]
200
201 -- | Default source arguments, e.g. optimisation settings.
202 defaultSourceArgs :: SourceArgs
203 defaultSourceArgs = SourceArgs
204 { hsDefault = mconcat [ stage0 ? arg "-O"
205 , notStage0 ? arg "-O2"
206 , arg "-H32m" ]
207 , hsLibrary = mempty
208 , hsCompiler = mempty
209 , hsGhc = mempty }
210
211 -- Please update doc/flavours.md when changing the default build flavour.
212 -- | Default build flavour. Other build flavours are defined in modules
213 -- @Settings.Flavours.*@. Users can add new build flavours in "UserSettings".
214 defaultFlavour :: Flavour
215 defaultFlavour = Flavour
216 { name = "default"
217 , args = defaultArgs
218 , packages = defaultPackages
219 , integerLibrary = (\x -> if x then integerSimple else integerGmp) <$> cmdIntegerSimple
220 , libraryWays = defaultLibraryWays
221 , rtsWays = defaultRtsWays
222 , splitObjects = defaultSplitObjects
223 , dynamicGhcPrograms = defaultDynamicGhcPrograms
224 , ghciWithDebugger = False
225 , ghcProfiled = False
226 , ghcDebugged = False }
227
228 -- | Default logic for determining whether to build
229 -- dynamic GHC programs.
230 --
231 -- It corresponds to the DYNAMIC_GHC_PROGRAMS logic implemented
232 -- in @mk/config.mk.in@.
233 defaultDynamicGhcPrograms :: Action Bool
234 defaultDynamicGhcPrograms = do
235 win <- windowsHost
236 supportsShared <- platformSupportsSharedLibs
237 return (not win && supportsShared)
238
239 -- | Default condition for building split objects.
240 defaultSplitObjects :: Predicate
241 defaultSplitObjects = do
242 goodStage <- notStage0 -- We don't split bootstrap (stage 0) packages
243 pkg <- getPackage
244 supported <- expr supportsSplitObjects
245 split <- expr cmdSplitObjects
246 let goodPackage = isLibrary pkg && pkg /= compiler && pkg /= rts
247 return $ split && goodStage && goodPackage && supported
248
249 -- | All 'Builder'-dependent command line arguments.
250 defaultBuilderArgs :: Args
251 defaultBuilderArgs = mconcat
252 -- GHC-specific builders:
253 [ alexBuilderArgs
254 , cabalBuilderArgs
255 , ccBuilderArgs
256 , configureBuilderArgs
257 , deriveConstantsBuilderArgs
258 , genPrimopCodeBuilderArgs
259 , ghcBuilderArgs
260 , ghcPkgBuilderArgs
261 , haddockBuilderArgs
262 , happyBuilderArgs
263 , hsc2hsBuilderArgs
264 , hsCppBuilderArgs
265 , ldBuilderArgs
266 , makeBuilderArgs
267 , runTestBuilderArgs
268 , validateBuilderArgs
269 , xelatexBuilderArgs
270 -- Generic builders from the Hadrian library:
271 , builder (Ar Pack ) ? Hadrian.Builder.Ar.args Pack
272 , builder (Ar Unpack ) ? Hadrian.Builder.Ar.args Unpack
273 , builder (Sphinx Html ) ? Hadrian.Builder.Sphinx.args Html
274 , builder (Sphinx Latex) ? Hadrian.Builder.Sphinx.args Latex
275 , builder (Sphinx Man ) ? Hadrian.Builder.Sphinx.args Man
276 , builder (Tar Create ) ? Hadrian.Builder.Tar.args Create
277 , builder (Tar Extract ) ? Hadrian.Builder.Tar.args Extract ]
278
279 -- | All 'Package'-dependent command line arguments.
280 defaultPackageArgs :: Args
281 defaultPackageArgs = mconcat [ packageArgs, warningArgs ]