Add Base.hs with Shake imports and build paths.
[hadrian.git] / src / Oracles / Flag.hs
1 module Oracles.Flag (
2 Flag (..), flag,
3 supportsPackageKey, 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 . redError
32 $ "\nFlag '" ++ key ++ "' not set in configuration files."
33 unless (value == "YES" || value == "NO") . redError
34 $ "\nFlag '" ++ key ++ "' is set to '" ++ value
35 ++ "' instead of 'YES' or 'NO'."
36 return $ value == "YES"
37
38 supportsPackageKey :: Action Bool
39 supportsPackageKey = flag SupportsPackageKey
40
41 crossCompiling :: Action Bool
42 crossCompiling = flag CrossCompiling
43
44 gccIsClang :: Action Bool
45 gccIsClang = flag GccIsClang
46
47 gccLt46 :: Action Bool
48 gccLt46 = flag GccLt46
49
50 platformSupportsSharedLibs :: Action Bool
51 platformSupportsSharedLibs = do
52 badPlatform <- targetPlatforms [ "powerpc-unknown-linux"
53 , "x86_64-unknown-mingw32"
54 , "i386-unknown-mingw32" ]
55 solaris <- targetPlatform "i386-unknown-solaris2"
56 solarisBroken <- flag SolarisBrokenShld
57 return $ not (badPlatform || solaris && solarisBroken)
58
59 ghcWithSMP :: Action Bool
60 ghcWithSMP = do
61 goodArch <- targetArchs ["i386", "x86_64", "sparc", "powerpc", "arm"]
62 ghcUnreg <- flag GhcUnregisterised
63 return $ goodArch && not ghcUnreg
64
65 ghcWithNativeCodeGen :: Action Bool
66 ghcWithNativeCodeGen = do
67 goodArch <- targetArchs ["i386", "x86_64", "sparc", "powerpc"]
68 badOs <- targetOss ["ios", "aix"]
69 ghcUnreg <- flag GhcUnregisterised
70 return $ goodArch && not badOs && not ghcUnreg