10ec84f39f95fbde3c837d9bbf04c9d4e03f72f0
[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
9 import CommandLine
10 import Expression
11 import Flavour
12 import Oracles.Flag
13 import Oracles.PackageData
14 import Oracles.Setting
15 import Settings
16 import Settings.Builders.Alex
17 import Settings.Builders.DeriveConstants
18 import Settings.Builders.Cc
19 import Settings.Builders.Configure
20 import Settings.Builders.GenPrimopCode
21 import Settings.Builders.Ghc
22 import Settings.Builders.GhcCabal
23 import Settings.Builders.GhcPkg
24 import Settings.Builders.Haddock
25 import Settings.Builders.Happy
26 import Settings.Builders.Hsc2Hs
27 import Settings.Builders.HsCpp
28 import Settings.Builders.Ld
29 import Settings.Builders.Make
30 import Settings.Builders.Sphinx
31 import Settings.Builders.Tar
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 (haskelinePackageArgs)
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 -- | Default build flavour. Other build flavours are defined in modules
114 -- @Settings.Flavours.*@. Users can add new build flavours in "UserSettings".
115 defaultFlavour :: Flavour
116 defaultFlavour = Flavour
117 { name = "default"
118 , args = defaultArgs
119 , packages = defaultPackages
120 , integerLibrary = (\x -> if x then integerSimple else integerGmp) <$> cmdIntegerSimple
121 , libraryWays = defaultLibraryWays
122 , rtsWays = defaultRtsWays
123 , splitObjects = defaultSplitObjects
124 , buildHaddock = expr cmdBuildHaddock
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 [ alexBuilderArgs
144 , builder (Ar Pack ) ? Hadrian.Builder.Ar.args Pack
145 , builder (Ar Unpack) ? Hadrian.Builder.Ar.args Unpack
146 , ccBuilderArgs
147 , configureBuilderArgs
148 , deriveConstantsBuilderArgs
149 , genPrimopCodeBuilderArgs
150 , ghcBuilderArgs
151 , ghcCbuilderArgs
152 , ghcCabalBuilderArgs
153 , ghcMBuilderArgs
154 , ghcPkgBuilderArgs
155 , haddockBuilderArgs
156 , happyBuilderArgs
157 , hsc2hsBuilderArgs
158 , hsCppBuilderArgs
159 , ldBuilderArgs
160 , makeBuilderArgs
161 , sphinxBuilderArgs
162 , tarBuilderArgs
163 , xelatexBuilderArgs ]
164
165 -- TODO: Disable warnings for Windows specifics.
166 -- TODO: Move this elsewhere?
167 -- ref: mk/warnings.mk
168 -- | Disable warnings in packages we use.
169 disableWarningArgs :: Args
170 disableWarningArgs = builder Ghc ? mconcat
171 [ stage0 ? mconcat
172 [ package terminfo ? pure [ "-fno-warn-unused-imports" ]
173 , package transformers ? pure [ "-fno-warn-unused-matches"
174 , "-fno-warn-unused-imports" ]
175 , libraryPackage ? pure [ "-fno-warn-deprecated-flags" ] ]
176
177 , notStage0 ? mconcat
178 [ package base ? pure [ "-Wno-trustworthy-safe" ]
179 , package binary ? pure [ "-Wno-deprecations" ]
180 , package bytestring ? pure [ "-Wno-inline-rule-shadowing" ]
181 , package directory ? pure [ "-Wno-unused-imports" ]
182 , package ghcPrim ? pure [ "-Wno-trustworthy-safe" ]
183 , package haddock ? pure [ "-Wno-unused-imports"
184 , "-Wno-deprecations" ]
185 , package haskeline ? pure [ "-Wno-deprecations"
186 , "-Wno-unused-imports"
187 , "-Wno-redundant-constraints"
188 , "-Wno-simplifiable-class-constraints" ]
189 , package pretty ? pure [ "-Wno-unused-imports" ]
190 , package primitive ? pure [ "-Wno-unused-imports"
191 , "-Wno-deprecations" ]
192 , package terminfo ? pure [ "-Wno-unused-imports" ]
193 , package transformers ? pure [ "-Wno-unused-matches"
194 , "-Wno-unused-imports"
195 , "-Wno-redundant-constraints"
196 , "-Wno-orphans" ]
197 , package win32 ? pure [ "-Wno-trustworthy-safe" ]
198 , package xhtml ? pure [ "-Wno-unused-imports"
199 , "-Wno-tabs" ]
200 , libraryPackage ? pure [ "-Wno-deprecated-flags" ] ] ]
201
202 -- | All 'Package'-dependent command line arguments.
203 defaultPackageArgs :: Args
204 defaultPackageArgs = mconcat
205 [ basePackageArgs
206 , cabalPackageArgs
207 , compilerPackageArgs
208 , ghcPackageArgs
209 , ghcCabalPackageArgs
210 , ghciPackageArgs
211 , ghcPrimPackageArgs
212 , haddockPackageArgs
213 , integerGmpPackageArgs
214 , rtsPackageArgs
215 , runGhcPackageArgs
216 , disableWarningArgs
217 , ghcPkgPackageArgs
218 , haskelinePackageArgs ]