Option.hs 2.25 KB
Newer Older
1
module Oracles.Option (
2
    Option (..), MultiOption (..), windowsHost
3
4
5
6
7
    ) where

import Base
import Oracles.Base

8
9
-- For each Option the file default.config contains a line of the
-- form 'target-os = mingw32'.
10
11
12
13
-- (showArg TargetOs) is an action that consults the config files
-- and returns "mingw32".
--
-- MultiOption is used for multiple string options separated by spaces,
14
-- such as 'src-hc-args = -H32m -O'.
15
16
-- (showArgs SrcHcArgs) therefore returns a list of strings ["-H32", "-O"].
data Option = TargetOs
Andrey Mokhov's avatar
Andrey Mokhov committed
17
18
            | TargetArch
            | TargetPlatformFull
19
            | HostOsCpp
20
21
            | DynamicExtension
            | ProjectVersion
Andrey Mokhov's avatar
Andrey Mokhov committed
22
            | GhcSourcePath
23

24
25
26
27
28
29
30
31
32
33
34
35
36
data MultiOption = SrcHcArgs
                 | ConfCcArgs Stage
                 | ConfGccLinkerArgs Stage
                 | ConfLdLinkerArgs Stage
                 | ConfCppArgs Stage
                 | IconvIncludeDirs
                 | IconvLibDirs
                 | GmpIncludeDirs
                 | GmpLibDirs

instance ShowArg Option where
    showArg opt = askConfig $ case opt of
        TargetOs                -> "target-os"
37
38
        TargetArch              -> "target-arch"
        TargetPlatformFull      -> "target-platform-full"
39
40
41
        HostOsCpp               -> "host-os-cpp"
        DynamicExtension        -> "dynamic-extension"
        ProjectVersion          -> "project-version"
Andrey Mokhov's avatar
Andrey Mokhov committed
42
        GhcSourcePath           -> "ghc-source-path"
43
44
45
46
47
48
49
50

instance ShowArgs MultiOption where
    showArgs opt = showArgs $ fmap words $ askConfig $ case opt of
        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
51
52
53
54
        IconvIncludeDirs        -> "iconv-include-dirs"
        IconvLibDirs            -> "iconv-lib-dirs"
        GmpIncludeDirs          -> "gmp-include-dirs"
        GmpLibDirs              -> "gmp-lib-dirs"
55
      where
56
        showStage = ("-stage" ++) . show
57

58
windowsHost :: Action Bool
59
windowsHost = do
60
    hostOsCpp <- showArg HostOsCpp
61
    return $ hostOsCpp `elem` ["mingw32", "cygwin32"]