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