Commit e6dcd1b0 authored by Zhen Zhang's avatar Zhen Zhang Committed by Andrey Mokhov
Browse files

Use GHC to compile C files (#380)

parent 57cfa03c
......@@ -15,8 +15,8 @@ import Stage
-- * Extracting source dependencies, e.g. by passing @-M@ command line argument;
-- * Linking object files & static libraries into an executable.
-- We have CcMode for C compiler and GhcMode for GHC.
data CcMode = CompileC | FindCDependencies deriving (Eq, Generic, Show)
data GhcMode = CompileHs | FindHsDependencies | LinkHs
data CcMode = CompileC | FindCDependencies deriving (Eq, Generic, Show)
data GhcMode = CompileCWithGhc | CompileHs | FindHsDependencies | LinkHs
deriving (Eq, Generic, Show)
-- | GhcPkg can initialise a package database and register packages in it.
......
......@@ -28,9 +28,9 @@ compilePackage rs context@Context {..} = do
buildWithResources rs $ Target context (Ghc CompileHs stage) [src] [obj]
priority 2.0 $ do
nonHs "c" %> compile (Cc CompileC ) (obj2src "c" isGeneratedCFile )
nonHs "cmm" %> compile (Ghc CompileHs) (obj2src "cmm" isGeneratedCmmFile)
nonHs "s" %> compile (Ghc CompileHs) (obj2src "S" $ const False )
nonHs "c" %> compile (Ghc CompileCWithGhc) (obj2src "c" isGeneratedCFile )
nonHs "cmm" %> compile (Ghc CompileHs) (obj2src "cmm" isGeneratedCmmFile)
nonHs "s" %> compile (Ghc CompileHs) (obj2src "S" $ const False )
-- TODO: Add dependencies for #include of .h and .hs-incl files (gcc -MM?).
[ path <//> "*" <.> suf way | suf <- [ osuf, hisuf] ] &%> compileHs
......
module Settings.Builders.Ghc (ghcBuilderArgs, ghcMBuilderArgs, haddockGhcArgs) where
module Settings.Builders.Ghc (
ghcBuilderArgs, ghcMBuilderArgs, haddockGhcArgs,
ghcCbuilderArgs
) where
import Flavour
import GHC
......@@ -15,6 +18,25 @@ ghcBuilderArgs = (builder (Ghc CompileHs) ||^ builder (Ghc LinkHs)) ? do
, append =<< getInputs
, arg "-o", arg =<< getOutput ]
ghcCbuilderArgs :: Args
ghcCbuilderArgs =
builder (Ghc CompileCWithGhc) ? do
way <- getWay
let ccArgs = [ append =<< getPkgDataList CcArgs
, getSettingList . ConfCcArgs =<< getStage
, cIncludeArgs
, arg "-Werror"
, Dynamic `wayUnit` way ? append [ "-fPIC", "-DDYNAMIC" ] ]
mconcat [ arg "-Wall"
, ghcLinkArgs
, commonGhcArgs
, mconcat (map (map ("-optc" ++) <$>) ccArgs)
, arg "-c"
, append =<< getInputs
, arg "-o"
, arg =<< getOutput ]
ghcLinkArgs :: Args
ghcLinkArgs = builder (Ghc LinkHs) ? do
stage <- getStage
......
......@@ -212,6 +212,7 @@ defaultBuilderArgs = mconcat
, deriveConstantsBuilderArgs
, genPrimopCodeBuilderArgs
, ghcBuilderArgs
, ghcCbuilderArgs
, ghcCabalBuilderArgs
, ghcCabalHsColourBuilderArgs
, ghcMBuilderArgs
......
......@@ -7,4 +7,4 @@ import Settings
basePackageArgs :: Args
basePackageArgs = package base ? mconcat
[ builder GhcCabal ? arg ("--flags=" ++ integerLibraryName)
, builder Cc ? arg "-O2" ] -- Fix the 'unknown symbol stat' issue, see #259.
, builder (Ghc CompileCWithGhc) ? arg "-optc-O2" ] -- Fix the 'unknown symbol stat' issue, see #259.
......@@ -48,8 +48,7 @@ rtsPackageArgs = package rts ? do
ffiIncludeDir <- getSetting FfiIncludeDir
ffiLibraryDir <- getSetting FfiLibDir
ghclibDir <- expr installGhcLibDir
mconcat
[ builder Cc ? mconcat
let cArgs =
[ arg "-Irts"
, arg $ "-I" ++ path
, arg $ "-DRtsWay=\"rts_" ++ show way ++ "\""
......@@ -96,8 +95,10 @@ rtsPackageArgs = package rts ? do
append [ "-Wno-incompatible-pointer-types" ]
]
mconcat
[ builder (Cc FindCDependencies) ? mconcat cArgs
, builder (Ghc CompileCWithGhc) ? mconcat (map (map ("-optc" ++) <$>) cArgs)
, builder Ghc ? arg "-Irts"
, builder HsCpp ? append
[ "-DTOP=" ++ show top
, "-DFFI_INCLUDE_DIR=" ++ show ffiIncludeDir
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment