Default.hs 5.7 KB
Newer Older
Andrey Mokhov's avatar
Andrey Mokhov committed
1
module Settings.Default (
Andrey Mokhov's avatar
Andrey Mokhov committed
2
    SourceArgs (..), sourceArgs, defaultBuilderArgs, defaultPackageArgs,
Andrey Mokhov's avatar
Andrey Mokhov committed
3
    defaultArgs, defaultLibraryWays, defaultRtsWays,
Andrey Mokhov's avatar
Andrey Mokhov committed
4
    defaultFlavour, defaultSplitObjects
Andrey Mokhov's avatar
Andrey Mokhov committed
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
Andrey Mokhov's avatar
Andrey Mokhov committed
13
import Flavour
14
import Oracles.Flag
Andrey Mokhov's avatar
Andrey Mokhov committed
15
import Oracles.PackageData
Andrey Mokhov's avatar
Andrey Mokhov committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
import Settings
import Settings.Builders.Alex
import Settings.Builders.DeriveConstants
import Settings.Builders.Cc
import Settings.Builders.Configure
import Settings.Builders.GenPrimopCode
import Settings.Builders.Ghc
import Settings.Builders.GhcCabal
import Settings.Builders.GhcPkg
import Settings.Builders.Haddock
import Settings.Builders.Happy
import Settings.Builders.Hsc2Hs
import Settings.Builders.HsCpp
import Settings.Builders.Ld
import Settings.Builders.Make
31
import Settings.Builders.Xelatex
Andrey Mokhov's avatar
Andrey Mokhov committed
32
import Settings.Packages.Base
33
import Settings.Packages.Cabal
Andrey Mokhov's avatar
Andrey Mokhov committed
34 35 36
import Settings.Packages.Compiler
import Settings.Packages.Ghc
import Settings.Packages.GhcCabal
37
import Settings.Packages.Ghci
Zhen Zhang's avatar
Zhen Zhang committed
38
import Settings.Packages.GhcPkg
Andrey Mokhov's avatar
Andrey Mokhov committed
39 40
import Settings.Packages.GhcPrim
import Settings.Packages.Haddock
41
import Settings.Packages.Haskeline
Andrey Mokhov's avatar
Andrey Mokhov committed
42 43 44
import Settings.Packages.IntegerGmp
import Settings.Packages.Rts
import Settings.Packages.RunGhc
45
import Settings.Warnings
46

Andrey Mokhov's avatar
Andrey Mokhov committed
47 48 49 50 51 52 53 54 55 56
-- TODO: Move C source arguments here
-- | Default and package-specific source arguments.
data SourceArgs = SourceArgs
    { hsDefault  :: Args
    , hsLibrary  :: Args
    , hsCompiler :: Args
    , hsGhc      :: Args }

-- | Concatenate source arguments in appropriate order.
sourceArgs :: SourceArgs -> Args
Andrey Mokhov's avatar
Andrey Mokhov committed
57 58
sourceArgs SourceArgs {..} = builder Ghc ? mconcat
    [ hsDefault
Andrey Mokhov's avatar
Andrey Mokhov committed
59
    , getPkgDataList HsArgs
Andrey Mokhov's avatar
Andrey Mokhov committed
60 61 62
    , libraryPackage   ? hsLibrary
    , package compiler ? hsCompiler
    , package ghc      ? hsGhc ]
Andrey Mokhov's avatar
Andrey Mokhov committed
63

Andrey Mokhov's avatar
Andrey Mokhov committed
64 65
-- | All default command line arguments.
defaultArgs :: Args
Andrey Mokhov's avatar
Andrey Mokhov committed
66 67
defaultArgs = mconcat
    [ defaultBuilderArgs
68
    , sourceArgs defaultSourceArgs
Andrey Mokhov's avatar
Andrey Mokhov committed
69
    , defaultPackageArgs ]
Andrey Mokhov's avatar
Andrey Mokhov committed
70

Andrey Mokhov's avatar
Andrey Mokhov committed
71
-- | Default source arguments, e.g. optimisation settings.
72 73
defaultSourceArgs :: SourceArgs
defaultSourceArgs = SourceArgs
Andrey Mokhov's avatar
Andrey Mokhov committed
74
    { hsDefault  = mconcat [ stage0    ? arg "-O"
Zhen Zhang's avatar
Zhen Zhang committed
75
                           , notStage0 ? arg "-O2"
76
                           , arg "-H32m" ]
Andrey Mokhov's avatar
Andrey Mokhov committed
77 78 79 80
    , hsLibrary  = mempty
    , hsCompiler = mempty
    , hsGhc      = mempty }

Andrey Mokhov's avatar
Andrey Mokhov committed
81 82 83 84 85 86
-- | Default build ways for library packages:
-- * We always build 'vanilla' way.
-- * We build 'profiling' way when stage > Stage0.
-- * We build 'dynamic' way when stage > Stage0 and the platform supports it.
defaultLibraryWays :: Ways
defaultLibraryWays = mconcat
Andrey Mokhov's avatar
Andrey Mokhov committed
87 88 89
    [ pure [vanilla]
    , notStage0 ? pure [profiling]
    , notStage0 ? platformSupportsSharedLibs ? pure [dynamic] ]
Andrey Mokhov's avatar
Andrey Mokhov committed
90 91 92 93 94 95

-- | Default build ways for the RTS.
defaultRtsWays :: Ways
defaultRtsWays = do
    ways <- getLibraryWays
    mconcat
Andrey Mokhov's avatar
Andrey Mokhov committed
96 97
        [ pure [ logging, debug, threaded, threadedDebug, threadedLogging ]
        , (profiling `elem` ways) ? pure [threadedProfiling]
Andrey Mokhov's avatar
Andrey Mokhov committed
98
        , (dynamic `elem` ways) ?
Andrey Mokhov's avatar
Andrey Mokhov committed
99
          pure [ dynamic, debugDynamic, threadedDynamic, threadedDebugDynamic
Andrey Mokhov's avatar
Andrey Mokhov committed
100 101
                 , loggingDynamic, threadedLoggingDynamic ] ]

102
-- Please update doc/flavours.md when changing the default build flavour.
Andrey Mokhov's avatar
Andrey Mokhov committed
103 104 105 106 107 108 109
-- | Default build flavour. Other build flavours are defined in modules
-- @Settings.Flavours.*@. Users can add new build flavours in "UserSettings".
defaultFlavour :: Flavour
defaultFlavour = Flavour
    { name               = "default"
    , args               = defaultArgs
    , packages           = defaultPackages
110
    , integerLibrary     = (\x -> if x then integerSimple else integerGmp) <$> cmdIntegerSimple
Andrey Mokhov's avatar
Andrey Mokhov committed
111 112 113 114 115 116 117 118 119
    , libraryWays        = defaultLibraryWays
    , rtsWays            = defaultRtsWays
    , splitObjects       = defaultSplitObjects
    , dynamicGhcPrograms = False
    , ghciWithDebugger   = False
    , ghcProfiled        = False
    , ghcDebugged        = False }

-- | Default condition for building split objects.
120 121 122 123
defaultSplitObjects :: Predicate
defaultSplitObjects = do
    goodStage <- notStage0 -- We don't split bootstrap (stage 0) packages
    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
Andrey Mokhov's avatar
Andrey Mokhov committed
128 129 130 131

-- | All 'Builder'-dependent command line arguments.
defaultBuilderArgs :: Args
defaultBuilderArgs = mconcat
132
    -- GHC-specific builders:
Andrey Mokhov's avatar
Andrey Mokhov committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146
    [ alexBuilderArgs
    , ccBuilderArgs
    , configureBuilderArgs
    , deriveConstantsBuilderArgs
    , genPrimopCodeBuilderArgs
    , ghcBuilderArgs
    , ghcCabalBuilderArgs
    , ghcPkgBuilderArgs
    , haddockBuilderArgs
    , happyBuilderArgs
    , hsc2hsBuilderArgs
    , hsCppBuilderArgs
    , ldBuilderArgs
    , makeBuilderArgs
147 148 149 150 151 152 153 154 155
    , xelatexBuilderArgs
    -- Generic builders from the Hadrian library:
    , builder (Ar Pack     ) ? Hadrian.Builder.Ar.args Pack
    , builder (Ar Unpack   ) ? Hadrian.Builder.Ar.args Unpack
    , builder (Sphinx Html ) ? Hadrian.Builder.Sphinx.args Html
    , builder (Sphinx Latex) ? Hadrian.Builder.Sphinx.args Latex
    , builder (Sphinx Man  ) ? Hadrian.Builder.Sphinx.args Man
    , builder (Tar Create  ) ? Hadrian.Builder.Tar.args Create
    , builder (Tar Extract ) ? Hadrian.Builder.Tar.args Extract ]
Andrey Mokhov's avatar
Andrey Mokhov committed
156 157 158 159 160

-- | All 'Package'-dependent command line arguments.
defaultPackageArgs :: Args
defaultPackageArgs = mconcat
    [ basePackageArgs
161
    , cabalPackageArgs
Andrey Mokhov's avatar
Andrey Mokhov committed
162 163
    , compilerPackageArgs
    , ghcCabalPackageArgs
164
    , ghciPackageArgs
165 166
    , ghcPackageArgs
    , ghcPkgPackageArgs
Andrey Mokhov's avatar
Andrey Mokhov committed
167 168
    , ghcPrimPackageArgs
    , haddockPackageArgs
169
    , haskelinePackageArgs
Andrey Mokhov's avatar
Andrey Mokhov committed
170 171
    , integerGmpPackageArgs
    , rtsPackageArgs
Zhen Zhang's avatar
Zhen Zhang committed
172
    , runGhcPackageArgs
173
    , warningArgs ]