Hsc2Hs.hs 2.67 KB
Newer Older
1 2 3 4 5 6
module Settings.Builders.Hsc2Hs (hsc2HsArgs) where

import Expression
import Oracles
import Predicates (builder, stage0, notStage0)
import Settings
Andrey Mokhov's avatar
Andrey Mokhov committed
7
import Settings.Builders.GhcCabal hiding (cppArgs)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

hsc2HsArgs :: Args
hsc2HsArgs = builder Hsc2Hs ? do
    stage   <- getStage
    ccPath  <- lift . builderPath $ Gcc stage
    gmpDirs <- getSettingList GmpIncludeDirs
    cFlags  <- getCFlags
    lFlags  <- getLFlags
    hArch   <- getSetting HostArch
    hOs     <- getSetting HostOs
    tArch   <- getSetting TargetArch
    tOs     <- getSetting TargetOs
    version <- if stage == Stage0
               then lift $ ghcCanonVersion
               else getSetting ProjectVersionInt
    mconcat [ arg $ "--cc=" ++ ccPath
            , arg $ "--ld=" ++ ccPath
Andrey Mokhov's avatar
Andrey Mokhov committed
25
            , notM windowsHost ? arg "--cross-safe"
26 27 28 29 30 31 32 33 34
            , append $ map ("-I"       ++) gmpDirs
            , append $ map ("--cflag=" ++) cFlags
            , append $ map ("--lflag=" ++) lFlags
            , 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"  )
            , arg ("--cflag=-D__GLASGOW_HASKELL__=" ++ version)
35 36
            , arg =<< getInput
            , arg "-o", arg =<< getOutput ]
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 62 63 64 65 66 67 68

getCFlags :: Expr [String]
getCFlags = fromDiffExpr $ do
    pkg       <- getPackage
    path      <- getTargetPath
    iDirs     <- getPkgDataList IncludeDirs
    dDirs     <- getPkgDataList DepIncludeDirs
    cppArgs   <- getPkgDataList CppArgs
    depCcArgs <- getPkgDataList DepCcArgs
    mconcat [ ccArgs
            , argStagedSettingList ConfCcArgs
            , remove ["-O"]
            , argStagedSettingList ConfCppArgs
            , arg $ "-I" ++ path -/- "build/autogen"
            , append [ "-I" ++ pkgPath pkg -/- dir | dir <- iDirs ++ dDirs ]
            , append cppArgs
            , append depCcArgs
            , ccWarnings
            , arg "-include", arg $ path -/- "build/autogen/cabal_macros.h" ]

getLFlags :: Expr [String]
getLFlags = fromDiffExpr $ do
    ldArgs    <- getPkgDataList LdArgs
    libDirs   <- getPkgDataList DepLibDirs
    extraLibs <- getPkgDataList DepExtraLibs
    depLdArgs <- getPkgDataList DepLdArgs
    mconcat [ argStagedSettingList ConfGccLinkerArgs
            --, ldArgs -- TODO: resolve name conflict (ldArgs is currently empty)
            , append ldArgs
            , append $ [ "-L" ++ unifyPath dir | dir <- libDirs ]
            , append $ [ "-l" ++ unifyPath dir | dir <- extraLibs ]
            , append depLdArgs ]