Setting.hs 2.15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
module Oracles.Setting (
    Setting (..), MultiSetting (..),
    setting, multiSetting,
    windowsHost
    ) where

import Base
import Oracles.Base

-- Each Setting comes from the system.config file, e.g. 'target-os = mingw32'.
-- setting TargetOs looks up the config file and returns "mingw32".
--
-- MultiSetting is used for multiple string values separated by spaces, such
-- as 'src-hc-args = -H32m -O'.
-- multiSetting SrcHcArgs therefore returns a list of strings ["-H32", "-O"].
data Setting = TargetOs
             | TargetArch
             | TargetPlatformFull
             | HostOsCpp
             | DynamicExtension
             | ProjectVersion
             | GhcSourcePath

data MultiSetting = SrcHcArgs
                  | 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"

multiSetting :: MultiSetting -> Action [String]
multiSetting s = fmap words $ askConfig $ case s 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
    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"]