Clean up.
[ghc.git] / src / Rules / Dependencies.hs
1 module Rules.Dependencies (buildPackageDependencies) where
2
3 import Expression
4 import GHC
5 import Oracles
6 import Rules.Actions
7 import Rules.Resources
8 import Settings
9
10 buildPackageDependencies :: Resources -> PartialTarget -> Rules ()
11 buildPackageDependencies _ target @ (PartialTarget stage pkg) =
12 let path = targetPath stage pkg
13 buildPath = path -/- "build"
14 dropBuild = (pkgPath pkg ++) . drop (length buildPath)
15 hDepFile = buildPath -/- ".hs-dependencies"
16 platformH = targetPath stage compiler -/- "ghc_boot_platform.h"
17 in do
18 (buildPath <//> "*.c.deps") %> \out -> do
19 let srcFile = dropBuild . dropExtension $ out
20 when (pkg == compiler) $ need [platformH]
21 need [srcFile]
22 build $ fullTarget target (GccM stage) [srcFile] [out]
23
24 hDepFile %> \file -> do
25 srcs <- interpretPartial target getPackageSources
26 when (pkg == compiler) $ need [platformH]
27 need srcs
28 if srcs == []
29 then writeFileChanged file ""
30 else build $ fullTarget target (GhcM stage) srcs [file]
31 removeFileIfExists $ file <.> "bak"
32
33 (buildPath -/- ".dependencies") %> \file -> do
34 cSrcs <- pkgDataList $ CSrcs path
35 let cDepFiles = [ buildPath -/- src <.> "deps" | src <- cSrcs ]
36 need $ hDepFile : cDepFiles -- need all for more parallelism
37 cDeps <- fmap concat $ mapM readFile' cDepFiles
38 hDeps <- readFile' hDepFile
39 -- TODO: very ugly and fragile; use gcc -MM instead?
40 let hsIncl hs incl = buildPath -/- hs <.> "o" ++ " : "
41 ++ buildPath -/- incl ++ "\n"
42 extraDeps = if pkg /= compiler then [] else
43 hsIncl "PrelNames" "primop-vector-uniques.hs-incl"
44 ++ hsIncl "PrimOp" "primop-data-decl.hs-incl"
45 ++ hsIncl "PrimOp" "primop-tag.hs-incl"
46 ++ hsIncl "PrimOp" "primop-list.hs-incl"
47 ++ hsIncl "PrimOp" "primop-strictness.hs-incl"
48 ++ hsIncl "PrimOp" "primop-fixity.hs-incl"
49 ++ hsIncl "PrimOp" "primop-primop-info.hs-incl"
50 ++ hsIncl "PrimOp" "primop-out-of-line.hs-incl"
51 ++ hsIncl "PrimOp" "primop-has-side-effects.hs-incl"
52 ++ hsIncl "PrimOp" "primop-can-fail.hs-incl"
53 ++ hsIncl "PrimOp" "primop-code-size.hs-incl"
54 ++ hsIncl "PrimOp" "primop-commutable.hs-incl"
55 ++ hsIncl "TysPrim" "primop-vector-tys-exports.hs-incl"
56 ++ hsIncl "TysPrim" "primop-vector-tycons.hs-incl"
57 ++ hsIncl "TysPrim" "primop-vector-tys.hs-incl"
58 writeFileChanged file $ cDeps ++ hDeps ++ extraDeps