Setting.hs 2.18 KB
Newer Older
1
module Oracles.Setting (
2
3
    Setting (..), SettingMulti (..),
    setting, settingMulti,
4
5
6
    windowsHost
    ) where

7
import Stage
8
import Oracles.Base
9
import Development.Shake
10
11
12
13

-- Each Setting comes from the system.config file, e.g. 'target-os = mingw32'.
-- setting TargetOs looks up the config file and returns "mingw32".
--
14
-- SettingMulti is used for multiple string values separated by spaces, such
15
-- as 'src-hc-args = -H32m -O'.
16
-- settingMulti SrcHcArgs therefore returns a list of strings ["-H32", "-O"].
17
18
19
20
21
22
23
24
data Setting = TargetOs
             | TargetArch
             | TargetPlatformFull
             | HostOsCpp
             | DynamicExtension
             | ProjectVersion
             | GhcSourcePath

25
data SettingMulti = SrcHcArgs
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
                  | ConfCcArgs Stage
                  | ConfGccLinkerArgs Stage
                  | ConfLdLinkerArgs Stage
                  | ConfCppArgs Stage
                  | IconvIncludeDirs
                  | IconvLibDirs
                  | GmpIncludeDirs
                  | GmpLibDirs

setting :: Setting -> Action String
setting s = askConfig $ case s of
    TargetOs           -> "target-os"
    TargetArch         -> "target-arch"
    TargetPlatformFull -> "target-platform-full"
    HostOsCpp          -> "host-os-cpp"
    DynamicExtension   -> "dynamic-extension"
    ProjectVersion     -> "project-version"
    GhcSourcePath      -> "ghc-source-path"

45
46
settingMulti :: SettingMulti -> Action [String]
settingMulti s = fmap words $ askConfig $ case s of
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
    SrcHcArgs               -> "src-hc-args"
    ConfCcArgs        stage -> "conf-cc-args"         ++ showStage stage
    ConfCppArgs       stage -> "conf-cpp-args"        ++ showStage stage
    ConfGccLinkerArgs stage -> "conf-gcc-linker-args" ++ showStage stage
    ConfLdLinkerArgs  stage -> "conf-ld-linker-args"  ++ showStage stage
    IconvIncludeDirs        -> "iconv-include-dirs"
    IconvLibDirs            -> "iconv-lib-dirs"
    GmpIncludeDirs          -> "gmp-include-dirs"
    GmpLibDirs              -> "gmp-lib-dirs"
  where
    showStage = ("-stage" ++) . show

windowsHost :: Action Bool
windowsHost = do
    hostOsCpp <- setting HostOsCpp
    return $ hostOsCpp `elem` ["mingw32", "cygwin32"]