GhcCabal.hs 5.29 KB
Newer Older
1
module Settings.GhcCabal (
2
    cabalArgs, bootPackageDbArgs, customPackageArgs
3
4
    ) where

5
import Way
6
import Base
Andrey Mokhov's avatar
Andrey Mokhov committed
7
8
import Builder
import Package
9
import Util
Andrey Mokhov's avatar
Andrey Mokhov committed
10
import Oracles.Base
11
import Switches
12
import Expression
13
import Settings.User
14
15
16
import Settings.Ways
import Settings.Util
import Settings.Packages
17
import Settings.TargetDirectory
18

19
20
cabalArgs :: Args
cabalArgs = builder GhcCabal ? do
21
22
23
    stage <- asks getStage
    pkg   <- asks getPackage
    mconcat [ arg "configure"
24
25
            , argPath $ pkgPath pkg
            , argPath $ targetDirectory stage pkg
26
            , dllArgs
Andrey Mokhov's avatar
Andrey Mokhov committed
27
28
            , with $ Ghc stage
            , with $ GhcPkg stage
29
30
            , stage0 ? bootPackageDbArgs
            , libraryArgs
Andrey Mokhov's avatar
Andrey Mokhov committed
31
            , configKeyNonEmpty "hscolour" ? with HsColour
32
            , configureArgs
33
            , stage0 ? packageConstraints
Andrey Mokhov's avatar
Andrey Mokhov committed
34
35
36
37
38
            , with $ Gcc stage
            , notStage Stage0 ? with Ld
            , with Ar
            , with Alex
            , with Happy ]
39
40

-- TODO: Isn't vanilla always built? If yes, some conditions are redundant.
41
42
libraryArgs :: Args
libraryArgs = do
43
    ways            <- fromDiffExpr Settings.Ways.ways
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
    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" ]

59
60
configureArgs :: Args
configureArgs = do
61
    stage <- asks getStage
Andrey Mokhov's avatar
Andrey Mokhov committed
62
    let conf key = appendSubD $ "--configure-option=" ++ key
63
        cFlags   = mconcat [ ccArgs
Andrey Mokhov's avatar
Andrey Mokhov committed
64
65
                           , remove ["-Werror"]
                           , argStagedConfig "conf-cc-args" ]
66
67
        ldFlags  = ldArgs <> argStagedConfig "conf-gcc-linker-args"
        cppFlags = cppArgs <> 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
        , 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")
Andrey Mokhov's avatar
Andrey Mokhov committed
79
        , conf "--with-cc" . argM . builderPath $ Gcc stage ]
80

81
82
bootPackageDbArgs :: Args
bootPackageDbArgs = do
83
84
85
    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
dllArgs :: Args
dllArgs = arg ""
91

92
packageConstraints :: Args
93
packageConstraints = do
94
    pkgs <- fromDiffExpr packages
95
96
97
98
99
100
101
102
103
104
    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 ++ "'."
105
    append $ concatMap (\c -> ["--constraint", c]) $ constraints
106

107
-- TODO: should be in a different file
Andrey Mokhov's avatar
Andrey Mokhov committed
108
-- TODO: put all validating options together in one file
109
110
ccArgs :: Args
ccArgs = validating ? do
111
    let gccGe46 = liftM not gccLt46
112
    mconcat [ arg "-Werror"
113
114
115
116
117
118
            , arg "-Wall"
            , gccIsClang ??
              ( arg "-Wno-unknown-pragmas" <>
                gccGe46 ? windowsHost ? arg "-Werror=unused-but-set-variable"
              , gccGe46 ? arg "-Wno-error=inline" )]

119
120
ldArgs :: Args
ldArgs = mempty
121

122
123
cppArgs :: Args
cppArgs = mempty
124

125
126
customPackageArgs :: Args
customPackageArgs = mconcat
127
128
129
    [ package integerGmp2 ?
      mconcat [ windowsHost ? builder GhcCabal ?
                arg "--configure-option=--with-intree-gmp"
130
              , appendCcArgs ["-Ilibraries/integer-gmp2/gmp"] ]
131
132
133
134
135
136

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

    , package ghcPrim ?
      builder GhcCabal ? arg "--flag=include-ghc-prim" ]
Andrey Mokhov's avatar
Andrey Mokhov committed
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

withBuilderKey :: Builder -> String
withBuilderKey builder = case builder of
    Ar       -> "--with-ar="
    Ld       -> "--with-ld="
    Gcc _    -> "--with-gcc="
    Ghc _    -> "--with-ghc="
    Alex     -> "--with-alex="
    Happy    -> "--with-happy="
    GhcPkg _ -> "--with-ghc-pkg="
    HsColour -> "--with-hscolour="
    _        -> error "withBuilderKey: not supported builder"

-- Expression 'with Gcc' appends "--with-gcc=/path/to/gcc" and needs Gcc.
with :: Builder -> Args
with builder = do
    path <- lift $ builderPath builder
    lift $ needBuilder builder
    append [withBuilderKey builder ++ path]