GhcCabal.hs 4.47 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module Settings.GhcCabal (
    cabalSettings, bootPackageDbSettings
    ) 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 UserSettings
18
19

cabalSettings :: Settings
Andrey Mokhov's avatar
Andrey Mokhov committed
20
cabalSettings = builder GhcCabal ? do
21
22
23
24
25
26
27
28
    stage <- asks getStage
    pkg   <- asks getPackage
    mconcat [ arg "configure"
            , arg $ pkgPath pkg
            , arg $ targetDirectory stage pkg
            , dllSettings
            , with' $ Ghc stage
            , with' $ GhcPkg stage
29
            , stage0 ? bootPackageDbSettings
30
31
32
            , librarySettings
            , configKeyNonEmpty "hscolour" ? with' HsColour -- TODO: generalise?
            , configureSettings
33
            , stage0 ? packageConstraints
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
            , with' $ Gcc stage
            , notStage Stage0 ? with' Ld
            , with' Ar
            , with' Alex
            , with' Happy ] -- TODO: reorder with's

-- TODO: Isn't vanilla always built? If yes, some conditions are redundant.
librarySettings :: Settings
librarySettings = do
    ways            <- fromDiff Settings.Ways.ways
    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
61
    stage <- asks getStage
Andrey Mokhov's avatar
Andrey Mokhov committed
62
63
64
65
66
67
    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"
68
    mconcat
Andrey Mokhov's avatar
Andrey Mokhov committed
69
70
71
72
        [ conf "CFLAGS"   cFlags
        , conf "LDFLAGS"  ldFlags
        , conf "CPPFLAGS" cppFlags
        , appendSubD "--gcc-options" $ cFlags <> ldFlags
73
74
75
76
77
78
79
80
81
82
83
84
85
        , 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
86
87
88
-- 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
89
90
91
dllSettings :: Settings
dllSettings = arg ""

92
-- TODO: remove
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
with' :: Builder -> Settings
with' builder = appendM $ with builder

packageConstraints :: Settings
packageConstraints = do
    pkgs <- fromDiff packages
    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

111
-- TODO: should be in a different file
112
ccSettings :: Settings
113
ccSettings = validating ? do
114
    let gccGe46 = liftM not gccLt46
115
    mconcat [ arg "-Werror"
116
117
118
119
120
121
122
            , 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
123
ldSettings = mempty
124
125

cppSettings :: Settings
Andrey Mokhov's avatar
Andrey Mokhov committed
126
cppSettings = mempty