539dfb9084b40c1e146f55cf8c8321f30ef0f02c
[hadrian.git] / src / Rules / Compile.hs
1 module Rules.Compile (compilePackage) where
2
3 import Base
4 import Context
5 import Expression
6 import Oracles.Dependencies
7 import Rules.Actions
8 import Settings
9 import Target
10
11 compilePackage :: [(Resource, Int)] -> Context -> Rules ()
12 compilePackage rs context @ (Context {..}) = do
13 let buildPath = contextPath context -/- "build"
14
15 buildPath <//> "*" <.> hisuf way %> \hi ->
16 if compileInterfaceFilesSeparately
17 then do
18 (src, deps) <- dependencies buildPath $ hi -<.> osuf way
19 need $ src : deps
20 buildWithResources rs $ Target context (Ghc stage) [src] [hi]
21 else need [ hi -<.> osuf way ]
22
23 buildPath <//> "*" <.> hibootsuf way %> \hiboot ->
24 if compileInterfaceFilesSeparately
25 then do
26 (src, deps) <- dependencies buildPath $ hiboot -<.> obootsuf way
27 need $ src : deps
28 buildWithResources rs $ Target context (Ghc stage) [src] [hiboot]
29 else need [ hiboot -<.> obootsuf way ]
30
31 -- TODO: add dependencies for #include of .h and .hs-incl files (gcc -MM?)
32 buildPath <//> "*" <.> osuf way %> \obj -> do
33 (src, deps) <- dependencies buildPath obj
34 if ("//*.c" ?== src)
35 then do
36 need $ src : deps
37 build $ Target context (Gcc stage) [src] [obj]
38 else do
39 if compileInterfaceFilesSeparately && "//*.hs" ?== src
40 then need $ (obj -<.> hisuf way) : src : deps
41 else need $ src : deps
42 buildWithResources rs $ Target context (Ghc stage) [src] [obj]
43
44 -- TODO: get rid of these special cases
45 buildPath <//> "*" <.> obootsuf way %> \obj -> do
46 (src, deps) <- dependencies buildPath obj
47 if compileInterfaceFilesSeparately
48 then need $ (obj -<.> hibootsuf way) : src : deps
49 else need $ src : deps
50 buildWithResources rs $ Target context (Ghc stage) [src] [obj]