Squashed 'hadrian/' content from commit 438dc57
[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 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.Xelatex
32 import Settings.Packages.Base
33 import Settings.Packages.Cabal
34 import Settings.Packages.Compiler
35 import Settings.Packages.Ghc
36 import Settings.Packages.GhcCabal
37 import Settings.Packages.Ghci
38 import Settings.Packages.GhcPkg
39 import Settings.Packages.GhcPrim
40 import Settings.Packages.Haddock
41 import Settings.Packages.Haskeline
42 import Settings.Packages.IntegerGmp
43 import Settings.Packages.Rts
44 import Settings.Packages.RunGhc
45 import Settings.Warnings
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 -- | Default source arguments, e.g. optimisation settings.
72 defaultSourceArgs :: SourceArgs
73 defaultSourceArgs = SourceArgs
74 { hsDefault = mconcat [ stage0 ? arg "-O"
75 , notStage0 ? arg "-O2"
76 , arg "-H32m" ]
77 , hsLibrary = mempty
78 , hsCompiler = mempty
79 , hsGhc = mempty }
80
81 -- | Default build ways for library packages:
82 -- * We always build 'vanilla' way.
83 -- * We build 'profiling' way when stage > Stage0.
84 -- * We build 'dynamic' way when stage > Stage0 and the platform supports it.
85 defaultLibraryWays :: Ways
86 defaultLibraryWays = mconcat
87 [ pure [vanilla]
88 , notStage0 ? pure [profiling]
89 , notStage0 ? platformSupportsSharedLibs ? pure [dynamic] ]
90
91 -- | Default build ways for the RTS.
92 defaultRtsWays :: Ways
93 defaultRtsWays = do
94 ways <- getLibraryWays
95 mconcat
96 [ pure [ logging, debug, threaded, threadedDebug, threadedLogging ]
97 , (profiling `elem` ways) ? pure [threadedProfiling]
98 , (dynamic `elem` ways) ?
99 pure [ dynamic, debugDynamic, threadedDynamic, threadedDebugDynamic
100 , loggingDynamic, threadedLoggingDynamic ] ]
101
102 -- Please update doc/flavours.md when changing the default build flavour.
103 -- | Default build flavour. Other build flavours are defined in modules
104 -- @Settings.Flavours.*@. Users can add new build flavours in "UserSettings".
105 defaultFlavour :: Flavour
106 defaultFlavour = Flavour
107 { name = "default"
108 , args = defaultArgs
109 , packages = defaultPackages
110 , integerLibrary = (\x -> if x then integerSimple else integerGmp) <$> cmdIntegerSimple
111 , libraryWays = defaultLibraryWays
112 , rtsWays = defaultRtsWays
113 , splitObjects = defaultSplitObjects
114 , dynamicGhcPrograms = False
115 , ghciWithDebugger = False
116 , ghcProfiled = False
117 , ghcDebugged = False }
118
119 -- | Default condition for building split objects.
120 defaultSplitObjects :: Predicate
121 defaultSplitObjects = do
122 goodStage <- notStage0 -- We don't split bootstrap (stage 0) packages
123 pkg <- getPackage
124 supported <- expr supportsSplitObjects
125 split <- expr cmdSplitObjects
126 let goodPackage = isLibrary pkg && pkg /= compiler && pkg /= rts
127 return $ split && goodStage && goodPackage && supported
128
129 -- | All 'Builder'-dependent command line arguments.
130 defaultBuilderArgs :: Args
131 defaultBuilderArgs = mconcat
132 -- GHC-specific builders:
133 [ alexBuilderArgs
134 , ccBuilderArgs
135 , configureBuilderArgs
136 , deriveConstantsBuilderArgs
137 , genPrimopCodeBuilderArgs
138 , ghcBuilderArgs
139 , ghcCabalBuilderArgs
140 , ghcPkgBuilderArgs
141 , haddockBuilderArgs
142 , happyBuilderArgs
143 , hsc2hsBuilderArgs
144 , hsCppBuilderArgs
145 , ldBuilderArgs
146 , makeBuilderArgs
147 , xelatexBuilderArgs
148 -- Generic builders from the Hadrian library:
149 , builder (Ar Pack ) ? Hadrian.Builder.Ar.args Pack
150 , builder (Ar Unpack ) ? Hadrian.Builder.Ar.args Unpack
151 , builder (Sphinx Html ) ? Hadrian.Builder.Sphinx.args Html
152 , builder (Sphinx Latex) ? Hadrian.Builder.Sphinx.args Latex
153 , builder (Sphinx Man ) ? Hadrian.Builder.Sphinx.args Man
154 , builder (Tar Create ) ? Hadrian.Builder.Tar.args Create
155 , builder (Tar Extract ) ? Hadrian.Builder.Tar.args Extract ]
156
157 -- | All 'Package'-dependent command line arguments.
158 defaultPackageArgs :: Args
159 defaultPackageArgs = mconcat
160 [ basePackageArgs
161 , cabalPackageArgs
162 , compilerPackageArgs
163 , ghcCabalPackageArgs
164 , ghciPackageArgs
165 , ghcPackageArgs
166 , ghcPkgPackageArgs
167 , ghcPrimPackageArgs
168 , haddockPackageArgs
169 , haskelinePackageArgs
170 , integerGmpPackageArgs
171 , rtsPackageArgs
172 , runGhcPackageArgs
173 , warningArgs ]