18e0d43d6d735462bfc52a1ab8db197c0759a023
[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.Tar
9
10 import CommandLine
11 import Expression
12 import Flavour
13 import Oracles.Flag
14 import Oracles.PackageData
15 import Oracles.Setting
16 import Settings
17 import Settings.Builders.Alex
18 import Settings.Builders.DeriveConstants
19 import Settings.Builders.Cc
20 import Settings.Builders.Configure
21 import Settings.Builders.GenPrimopCode
22 import Settings.Builders.Ghc
23 import Settings.Builders.GhcCabal
24 import Settings.Builders.GhcPkg
25 import Settings.Builders.Haddock
26 import Settings.Builders.Happy
27 import Settings.Builders.Hsc2Hs
28 import Settings.Builders.HsCpp
29 import Settings.Builders.Ld
30 import Settings.Builders.Make
31 import Settings.Builders.Sphinx
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 , ghcCabalBuilderArgs
152 , ghcCBuilderArgs
153 , ghcMBuilderArgs
154 , ghcPkgBuilderArgs
155 , haddockBuilderArgs
156 , happyBuilderArgs
157 , hsc2hsBuilderArgs
158 , hsCppBuilderArgs
159 , ldBuilderArgs
160 , makeBuilderArgs
161 , sphinxBuilderArgs
162 , builder (Tar Create ) ? Hadrian.Builder.Tar.args Create
163 , builder (Tar Extract) ? Hadrian.Builder.Tar.args Extract
164 , xelatexBuilderArgs ]
165
166 -- TODO: Disable warnings for Windows specifics.
167 -- TODO: Move this elsewhere?
168 -- ref: mk/warnings.mk
169 -- | Disable warnings in packages we use.
170 disableWarningArgs :: Args
171 disableWarningArgs = builder Ghc ? mconcat
172 [ stage0 ? mconcat
173 [ package terminfo ? pure [ "-fno-warn-unused-imports" ]
174 , package transformers ? pure [ "-fno-warn-unused-matches"
175 , "-fno-warn-unused-imports" ]
176 , libraryPackage ? pure [ "-fno-warn-deprecated-flags" ] ]
177
178 , notStage0 ? mconcat
179 [ package base ? pure [ "-Wno-trustworthy-safe" ]
180 , package binary ? pure [ "-Wno-deprecations" ]
181 , package bytestring ? pure [ "-Wno-inline-rule-shadowing" ]
182 , package directory ? pure [ "-Wno-unused-imports" ]
183 , package ghcPrim ? pure [ "-Wno-trustworthy-safe" ]
184 , package haddock ? pure [ "-Wno-unused-imports"
185 , "-Wno-deprecations" ]
186 , package haskeline ? pure [ "-Wno-deprecations"
187 , "-Wno-unused-imports"
188 , "-Wno-redundant-constraints"
189 , "-Wno-simplifiable-class-constraints" ]
190 , package pretty ? pure [ "-Wno-unused-imports" ]
191 , package primitive ? pure [ "-Wno-unused-imports"
192 , "-Wno-deprecations" ]
193 , package terminfo ? pure [ "-Wno-unused-imports" ]
194 , package transformers ? pure [ "-Wno-unused-matches"
195 , "-Wno-unused-imports"
196 , "-Wno-redundant-constraints"
197 , "-Wno-orphans" ]
198 , package win32 ? pure [ "-Wno-trustworthy-safe" ]
199 , package xhtml ? pure [ "-Wno-unused-imports"
200 , "-Wno-tabs" ]
201 , libraryPackage ? pure [ "-Wno-deprecated-flags" ] ] ]
202
203 -- | All 'Package'-dependent command line arguments.
204 defaultPackageArgs :: Args
205 defaultPackageArgs = mconcat
206 [ basePackageArgs
207 , cabalPackageArgs
208 , compilerPackageArgs
209 , ghcPackageArgs
210 , ghcCabalPackageArgs
211 , ghciPackageArgs
212 , ghcPrimPackageArgs
213 , haddockPackageArgs
214 , integerGmpPackageArgs
215 , rtsPackageArgs
216 , runGhcPackageArgs
217 , disableWarningArgs
218 , ghcPkgPackageArgs
219 , haskelinePackageArgs ]