Commit 061dcf1f authored by Andrey Mokhov's avatar Andrey Mokhov

Minor revision

See #238
parent 4bdc4a47
module Rules.Library ( module Rules.Library (
buildPackageLibrary, buildPackageGhciLibrary, buildPackageLibrary, buildPackageGhciLibrary, buildDynamicLib
buildDynamicLib
) where ) where
import Data.Char import Data.Char
...@@ -13,15 +12,15 @@ import Flavour ...@@ -13,15 +12,15 @@ import Flavour
import GHC import GHC
import Oracles.ModuleFiles import Oracles.ModuleFiles
import Oracles.PackageData import Oracles.PackageData
import Oracles.Dependencies (contextDependencies) import Oracles.Dependencies
import Settings import Settings
import Settings.Path import Settings.Path
import Target import Target
import UserSettings import UserSettings
import Util import Util
getLibraryObjs :: Context -> Action [FilePath] libraryObjects :: Context -> Action [FilePath]
getLibraryObjs context@Context{..} = do libraryObjects context@Context{..} = do
hsObjs <- hsObjects context hsObjs <- hsObjects context
noHsObjs <- nonHsObjects context noHsObjs <- nonHsObjects context
...@@ -31,34 +30,26 @@ getLibraryObjs context@Context{..} = do ...@@ -31,34 +30,26 @@ getLibraryObjs context@Context{..} = do
split <- interpretInContext context $ splitObjects flavour split <- interpretInContext context $ splitObjects flavour
let getSplitObjs = concatForM hsObjs $ \obj -> do let getSplitObjs = concatForM hsObjs $ \obj -> do
let dir = dropExtension obj ++ "_" ++ osuf way ++ "_split" let dir = dropExtension obj ++ "_" ++ osuf way ++ "_split"
contents <- liftIO $ IO.getDirectoryContents dir contents <- liftIO $ IO.getDirectoryContents dir
return . map (dir -/-) $ filter (not . all (== '.')) contents return . map (dir -/-) $ filter (not . all (== '.')) contents
(noHsObjs ++) <$> if split then getSplitObjs else return hsObjs (noHsObjs ++) <$> if split then getSplitObjs else return hsObjs
buildDynamicLib :: Context -> Rules () buildDynamicLib :: Context -> Rules ()
buildDynamicLib context@Context{..} = do buildDynamicLib context@Context{..} = do
-- macOS let path = buildPath context
matchGhcVersionedFilePath libPrefix "dylib" ?> buildDynamicLibUNIX libPrefix = path -/- "libHS" ++ pkgNameString package
-- OS X
matchGhcVersionedFilePath libPrefix "dylib" ?> buildDynamicLibUnix
-- Linux -- Linux
matchGhcVersionedFilePath libPrefix "so" ?> buildDynamicLibUNIX matchGhcVersionedFilePath libPrefix "so" ?> buildDynamicLibUnix
-- TODO: Windows -- TODO: Windows
where where
path = buildPath context buildDynamicLibUnix so = do
libPrefix = path -/- "libHS" ++ pkgNameString package
buildDynamicLibUNIX so = do
deps <- contextDependencies context deps <- contextDependencies context
need =<< mapM pkgLibraryFile deps
forM_ deps $ \dep -> do objs <- libraryObjects context
lib <- pkgLibraryFile dep
need [lib]
removeFile so
objs <- getLibraryObjs context
build $ Target context (Ghc LinkHs stage) objs [so] build $ Target context (Ghc LinkHs stage) objs [so]
buildPackageLibrary :: Context -> Rules () buildPackageLibrary :: Context -> Rules ()
...@@ -66,12 +57,10 @@ buildPackageLibrary context@Context {..} = do ...@@ -66,12 +57,10 @@ buildPackageLibrary context@Context {..} = do
let path = buildPath context let path = buildPath context
libPrefix = path -/- "libHS" ++ pkgNameString package libPrefix = path -/- "libHS" ++ pkgNameString package
matchVersionedFilePath libPrefix (waySuffix way <.> "a") ?> \a -> do matchVersionedFilePath libPrefix (waySuffix way <.> "a") ?> \a -> do
removeFile a objs <- libraryObjects context
objs <- getLibraryObjs context
asuf <- libsuf way asuf <- libsuf way
let isLib0 = ("//*-0" ++ asuf) ?== a let isLib0 = ("//*-0" ++ asuf) ?== a
removeFile a
if isLib0 then build $ Target context (Ar stage) [] [a] -- TODO: Scan for dlls if isLib0 then build $ Target context (Ar stage) [] [a] -- TODO: Scan for dlls
else build $ Target context (Ar stage) objs [a] else build $ Target context (Ar stage) objs [a]
......
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