a084a1625e19aac2e6d815e55d10faf3f0bb8080
[hadrian.git] / src / Oracles / Config / Setting.hs
1 module Oracles.Config.Setting (
2 Setting (..), SettingList (..),
3 setting, settingList,
4 targetPlatform, targetPlatforms, targetOs, targetOss, notTargetOs,
5 targetArchs, windowsHost, notWindowsHost, ghcWithInterpreter,
6 ghcEnableTablesNextToCode, cmdLineLengthLimit
7 ) where
8
9 import Base
10 import Stage
11 import Oracles.Config
12
13 -- Each Setting comes from the system.config file, e.g. 'target-os = mingw32'.
14 -- setting TargetOs looks up the config file and returns "mingw32".
15 --
16 -- SettingList is used for multiple string values separated by spaces, such
17 -- as 'gmp-include-dirs = a b'.
18 -- settingList GmpIncludeDirs therefore returns a list of strings ["a", "b"].
19 data Setting = TargetOs
20 | TargetArch
21 | TargetPlatformFull
22 | HostOsCpp
23 | DynamicExtension
24 | ProjectVersion
25 | GhcSourcePath
26
27 data SettingList = ConfCcArgs Stage
28 | ConfGccLinkerArgs Stage
29 | ConfLdLinkerArgs Stage
30 | ConfCppArgs Stage
31 | IconvIncludeDirs
32 | IconvLibDirs
33 | GmpIncludeDirs
34 | GmpLibDirs
35
36 setting :: Setting -> Action String
37 setting key = askConfig $ case key of
38 TargetOs -> "target-os"
39 TargetArch -> "target-arch"
40 TargetPlatformFull -> "target-platform-full"
41 HostOsCpp -> "host-os-cpp"
42 DynamicExtension -> "dynamic-extension"
43 ProjectVersion -> "project-version"
44 GhcSourcePath -> "ghc-source-path"
45
46 settingList :: SettingList -> Action [String]
47 settingList key = fmap words $ askConfig $ case key of
48 ConfCcArgs stage -> "conf-cc-args-stage" ++ show stage
49 ConfCppArgs stage -> "conf-cpp-args-stage" ++ show stage
50 ConfGccLinkerArgs stage -> "conf-gcc-linker-args-stage" ++ show stage
51 ConfLdLinkerArgs stage -> "conf-ld-linker-args-stage" ++ show stage
52 IconvIncludeDirs -> "iconv-include-dirs"
53 IconvLibDirs -> "iconv-lib-dirs"
54 GmpIncludeDirs -> "gmp-include-dirs"
55 GmpLibDirs -> "gmp-lib-dirs"
56
57 matchSetting :: Setting -> [String] -> Action Bool
58 matchSetting key values = do
59 value <- setting key
60 return $ value `elem` values
61
62 targetPlatforms :: [String] -> Action Bool
63 targetPlatforms = matchSetting TargetPlatformFull
64
65 targetPlatform :: String -> Action Bool
66 targetPlatform s = targetPlatforms [s]
67
68 targetOss :: [String] -> Action Bool
69 targetOss = matchSetting TargetOs
70
71 targetOs :: String -> Action Bool
72 targetOs s = targetOss [s]
73
74 notTargetOs :: String -> Action Bool
75 notTargetOs = fmap not . targetOs
76
77 targetArchs :: [String] -> Action Bool
78 targetArchs = matchSetting TargetArch
79
80 windowsHost :: Action Bool
81 windowsHost = do
82 hostOsCpp <- setting HostOsCpp
83 return $ hostOsCpp `elem` ["mingw32", "cygwin32"]
84
85 notWindowsHost :: Action Bool
86 notWindowsHost = fmap not windowsHost
87
88 ghcWithInterpreter :: Action Bool
89 ghcWithInterpreter = do
90 goodOs <- targetOss [ "mingw32", "cygwin32", "linux", "solaris2"
91 , "freebsd", "dragonfly", "netbsd", "openbsd"
92 , "darwin", "kfreebsdgnu" ]
93 goodArch <- targetArchs [ "i386", "x86_64", "powerpc", "sparc"
94 , "sparc64", "arm" ]
95 return $ goodOs && goodArch
96
97 ghcEnableTablesNextToCode :: Action Bool
98 ghcEnableTablesNextToCode = targetArchs ["ia64", "powerpc64"]
99
100 -- Command lines have limited size on Windows. Since Windows 7 the limit is
101 -- 32768 characters (theoretically). In practice we use 31000 to leave some
102 -- breathing space for the builder's path & name, auxiliary flags, and other
103 -- overheads. Use this function to set limits for other OSs if necessary.
104 cmdLineLengthLimit :: Action Int
105 cmdLineLengthLimit = do
106 windows <- windowsHost
107 return $ if windows
108 then 31000
109 else 4194304 -- Cabal needs a bit more than 2MB!