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