Switches.hs 2.68 KB
Newer Older
1
2
3
4
module Switches (
    buildHaddock, validating,
    IntegerLibraryImpl (..), integerLibraryImpl,
    supportsPackageKey, targetPlatforms, targetPlatform,
Andrey Mokhov's avatar
Andrey Mokhov committed
5
6
    targetOss, targetOs, notTargetOs,
    targetArchs, dynamicGhcPrograms, ghcWithInterpreter,
7
    platformSupportsSharedLibs, crossCompiling,
Andrey Mokhov's avatar
Andrey Mokhov committed
8
    gccIsClang, gccLt46, windowsHost, notWindowsHost
9
10
    ) where

Andrey Mokhov's avatar
Andrey Mokhov committed
11
12
import Base
import Expression
13
14

-- User-defined switches
Andrey Mokhov's avatar
Andrey Mokhov committed
15
16
buildHaddock :: Monad m => Predicate m
buildHaddock = return True
17

Andrey Mokhov's avatar
Andrey Mokhov committed
18
19
validating :: Monad m => Predicate m
validating = return False
20
21
22
23
24
25
26
27

-- Support for multiple integer library implementations
data IntegerLibraryImpl = IntegerGmp | IntegerGmp2 | IntegerSimple

integerLibraryImpl :: IntegerLibraryImpl
integerLibraryImpl = IntegerGmp2

-- Predicates based on configuration files
Andrey Mokhov's avatar
Andrey Mokhov committed
28
29
supportsPackageKey :: Predicate Action
supportsPackageKey = configKeyYes "supports-package-key"
30

Andrey Mokhov's avatar
Andrey Mokhov committed
31
32
targetPlatforms :: [String] -> Predicate Action
targetPlatforms = configKeyValues "target-platform-full"
33

Andrey Mokhov's avatar
Andrey Mokhov committed
34
targetPlatform :: String -> Predicate Action
35
36
targetPlatform s = targetPlatforms [s]

Andrey Mokhov's avatar
Andrey Mokhov committed
37
38
targetOss :: [String] -> Predicate Action
targetOss = configKeyValues "target-os"
39

Andrey Mokhov's avatar
Andrey Mokhov committed
40
targetOs :: String -> Predicate Action
41
42
targetOs s = targetOss [s]

Andrey Mokhov's avatar
Andrey Mokhov committed
43
44
45
46
47
notTargetOs :: String -> Predicate Action
notTargetOs = fmap not . targetOs

targetArchs :: [String] -> Predicate Action
targetArchs = configKeyValues "target-arch"
48

Andrey Mokhov's avatar
Andrey Mokhov committed
49
50
51
52
53
54
55
56
platformSupportsSharedLibs :: Predicate Action
platformSupportsSharedLibs = do
    badPlatform   <- targetPlatforms [ "powerpc-unknown-linux"
                                     , "x86_64-unknown-mingw32"
                                     , "i386-unknown-mingw32" ]
    solaris       <- targetPlatform    "i386-unknown-solaris2"
    solarisBroken <- configKeyYes "solaris-broken-shld"
    return $ not (badPlatform || solaris && solarisBroken)
57

Andrey Mokhov's avatar
Andrey Mokhov committed
58
59
dynamicGhcPrograms :: Predicate Action
dynamicGhcPrograms = configKeyYes "dynamic-ghc-programs"
60

Andrey Mokhov's avatar
Andrey Mokhov committed
61
62
63
64
65
66
67
68
ghcWithInterpreter :: Predicate Action
ghcWithInterpreter = do
    goodOs <- targetOss [ "mingw32", "cygwin32", "linux", "solaris2"
                        , "freebsd", "dragonfly", "netbsd", "openbsd"
                        , "darwin", "kfreebsdgnu" ]
    goodArch <- targetArchs [ "i386", "x86_64", "powerpc", "sparc"
                            , "sparc64", "arm" ]
    return $ goodOs && goodArch
69

Andrey Mokhov's avatar
Andrey Mokhov committed
70
71
crossCompiling :: Predicate Action
crossCompiling = configKeyYes "cross-compiling"
72

Andrey Mokhov's avatar
Andrey Mokhov committed
73
74
gccIsClang :: Predicate Action
gccIsClang = configKeyYes "gcc-is-clang"
75

Andrey Mokhov's avatar
Andrey Mokhov committed
76
77
gccLt46 :: Predicate Action
gccLt46 = configKeyYes "gcc-lt-46"
78

Andrey Mokhov's avatar
Andrey Mokhov committed
79
80
windowsHost :: Predicate Action
windowsHost = configKeyValues "host-os-cpp" ["mingw32", "cygwin32"]
81

Andrey Mokhov's avatar
Andrey Mokhov committed
82
83
notWindowsHost :: Predicate Action
notWindowsHost = fmap not windowsHost