80d8c6a59b37c6f510b0a821d3f8a82117b316d4
[hadrian.git] / src / Oracles / Config / Flag.hs
1 module Oracles.Config.Flag (
2 Flag (..), flag,
3 crossCompiling, gccIsClang, gccGe46,
4 platformSupportsSharedLibs, ghcWithSMP, ghcWithNativeCodeGen
5 ) where
6
7 import Base
8 import Oracles.Config
9 import Oracles.Config.Setting
10
11 data Flag = GccIsClang
12 | GccLt46
13 | CrossCompiling
14 | SupportsPackageKey
15 | SolarisBrokenShld
16 | SplitObjectsBroken
17 | GhcUnregisterised
18
19 flag :: Flag -> Action Bool
20 flag f = do
21 key <- return $ case f of
22 GccIsClang -> "gcc-is-clang"
23 GccLt46 -> "gcc-lt-46"
24 CrossCompiling -> "cross-compiling"
25 SupportsPackageKey -> "supports-package-key"
26 SolarisBrokenShld -> "solaris-broken-shld"
27 SplitObjectsBroken -> "split-objects-broken"
28 GhcUnregisterised -> "ghc-unregisterised"
29 value <- askConfigWithDefault key . putError
30 $ "\nFlag '" ++ key ++ "' not set in configuration files."
31 unless (value == "YES" || value == "NO") . putError
32 $ "\nFlag '" ++ key ++ "' is set to '" ++ value
33 ++ "' instead of 'YES' or 'NO'."
34 return $ value == "YES"
35
36 crossCompiling :: Action Bool
37 crossCompiling = flag CrossCompiling
38
39 gccIsClang :: Action Bool
40 gccIsClang = flag GccIsClang
41
42 gccGe46 :: Action Bool
43 gccGe46 = fmap not $ flag GccLt46
44
45 platformSupportsSharedLibs :: Action Bool
46 platformSupportsSharedLibs = do
47 badPlatform <- targetPlatforms [ "powerpc-unknown-linux"
48 , "x86_64-unknown-mingw32"
49 , "i386-unknown-mingw32" ]
50 solaris <- targetPlatform "i386-unknown-solaris2"
51 solarisBroken <- flag SolarisBrokenShld
52 return $ not (badPlatform || solaris && solarisBroken)
53
54 ghcWithSMP :: Action Bool
55 ghcWithSMP = do
56 goodArch <- targetArchs ["i386", "x86_64", "sparc", "powerpc", "arm"]
57 ghcUnreg <- flag GhcUnregisterised
58 return $ goodArch && not ghcUnreg
59
60 ghcWithNativeCodeGen :: Action Bool
61 ghcWithNativeCodeGen = do
62 goodArch <- targetArchs ["i386", "x86_64", "sparc", "powerpc"]
63 badOs <- targetOss ["ios", "aix"]
64 ghcUnreg <- flag GhcUnregisterised
65 return $ goodArch && not badOs && not ghcUnreg