GhcCabal.hs 4.88 KB
Newer Older
1
module Settings.GhcCabal (
2
    cabalSettings, bootPackageDbSettings, customPackageSettings
3 4 5 6 7 8 9 10 11
    ) where

import Base hiding (arg, args)
import Oracles.Base
import Oracles.Builder
import Ways
import Util
import Package
import Switches
Andrey Mokhov's avatar
Andrey Mokhov committed
12
import Expression hiding (liftIO)
13
import Settings.User
14 15 16
import Settings.Ways
import Settings.Util
import Settings.Packages
17
import Settings.TargetDirectory
18 19

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

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

packageConstraints :: Settings
packageConstraints = do
94
    pkgs <- fromDiffExpr packages
95 96 97 98 99 100 101 102 103 104 105 106
    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

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
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" ]