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