Flavour.hs 3.76 KB
Newer Older
1
2
3
module Flavour
  ( Flavour (..), werror
  , DocTargets, DocTarget(..)
4
5
    -- * Flavour transformers
  , addArgs
6
  , splitSections, splitSectionsIf
7
  , enableDebugInfo
8
  ) where
Andrey Mokhov's avatar
Andrey Mokhov committed
9
10

import Expression
11
import Data.Set (Set)
12
import Packages
Andrey Mokhov's avatar
Andrey Mokhov committed
13

Andrey Mokhov's avatar
Andrey Mokhov committed
14
-- Please update doc/{flavours.md, user-settings.md} when changing this file.
Andrey Mokhov's avatar
Andrey Mokhov committed
15
-- | 'Flavour' is a collection of build settings that fully define a GHC build.
Andrey Mokhov's avatar
Andrey Mokhov committed
16
17
18
19
20
-- Note the following type semantics:
-- * @Bool@: a plain Boolean flag whose value is known at compile time.
-- * @Action Bool@: a flag whose value can depend on the build environment.
-- * @Predicate@: a flag whose value can depend on the build environment and
-- on the current build target.
Andrey Mokhov's avatar
Andrey Mokhov committed
21
data Flavour = Flavour {
Andrey Mokhov's avatar
Andrey Mokhov committed
22
    -- | Flavour name, to select this flavour from command line.
Andrey Mokhov's avatar
Andrey Mokhov committed
23
24
25
26
27
28
29
30
31
32
33
34
    name :: String,
    -- | Use these command line arguments.
    args :: Args,
    -- | Build these packages.
    packages :: Stage -> Action [Package],
    -- | Either 'integerGmp' or 'integerSimple'.
    integerLibrary :: Action Package,
    -- | Build libraries these ways.
    libraryWays :: Ways,
    -- | Build RTS these ways.
    rtsWays :: Ways,
    -- | Build dynamic GHC programs.
35
    dynamicGhcPrograms :: Action Bool,
Andrey Mokhov's avatar
Andrey Mokhov committed
36
37
38
39
    -- | Enable GHCi debugger.
    ghciWithDebugger :: Bool,
    -- | Build profiled GHC.
    ghcProfiled :: Bool,
40
    -- | Build GHC with debugging assertions.
41
42
43
44
    ghcDebugged :: Bool,
    -- | Whether to build docs and which ones
    --   (haddocks, user manual, haddock manual)
    ghcDocs :: Action DocTargets }
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- | A set of documentation targets
type DocTargets = Set DocTarget

-- | Documentation targets
--
--   While we can't reasonably expose settings or CLI options
--   to selectively disable, say, base's haddocks, we can offer
--   a less fine-grained choice:
--
--   - haddocks for libraries
--   - non-haddock html pages (e.g GHC's user manual)
--   - PDF documents (e.g haddock's manual)
--   - man pages (GHC's)
--
--   The main goal being to have easy ways to do away with the need
--   for e.g @sphinx-build@ or @xelatex@ and associated packages
--   while still being able to build a(n almost) complete binary
--   distribution.
64
data DocTarget = Haddocks | SphinxHTML | SphinxPDFs | SphinxMan | SphinxInfo
65
  deriving (Eq, Ord, Show, Bounded, Enum)
66

67
68
69
70
-- | Add arguments to the 'args' of a 'Flavour'.
addArgs :: Args -> Flavour -> Flavour
addArgs args' fl = fl { args = args fl <> args' }

71
72
73
-- | Turn on -Werror for packages built with the stage1 compiler.
-- It mimics the CI settings so is useful to turn on when developing.
werror :: Flavour -> Flavour
74
75
76
77
78
79
80
81
werror = addArgs (builder Ghc ? notStage0 ? arg "-Werror")

-- | Build C and Haskell objects with debugging information.
enableDebugInfo :: Flavour -> Flavour
enableDebugInfo = addArgs $ mconcat
    [ builder (Ghc CompileHs) ? notStage0 ? arg "-g3"
    , builder (Cc CompileC) ? notStage0 ? arg "-g3"
    ]
82
83
84
85
86
87
88
89
90

-- | Transform the input 'Flavour' so as to build with
--   @-split-sections@ whenever appropriate. You can
--   select which package gets built with split sections
--   by passing a suitable predicate. If the predicate holds
--   for a given package, then @split-sections@ is used when
--   building it. If the given flavour doesn't build
--   anything in a @dyn@-enabled way, then 'splitSections' is a no-op.
splitSectionsIf :: (Package -> Bool) -> Flavour -> Flavour
91
92
93
94
95
splitSectionsIf pkgPredicate = addArgs $ do
    way <- getWay
    pkg <- getPackage
    (Dynamic `wayUnit` way) ? pkgPredicate pkg ?
        builder (Ghc CompileHs) ? arg "-split-sections"
96
97
98
99
100
101
102

-- | Like 'splitSectionsIf', but with a fixed predicate: use
--   split sections for all packages but the GHC library.
splitSections :: Flavour -> Flavour
splitSections = splitSectionsIf (/=ghc)
-- Disable section splitting for the GHC library. It takes too long and
-- there is little benefit.