Flag.hs 2.16 KB
Newer Older
Andrey Mokhov's avatar
Andrey Mokhov committed
1
module Oracles.Config.Flag (
2
    Flag (..), flag,
3
    crossCompiling, gccIsClang, gccGe46,
4
    platformSupportsSharedLibs, ghcWithSMP, ghcWithNativeCodeGen
5
6
    ) where

Andrey Mokhov's avatar
Andrey Mokhov committed
7
8
9
import Base
import Oracles.Config
import Oracles.Config.Setting
10

11
data Flag = GccIsClang
12
13
          | GccLt46
          | CrossCompiling
14
          | SupportsPackageKey
15
          | SolarisBrokenShld
16
17
          | SplitObjectsBroken
          | GhcUnregisterised
18

19
20
21
22
23
24
25
26
27
28
flag :: Flag -> Action Bool
flag f = do
    key <- return $ case f of
        GccIsClang         -> "gcc-is-clang"
        GccLt46            -> "gcc-lt-46"
        CrossCompiling     -> "cross-compiling"
        SupportsPackageKey -> "supports-package-key"
        SolarisBrokenShld  -> "solaris-broken-shld"
        SplitObjectsBroken -> "split-objects-broken"
        GhcUnregisterised  -> "ghc-unregisterised"
29
    value <- askConfigWithDefault key . putError
30
        $ "\nFlag '" ++ key ++ "' not set in configuration files."
31
    unless (value == "YES" || value == "NO") . putError
32
33
        $ "\nFlag '" ++ key ++ "' is set to '" ++ value
        ++ "' instead of 'YES' or 'NO'."
34
    return $ value == "YES"
35
36
37
38
39
40
41

crossCompiling :: Action Bool
crossCompiling = flag CrossCompiling

gccIsClang :: Action Bool
gccIsClang = flag GccIsClang

42
43
gccGe46 :: Action Bool
gccGe46 = fmap not $ flag GccLt46
44
45
46
47
48
49
50
51
52

platformSupportsSharedLibs :: Action Bool
platformSupportsSharedLibs = do
    badPlatform   <- targetPlatforms [ "powerpc-unknown-linux"
                                     , "x86_64-unknown-mingw32"
                                     , "i386-unknown-mingw32" ]
    solaris       <- targetPlatform    "i386-unknown-solaris2"
    solarisBroken <- flag SolarisBrokenShld
    return $ not (badPlatform || solaris && solarisBroken)
53
54
55
56
57
58
59
60
61
62
63
64
65

ghcWithSMP :: Action Bool
ghcWithSMP = do
    goodArch <- targetArchs ["i386", "x86_64", "sparc", "powerpc", "arm"]
    ghcUnreg <- flag GhcUnregisterised
    return $ goodArch && not ghcUnreg

ghcWithNativeCodeGen :: Action Bool
ghcWithNativeCodeGen = do
    goodArch <- targetArchs ["i386", "x86_64", "sparc", "powerpc"]
    badOs    <- targetOss ["ios", "aix"]
    ghcUnreg <- flag GhcUnregisterised
    return $ goodArch && not badOs && not ghcUnreg