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