5dde31b4e4dd14acd2294352251935266f91ad7a
[ghc.git] / src / Settings / Default.hs
1 module Settings.Default (
2 SourceArgs (..), sourceArgs, defaultBuilderArgs, defaultPackageArgs,
3 defaultArgs, defaultLibraryWays, defaultRtsWays,
4 defaultFlavour, defaultSplitObjects
5 ) where
6
7 import qualified Hadrian.Builder.Ar
8 import qualified Hadrian.Builder.Sphinx
9 import qualified Hadrian.Builder.Tar
10
11 import CommandLine
12 import Expression
13 import Flavour
14 import Oracles.Flag
15 import Oracles.PackageData
16 import Oracles.Setting
17 import Settings
18 import Settings.Builders.Alex
19 import Settings.Builders.DeriveConstants
20 import Settings.Builders.Cc
21 import Settings.Builders.Configure
22 import Settings.Builders.GenPrimopCode
23 import Settings.Builders.Ghc
24 import Settings.Builders.GhcCabal
25 import Settings.Builders.GhcPkg
26 import Settings.Builders.Haddock
27 import Settings.Builders.Happy
28 import Settings.Builders.Hsc2Hs
29 import Settings.Builders.HsCpp
30 import Settings.Builders.Ld
31 import Settings.Builders.Make
32 import Settings.Builders.Xelatex
33 import Settings.Packages.Base
34 import Settings.Packages.Cabal
35 import Settings.Packages.Compiler
36 import Settings.Packages.Ghc
37 import Settings.Packages.GhcCabal
38 import Settings.Packages.Ghci
39 import Settings.Packages.GhcPkg
40 import Settings.Packages.GhcPrim
41 import Settings.Packages.Haddock
42 import Settings.Packages.Haskeline
43 import Settings.Packages.IntegerGmp
44 import Settings.Packages.Rts
45 import Settings.Packages.RunGhc
46
47 -- TODO: Move C source arguments here
48 -- | Default and package-specific source arguments.
49 data SourceArgs = SourceArgs
50 { hsDefault :: Args
51 , hsLibrary :: Args
52 , hsCompiler :: Args
53 , hsGhc :: Args }
54
55 -- | Concatenate source arguments in appropriate order.
56 sourceArgs :: SourceArgs -> Args
57 sourceArgs SourceArgs {..} = builder Ghc ? mconcat
58 [ hsDefault
59 , getPkgDataList HsArgs
60 , libraryPackage ? hsLibrary
61 , package compiler ? hsCompiler
62 , package ghc ? hsGhc ]
63
64 -- | All default command line arguments.
65 defaultArgs :: Args
66 defaultArgs = mconcat
67 [ defaultBuilderArgs
68 , sourceArgs defaultSourceArgs
69 , defaultPackageArgs ]
70
71 -- ref: mk/warnings.mk
72 -- | Default Haskell warning-related arguments.
73 defaultHsWarningsArgs :: Args
74 defaultHsWarningsArgs = mconcat
75 [ notStage0 ? arg "-Werror"
76 , (not <$> flag GccIsClang) ? mconcat
77 [ (not <$> flag GccLt46) ? (not <$> windowsHost) ? arg "-optc-Werror=unused-but-set-variable"
78 , (not <$> flag GccLt44) ? arg "-optc-Wno-error=inline" ]
79 , flag GccIsClang ? arg "-optc-Wno-unknown-pragmas" ]
80
81 -- | Default source arguments, e.g. optimisation settings.
82 defaultSourceArgs :: SourceArgs
83 defaultSourceArgs = SourceArgs
84 { hsDefault = mconcat [ stage0 ? arg "-O"
85 , notStage0 ? arg "-O2"
86 , arg "-H32m"
87 , defaultHsWarningsArgs ]
88 , hsLibrary = mempty
89 , hsCompiler = mempty
90 , hsGhc = mempty }
91
92 -- | Default build ways for library packages:
93 -- * We always build 'vanilla' way.
94 -- * We build 'profiling' way when stage > Stage0.
95 -- * We build 'dynamic' way when stage > Stage0 and the platform supports it.
96 defaultLibraryWays :: Ways
97 defaultLibraryWays = mconcat
98 [ pure [vanilla]
99 , notStage0 ? pure [profiling]
100 , notStage0 ? platformSupportsSharedLibs ? pure [dynamic] ]
101
102 -- | Default build ways for the RTS.
103 defaultRtsWays :: Ways
104 defaultRtsWays = do
105 ways <- getLibraryWays
106 mconcat
107 [ pure [ logging, debug, threaded, threadedDebug, threadedLogging ]
108 , (profiling `elem` ways) ? pure [threadedProfiling]
109 , (dynamic `elem` ways) ?
110 pure [ dynamic, debugDynamic, threadedDynamic, threadedDebugDynamic
111 , loggingDynamic, threadedLoggingDynamic ] ]
112
113 -- Please update doc/flavours.md when changing the default build flavour.
114 -- | Default build flavour. Other build flavours are defined in modules
115 -- @Settings.Flavours.*@. Users can add new build flavours in "UserSettings".
116 defaultFlavour :: Flavour
117 defaultFlavour = Flavour
118 { name = "default"
119 , args = defaultArgs
120 , packages = defaultPackages
121 , integerLibrary = (\x -> if x then integerSimple else integerGmp) <$> cmdIntegerSimple
122 , libraryWays = defaultLibraryWays
123 , rtsWays = defaultRtsWays
124 , splitObjects = defaultSplitObjects
125 , dynamicGhcPrograms = False
126 , ghciWithDebugger = False
127 , ghcProfiled = False
128 , ghcDebugged = False }
129
130 -- | Default condition for building split objects.
131 defaultSplitObjects :: Predicate
132 defaultSplitObjects = do
133 goodStage <- notStage0 -- We don't split bootstrap (stage 0) packages
134 pkg <- getPackage
135 supported <- expr supportsSplitObjects
136 split <- expr cmdSplitObjects
137 let goodPackage = isLibrary pkg && pkg /= compiler && pkg /= rts
138 return $ split && goodStage && goodPackage && supported
139
140 -- | All 'Builder'-dependent command line arguments.
141 defaultBuilderArgs :: Args
142 defaultBuilderArgs = mconcat
143 -- GHC-specific builders:
144 [ alexBuilderArgs
145 , ccBuilderArgs
146 , configureBuilderArgs
147 , deriveConstantsBuilderArgs
148 , genPrimopCodeBuilderArgs
149 , ghcBuilderArgs
150 , ghcCabalBuilderArgs
151 , ghcCBuilderArgs
152 , ghcMBuilderArgs
153 , ghcPkgBuilderArgs
154 , haddockBuilderArgs
155 , happyBuilderArgs
156 , hsc2hsBuilderArgs
157 , hsCppBuilderArgs
158 , ldBuilderArgs
159 , makeBuilderArgs
160 , xelatexBuilderArgs
161 -- Generic builders from the Hadrian library:
162 , builder (Ar Pack ) ? Hadrian.Builder.Ar.args Pack
163 , builder (Ar Unpack ) ? Hadrian.Builder.Ar.args Unpack
164 , builder (Sphinx Html ) ? Hadrian.Builder.Sphinx.args Html
165 , builder (Sphinx Latex) ? Hadrian.Builder.Sphinx.args Latex
166 , builder (Sphinx Man ) ? Hadrian.Builder.Sphinx.args Man
167 , builder (Tar Create ) ? Hadrian.Builder.Tar.args Create
168 , builder (Tar Extract ) ? Hadrian.Builder.Tar.args Extract ]
169
170 -- TODO: Disable warnings for Windows specifics.
171 -- TODO: Move this elsewhere?
172 -- ref: mk/warnings.mk
173 -- | Disable warnings in packages we use.
174 disableWarningArgs :: Args
175 disableWarningArgs = builder Ghc ? mconcat
176 [ stage0 ? mconcat
177 [ package terminfo ? pure [ "-fno-warn-unused-imports" ]
178 , package transformers ? pure [ "-fno-warn-unused-matches"
179 , "-fno-warn-unused-imports" ]
180 , libraryPackage ? pure [ "-fno-warn-deprecated-flags" ] ]
181
182 , notStage0 ? mconcat
183 [ package base ? pure [ "-Wno-trustworthy-safe" ]
184 , package binary ? pure [ "-Wno-deprecations" ]
185 , package bytestring ? pure [ "-Wno-inline-rule-shadowing" ]
186 , package directory ? pure [ "-Wno-unused-imports" ]
187 , package ghcPrim ? pure [ "-Wno-trustworthy-safe" ]
188 , package haddock ? pure [ "-Wno-unused-imports"
189 , "-Wno-deprecations" ]
190 , package haskeline ? pure [ "-Wno-deprecations"
191 , "-Wno-unused-imports"
192 , "-Wno-redundant-constraints"
193 , "-Wno-simplifiable-class-constraints" ]
194 , package pretty ? pure [ "-Wno-unused-imports" ]
195 , package primitive ? pure [ "-Wno-unused-imports"
196 , "-Wno-deprecations" ]
197 , package terminfo ? pure [ "-Wno-unused-imports" ]
198 , package transformers ? pure [ "-Wno-unused-matches"
199 , "-Wno-unused-imports"
200 , "-Wno-redundant-constraints"
201 , "-Wno-orphans" ]
202 , package win32 ? pure [ "-Wno-trustworthy-safe" ]
203 , package xhtml ? pure [ "-Wno-unused-imports"
204 , "-Wno-tabs" ]
205 , libraryPackage ? pure [ "-Wno-deprecated-flags" ] ] ]
206
207 -- | All 'Package'-dependent command line arguments.
208 defaultPackageArgs :: Args
209 defaultPackageArgs = mconcat
210 [ basePackageArgs
211 , cabalPackageArgs
212 , compilerPackageArgs
213 , ghcPackageArgs
214 , ghcCabalPackageArgs
215 , ghciPackageArgs
216 , ghcPrimPackageArgs
217 , haddockPackageArgs
218 , integerGmpPackageArgs
219 , rtsPackageArgs
220 , runGhcPackageArgs
221 , disableWarningArgs
222 , ghcPkgPackageArgs
223 , haskelinePackageArgs ]