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