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