Clean up code, add comments.
[hadrian.git] / src / Oracles / Config / Flag.hs
1 module Oracles.Config.Flag (
2 Flag (..), flag, getFlag,
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 = CrossCompiling
12 | GccIsClang
13 | GccLt46
14 | GhcUnregisterised
15 | SolarisBrokenShld
16 | SplitObjectsBroken
17 | SupportsPackageKey
18
19 flag :: Flag -> Action Bool
20 flag f = do
21 key <- return $ case f of
22 CrossCompiling -> "cross-compiling"
23 GccIsClang -> "gcc-is-clang"
24 GccLt46 -> "gcc-lt-46"
25 GhcUnregisterised -> "ghc-unregisterised"
26 SolarisBrokenShld -> "solaris-broken-shld"
27 SplitObjectsBroken -> "split-objects-broken"
28 SupportsPackageKey -> "supports-package-key"
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 getFlag :: Flag -> ReaderT a Action Bool
37 getFlag = lift . flag
38
39 crossCompiling :: Action Bool
40 crossCompiling = flag CrossCompiling
41
42 gccIsClang :: Action Bool
43 gccIsClang = flag GccIsClang
44
45 gccGe46 :: Action Bool
46 gccGe46 = fmap not $ flag GccLt46
47
48 platformSupportsSharedLibs :: Action Bool
49 platformSupportsSharedLibs = do
50 badPlatform <- targetPlatforms [ "powerpc-unknown-linux"
51 , "x86_64-unknown-mingw32"
52 , "i386-unknown-mingw32" ]
53 solaris <- targetPlatform "i386-unknown-solaris2"
54 solarisBroken <- flag SolarisBrokenShld
55 return $ not (badPlatform || solaris && solarisBroken)
56
57 ghcWithSMP :: Action Bool
58 ghcWithSMP = do
59 goodArch <- targetArchs ["i386", "x86_64", "sparc", "powerpc", "arm"]
60 ghcUnreg <- flag GhcUnregisterised
61 return $ goodArch && not ghcUnreg
62
63 ghcWithNativeCodeGen :: Action Bool
64 ghcWithNativeCodeGen = do
65 goodArch <- targetArchs ["i386", "x86_64", "sparc", "powerpc"]
66 badOs <- targetOss ["ios", "aix"]
67 ghcUnreg <- flag GhcUnregisterised
68 return $ goodArch && not badOs && not ghcUnreg