35bc1ac28beebf597525e2f1752144b808e80ee3
[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 CommandLine
8 import Expression
9 import Flavour
10 import Oracles.Flag
11 import Settings
12 import Settings.Builders.Alex
13 import Settings.Builders.DeriveConstants
14 import Settings.Builders.Cc
15 import Settings.Builders.Configure
16 import Settings.Builders.GenPrimopCode
17 import Settings.Builders.Ghc
18 import Settings.Builders.GhcCabal
19 import Settings.Builders.GhcPkg
20 import Settings.Builders.Haddock
21 import Settings.Builders.Happy
22 import Settings.Builders.Hsc2Hs
23 import Settings.Builders.HsCpp
24 import Settings.Builders.Ld
25 import Settings.Builders.Make
26 import Settings.Builders.RunTest
27 import Settings.Builders.Xelatex
28 import Settings.Packages
29 import Settings.Packages.Rts
30 import Settings.Warnings
31
32 import {-# SOURCE #-} Builder
33 import GHC
34 import qualified Hadrian.Builder.Ar
35 import qualified Hadrian.Builder.Sphinx
36 import qualified Hadrian.Builder.Tar
37 import Hadrian.Haskell.Cabal.PackageData as PD
38
39 -- TODO: Move C source arguments here
40 -- | Default and package-specific source arguments.
41 data SourceArgs = SourceArgs
42 { hsDefault :: Args
43 , hsLibrary :: Args
44 , hsCompiler :: Args
45 , hsGhc :: Args }
46
47 -- | Concatenate source arguments in appropriate order.
48 sourceArgs :: SourceArgs -> Args
49 sourceArgs SourceArgs {..} = builder Ghc ? mconcat
50 [ hsDefault
51 , getPackageData PD.hcOpts
52 , libraryPackage ? hsLibrary
53 , package compiler ? hsCompiler
54 , package ghc ? hsGhc ]
55
56 -- | All default command line arguments.
57 defaultArgs :: Args
58 defaultArgs = mconcat
59 [ defaultBuilderArgs
60 , sourceArgs defaultSourceArgs
61 , defaultPackageArgs ]
62
63 -- | Default source arguments, e.g. optimisation settings.
64 defaultSourceArgs :: SourceArgs
65 defaultSourceArgs = SourceArgs
66 { hsDefault = mconcat [ stage0 ? arg "-O"
67 , notStage0 ? arg "-O2"
68 , arg "-H32m" ]
69 , hsLibrary = mempty
70 , hsCompiler = mempty
71 , hsGhc = mempty }
72
73 -- | Default build ways for library packages:
74 -- * We always build 'vanilla' way.
75 -- * We build 'profiling' way when stage > Stage0.
76 -- * We build 'dynamic' way when stage > Stage0 and the platform supports it.
77 defaultLibraryWays :: Ways
78 defaultLibraryWays = mconcat
79 [ pure [vanilla]
80 , notStage0 ? pure [profiling]
81 -- , notStage0 ? platformSupportsSharedLibs ? pure [dynamic]
82 ]
83
84 -- | Default build ways for the RTS.
85 defaultRtsWays :: Ways
86 defaultRtsWays = do
87 ways <- getLibraryWays
88 mconcat
89 [ pure [ logging, debug, threaded, threadedDebug, threadedLogging ]
90 , (profiling `elem` ways) ? pure [threadedProfiling]
91 {- , (dynamic `elem` ways) ?
92 pure [ dynamic, debugDynamic, threadedDynamic, threadedDebugDynamic
93 , loggingDynamic, threadedLoggingDynamic ] -}
94 ]
95
96 -- Please update doc/flavours.md when changing the default build flavour.
97 -- | Default build flavour. Other build flavours are defined in modules
98 -- @Settings.Flavours.*@. Users can add new build flavours in "UserSettings".
99 defaultFlavour :: Flavour
100 defaultFlavour = Flavour
101 { name = "default"
102 , args = defaultArgs
103 , packages = defaultPackages
104 , integerLibrary = (\x -> if x then integerSimple else integerGmp) <$> cmdIntegerSimple
105 , libraryWays = defaultLibraryWays
106 , rtsWays = defaultRtsWays
107 , splitObjects = defaultSplitObjects
108 , dynamicGhcPrograms = False
109 , ghciWithDebugger = False
110 , ghcProfiled = False
111 , ghcDebugged = False }
112
113 -- | Default condition for building split objects.
114 defaultSplitObjects :: Predicate
115 defaultSplitObjects = do
116 goodStage <- notStage0 -- We don't split bootstrap (stage 0) packages
117 pkg <- getPackage
118 supported <- expr supportsSplitObjects
119 split <- expr cmdSplitObjects
120 let goodPackage = isLibrary pkg && pkg /= compiler && pkg /= rts
121 return $ split && goodStage && goodPackage && supported
122
123 -- | All 'Builder'-dependent command line arguments.
124 defaultBuilderArgs :: Args
125 defaultBuilderArgs = mconcat
126 -- GHC-specific builders:
127 [ alexBuilderArgs
128 , ccBuilderArgs
129 , configureBuilderArgs
130 , deriveConstantsBuilderArgs
131 , genPrimopCodeBuilderArgs
132 , ghcBuilderArgs
133 , ghcCabalBuilderArgs
134 , ghcPkgBuilderArgs
135 , haddockBuilderArgs
136 , happyBuilderArgs
137 , hsc2hsBuilderArgs
138 , hsCppBuilderArgs
139 , ldBuilderArgs
140 , makeBuilderArgs
141 , runTestBuilderArgs
142 , validateBuilderArgs
143 , xelatexBuilderArgs
144 -- Generic builders from the Hadrian library:
145 , builder (Ar Pack ) ? Hadrian.Builder.Ar.args Pack
146 , builder (Ar Unpack ) ? Hadrian.Builder.Ar.args Unpack
147 , builder (Sphinx Html ) ? Hadrian.Builder.Sphinx.args Html
148 , builder (Sphinx Latex) ? Hadrian.Builder.Sphinx.args Latex
149 , builder (Sphinx Man ) ? Hadrian.Builder.Sphinx.args Man
150 , builder (Tar Create ) ? Hadrian.Builder.Tar.args Create
151 , builder (Tar Extract ) ? Hadrian.Builder.Tar.args Extract ]
152
153 -- | All 'Package'-dependent command line arguments.
154 defaultPackageArgs :: Args
155 defaultPackageArgs = mconcat
156 [ packageArgs
157 , rtsPackageArgs
158 , warningArgs ]