Dependencies.hs 1.51 KB
Newer Older
1
module Rules.Dependencies (buildPackageDependencies) where
2

3
import Base
4
import Util
5
6
7
8
9
import Builder
import Package
import Expression
import qualified Target
import Oracles.PackageData
Andrey Mokhov's avatar
Andrey Mokhov committed
10
import Settings.Util
11
12
import Settings.TargetDirectory
import Rules.Actions
13
import Rules.Resources
14
import qualified System.Directory as IO
15

16
17
buildPackageDependencies :: Resources -> StagePackageTarget -> Rules ()
buildPackageDependencies _ target =
18
19
20
21
    let stage     = Target.stage target
        pkg       = Target.package target
        path      = targetPath stage pkg
        buildPath = path -/- "build"
22
        dropBuild = (pkgPath pkg ++) . drop (length buildPath)
23
        hDepFile  = buildPath -/- ".hs-dependencies"
24
    in do
25
26
        (buildPath <//> "*.c.deps") %> \file -> do
            let srcFile = dropBuild . dropExtension $ file
27
            need [srcFile]
28
            build $ fullTarget target (GccM stage) [srcFile] [file]
29

30
31
        hDepFile %> \file -> do
            srcs <- interpret target getPackageSources
32
            need srcs
33
            build $ fullTarget target (GhcM stage) srcs [file]
34
            liftIO . IO.removeFile $ file <.> "bak"
35
36
37
38
39
40
41
42
43

        (buildPath -/- ".dependencies") %> \file -> do
            cSrcs <- pkgDataList $ CSrcs path
            let cDepFiles = [ buildPath -/- src <.> "deps" | src <- cSrcs ]
            need $ hDepFile : cDepFiles -- need all for more parallelism
            cDeps <- fmap concat $ mapM readFile' cDepFiles
            hDeps <- readFile' hDepFile
            writeFileChanged file $ cDeps ++ hDeps