Finalise warnings-related arguments (#448)
[ghc.git] / src / Oracles / Flag.hs
1 module Oracles.Flag (
2 Flag (..), flag, crossCompiling, platformSupportsSharedLibs,
3 ghcWithSMP, ghcWithNativeCodeGen, supportsSplitObjects
4 ) where
5
6 import Hadrian.Oracles.TextFile
7
8 import Base
9 import Oracles.Setting
10
11 data Flag = ArSupportsAtFile
12 | CrossCompiling
13 | GccIsClang
14 | GccLt34
15 | GccLt44
16 | GccLt46
17 | GhcUnregisterised
18 | LeadingUnderscore
19 | SolarisBrokenShld
20 | SplitObjectsBroken
21 | WithLibdw
22 | HaveLibMingwEx
23 | UseSystemFfi
24
25 -- Note, if a flag is set to empty string we treat it as set to NO. This seems
26 -- fragile, but some flags do behave like this, e.g. GccIsClang.
27 flag :: Flag -> Action Bool
28 flag f = do
29 let key = case f of
30 ArSupportsAtFile -> "ar-supports-at-file"
31 CrossCompiling -> "cross-compiling"
32 GccIsClang -> "gcc-is-clang"
33 GccLt34 -> "gcc-lt-34"
34 GccLt44 -> "gcc-lt-44"
35 GccLt46 -> "gcc-lt-46"
36 GhcUnregisterised -> "ghc-unregisterised"
37 LeadingUnderscore -> "leading-underscore"
38 SolarisBrokenShld -> "solaris-broken-shld"
39 SplitObjectsBroken -> "split-objects-broken"
40 WithLibdw -> "with-libdw"
41 HaveLibMingwEx -> "have-lib-mingw-ex"
42 UseSystemFfi -> "use-system-ffi"
43 value <- lookupValueOrError configFile key
44 when (value `notElem` ["YES", "NO", ""]) . error $ "Configuration flag "
45 ++ quote (key ++ " = " ++ value) ++ " cannot be parsed."
46 return $ value == "YES"
47
48 crossCompiling :: Action Bool
49 crossCompiling = flag CrossCompiling
50
51 platformSupportsSharedLibs :: Action Bool
52 platformSupportsSharedLibs = do
53 badPlatform <- anyTargetPlatform [ "powerpc-unknown-linux"
54 , "x86_64-unknown-mingw32"
55 , "i386-unknown-mingw32" ]
56 solaris <- anyTargetPlatform [ "i386-unknown-solaris2" ]
57 solarisBroken <- flag SolarisBrokenShld
58 return $ not (badPlatform || solaris && solarisBroken)
59
60 ghcWithSMP :: Action Bool
61 ghcWithSMP = do
62 goodArch <- anyTargetArch ["i386", "x86_64", "sparc", "powerpc", "arm"]
63 ghcUnreg <- flag GhcUnregisterised
64 return $ goodArch && not ghcUnreg
65
66 ghcWithNativeCodeGen :: Action Bool
67 ghcWithNativeCodeGen = do
68 goodArch <- anyTargetArch ["i386", "x86_64", "sparc", "powerpc"]
69 badOs <- anyTargetOs ["ios", "aix"]
70 ghcUnreg <- flag GhcUnregisterised
71 return $ goodArch && not badOs && not ghcUnreg
72
73 supportsSplitObjects :: Action Bool
74 supportsSplitObjects = do
75 broken <- flag SplitObjectsBroken
76 ghcUnreg <- flag GhcUnregisterised
77 goodArch <- anyTargetArch [ "i386", "x86_64", "powerpc", "sparc" ]
78 goodOs <- anyTargetOs [ "mingw32", "cygwin32", "linux", "darwin", "solaris2"
79 , "freebsd", "dragonfly", "netbsd", "openbsd" ]
80 return $ not broken && not ghcUnreg && goodArch && goodOs