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