Hsc2Hs.hs 2.21 KB
Newer Older
1
module Settings.Builders.Hsc2Hs (hsc2hsBuilderArgs) where
2

3
import Settings.Builders.Common
4

5 6
hsc2hsBuilderArgs :: Args
hsc2hsBuilderArgs = builder Hsc2Hs ? do
7
    stage   <- getStage
8
    ccPath  <- getBuilderPath $ Cc CompileC stage
9
    gmpDir  <- getSetting GmpIncludeDir
10
    top     <- expr topDirectory
11 12 13 14 15
    hArch   <- getSetting HostArch
    hOs     <- getSetting HostOs
    tArch   <- getSetting TargetArch
    tOs     <- getSetting TargetOs
    version <- if stage == Stage0
16
               then expr ghcCanonVersion
17 18 19
               else getSetting ProjectVersionInt
    mconcat [ arg $ "--cc=" ++ ccPath
            , arg $ "--ld=" ++ ccPath
Andrey Mokhov's avatar
Andrey Mokhov committed
20
            , notM windowsHost ? arg "--cross-safe"
Andrey Mokhov's avatar
Andrey Mokhov committed
21 22 23
            , pure $ map ("-I" ++) (words gmpDir)
            , map ("--cflag=" ++) <$> getCFlags
            , map ("--lflag=" ++) <$> getLFlags
24 25 26 27 28
            , notStage0 ? crossCompiling ? arg "--cross-compile"
            , stage0    ? arg ("--cflag=-D" ++ hArch ++ "_HOST_ARCH=1")
            , stage0    ? arg ("--cflag=-D" ++ hOs   ++ "_HOST_OS=1"  )
            , notStage0 ? arg ("--cflag=-D" ++ tArch ++ "_HOST_ARCH=1")
            , notStage0 ? arg ("--cflag=-D" ++ tOs   ++ "_HOST_OS=1"  )
Andrey Mokhov's avatar
Andrey Mokhov committed
29
            , arg $ "--cflag=-D__GLASGOW_HASKELL__=" ++ version
30
            , arg $ "--template=" ++ top -/- templateHscPath
31
            , arg $ "-I" ++ top -/- "inplace/lib/include/"
32 33
            , arg =<< getInput
            , arg "-o", arg =<< getOutput ]
34 35

getCFlags :: Expr [String]
36
getCFlags = do
37
    context   <- getContext
Andrey Mokhov's avatar
Andrey Mokhov committed
38 39
    mconcat [ remove ["-O"] (cArgs <> getStagedSettingList ConfCcArgs)
            , getStagedSettingList ConfCppArgs
40
            , cIncludeArgs
Andrey Mokhov's avatar
Andrey Mokhov committed
41 42
            , getPkgDataList CppArgs
            , getPkgDataList DepCcArgs
43
            , cWarnings
44
            , arg "-include", arg $ autogenPath context -/- "cabal_macros.h" ]
45 46

getLFlags :: Expr [String]
47
getLFlags = do
48 49
    libDirs   <- getPkgDataList DepLibDirs
    extraLibs <- getPkgDataList DepExtraLibs
Andrey Mokhov's avatar
Andrey Mokhov committed
50
    mconcat [ getStagedSettingList ConfGccLinkerArgs
Andrey Mokhov's avatar
Andrey Mokhov committed
51
            , ldArgs
Andrey Mokhov's avatar
Andrey Mokhov committed
52 53 54 55
            , getPkgDataList LdArgs
            , pure [ "-L" ++ unifyPath dir | dir <- libDirs ]
            , pure [ "-l" ++ unifyPath dir | dir <- extraLibs ]
            , getPkgDataList DepLdArgs ]