GhcCabal.hs 4.89 KB
Newer Older
1
module Settings.GhcCabal (
2
    cabalSettings, bootPackageDbSettings, customPackageSettings
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    ) where

import Base hiding (arg, args)
import Oracles.Base
import Oracles.Builder
import Ways
import Util
import Package
import Targets
import Switches
import Expression hiding (when, liftIO)
import Settings.Ways
import Settings.Util
import Settings.Packages
17
import Settings.TargetDirectory
18
import UserSettings
19
20

cabalSettings :: Settings
Andrey Mokhov's avatar
Andrey Mokhov committed
21
cabalSettings = builder GhcCabal ? do
22
23
24
25
26
27
    stage <- asks getStage
    pkg   <- asks getPackage
    mconcat [ arg "configure"
            , arg $ pkgPath pkg
            , arg $ targetDirectory stage pkg
            , dllSettings
Andrey Mokhov's avatar
Andrey Mokhov committed
28
29
            , argWith $ Ghc stage
            , argWith $ GhcPkg stage
30
            , stage0 ? bootPackageDbSettings
31
            , librarySettings
Andrey Mokhov's avatar
Andrey Mokhov committed
32
            , configKeyNonEmpty "hscolour" ? argWith HsColour -- TODO: generalise?
33
            , configureSettings
34
            , stage0 ? packageConstraints
Andrey Mokhov's avatar
Andrey Mokhov committed
35
36
37
38
39
            , argWith $ Gcc stage
            , notStage Stage0 ? argWith Ld
            , argWith Ar
            , argWith Alex
            , argWith Happy ] -- TODO: reorder argWiths
40
41
42
43

-- TODO: Isn't vanilla always built? If yes, some conditions are redundant.
librarySettings :: Settings
librarySettings = do
44
    ways            <- fromDiffExpr Settings.Ways.ways
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
    ghcInterpreter  <- ghcWithInterpreter
    dynamicPrograms <- dynamicGhcPrograms
    append [ if vanilla `elem` ways
             then  "--enable-library-vanilla"
             else "--disable-library-vanilla"
           , if vanilla `elem` ways && ghcInterpreter && not dynamicPrograms
             then  "--enable-library-for-ghci"
             else "--disable-library-for-ghci"
           , if profiling `elem` ways
             then  "--enable-library-profiling"
             else "--disable-library-profiling"
           , if dynamic `elem` ways
             then  "--enable-shared"
             else "--disable-shared" ]

configureSettings :: Settings
configureSettings = do
62
    stage <- asks getStage
Andrey Mokhov's avatar
Andrey Mokhov committed
63
64
65
66
67
68
    let conf key = appendSubD $ "--configure-option=" ++ key
        cFlags   = mconcat [ ccSettings
                           , remove ["-Werror"]
                           , argStagedConfig "conf-cc-args" ]
        ldFlags  = ldSettings <> argStagedConfig "conf-gcc-linker-args"
        cppFlags = cppSettings <> argStagedConfig "conf-cpp-args"
69
    mconcat
Andrey Mokhov's avatar
Andrey Mokhov committed
70
71
72
73
        [ conf "CFLAGS"   cFlags
        , conf "LDFLAGS"  ldFlags
        , conf "CPPFLAGS" cppFlags
        , appendSubD "--gcc-options" $ cFlags <> ldFlags
74
75
76
77
78
79
80
81
82
83
84
85
86
        , conf "--with-iconv-includes"  $ argConfig "iconv-include-dirs"
        , conf "--with-iconv-libraries" $ argConfig "iconv-lib-dirs"
        , conf "--with-gmp-includes"    $ argConfig "gmp-include-dirs"
        , conf "--with-gmp-libraries"   $ argConfig "gmp-lib-dirs"
        -- TODO: why TargetPlatformFull and not host?
        , crossCompiling ? (conf "--host" $ argConfig "target-platform-full")
        , conf "--with-cc" . argM . showArg $ Gcc stage ]

bootPackageDbSettings :: Settings
bootPackageDbSettings = do
    sourcePath <- lift $ askConfig "ghc-source-path"
    arg $ "--package-db=" ++ sourcePath </> "libraries/bootstrapping.conf"

Andrey Mokhov's avatar
Andrey Mokhov committed
87
88
89
-- this is a positional argument, hence:
-- * if it is empty, we need to emit one empty string argument
-- * otherwise, we must collapse it into one space-separated string
90
91
92
93
94
dllSettings :: Settings
dllSettings = arg ""

packageConstraints :: Settings
packageConstraints = do
95
    pkgs <- fromDiffExpr packages
96
97
98
99
100
101
102
103
104
105
106
107
    constraints <- lift $ forM pkgs $ \pkg -> do
        let cabal  = pkgPath pkg </> pkgCabal pkg
            prefix = dropExtension (pkgCabal pkg) ++ " == "
        need [cabal]
        content <- lines <$> liftIO (readFile cabal)
        let vs = filter (("ersion:" `isPrefixOf`) . drop 1) content
        case vs of
            [v] -> return $ prefix ++ dropWhile (not . isDigit) v
            _   -> redError $ "Cannot determine package version in '"
                            ++ cabal ++ "'."
    args $ concatMap (\c -> ["--constraint", c]) $ constraints

108
-- TODO: should be in a different file
109
ccSettings :: Settings
110
ccSettings = validating ? do
111
    let gccGe46 = liftM not gccLt46
112
    mconcat [ arg "-Werror"
113
114
115
116
117
118
119
            , arg "-Wall"
            , gccIsClang ??
              ( arg "-Wno-unknown-pragmas" <>
                gccGe46 ? windowsHost ? arg "-Werror=unused-but-set-variable"
              , gccGe46 ? arg "-Wno-error=inline" )]

ldSettings :: Settings
Andrey Mokhov's avatar
Andrey Mokhov committed
120
ldSettings = mempty
121
122

cppSettings :: Settings
Andrey Mokhov's avatar
Andrey Mokhov committed
123
cppSettings = mempty
124
125
126
127
128
129
130
131
132
133
134
135
136

customPackageSettings :: Settings
customPackageSettings = mconcat
    [ package integerGmp2 ?
      mconcat [ windowsHost ? builder GhcCabal ?
                arg "--configure-option=--with-intree-gmp"
              , ccArgs ["-Ilibraries/integer-gmp2/gmp"] ]

    , package base ?
      builder GhcCabal ? arg ("--flags=" ++ pkgName integerLibrary)

    , package ghcPrim ?
      builder GhcCabal ? arg "--flag=include-ghc-prim" ]