Commit c816782e authored by ijones's avatar ijones
Browse files

c-sources building and library inclusion

parent 2c31a146
......@@ -54,7 +54,7 @@ import Distribution.Simple.Configure (LocalBuildInfo(..), compiler)
import Distribution.Simple.Utils (rawSystemExit, setupMessage,
die, rawSystemPathExit,
split, createIfNotExists,
mkLibName, moveSources, pathJoin
mkLibName, moveSources, pathJoin, splitExt
)
......@@ -109,12 +109,13 @@ buildGHC pref pkg_descr lbi = do
-- build any C sources
when (not (null (maybe [] cSources (library pkg_descr)))) $
rawSystemExit (compilerPath (compiler lbi)) (maybe [] cSources (library pkg_descr))
rawSystemExit (compilerPath (compiler lbi)) (maybe [] cSources (library pkg_descr) ++ ["-odir " ++ pref, "-hidir " ++ pref, "-c"])
-- now, build the library
let objs = map (++objsuffix) (map dotToSep (maybe [] modules (library pkg_descr)))
let hObjs = map (++objsuffix) (map dotToSep (maybe [] modules (library pkg_descr)))
cObjs = [file ++ objsuffix | (file, _) <- (map splitExt (maybe [] cSources (library pkg_descr)))]
lib = mkLibName pref (showPackageId (package pkg_descr))
rawSystemPathExit "ar" (["q", lib] ++ [pathJoin [pref, x] | x <- objs])
rawSystemPathExit "ar" (["q", lib] ++ [pathJoin [pref, x] | x <- hObjs ++ cObjs])
constructGHCCmdLine :: FilePath -> PackageDescription -> LocalBuildInfo -> [String]
constructGHCCmdLine pref pkg_descr lbi =
......
......@@ -61,7 +61,8 @@ module Distribution.Simple.Utils (
mkLibName,
copyFile,
pathJoin,
removeFileRecursive
removeFileRecursive,
splitExt
) where
import Distribution.Package (PackageDescription(..), showPackageId)
......@@ -104,6 +105,10 @@ split_longest_prefix s pred'
(_:pre') -> (reverse pre', reverse suf)
where (suf,pre) = break pred' (reverse s)
-- |Split the path into filename and extension
splitExt :: FilePath -> (String, String)
splitExt p = split_longest_prefix p (== '.')
isPathSeparator :: Char -> Bool
isPathSeparator ch =
#ifdef mingw32_TARGET_OS
......
......@@ -2,6 +2,7 @@ Name: test
Version: 1.0
Modules: A, B.A
Exposed-Modules: A
C-Sources: hello.c
Extensions: ForeignFunctionInterface
Executable: testA
......
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