c713c7d5a90567d70af43b6086cf9f5849320e5b
[hadrian.git] / src / Rules.hs
1 module Rules (generateTargets, packageRules) where
2
3 import Expression
4 import Oracles
5 import Rules.Package
6 import Rules.Resources
7 import Settings
8
9 -- generateTargets needs top-level build targets
10 generateTargets :: Rules ()
11 generateTargets = action $ do
12 targets <- fmap concat . forM [Stage0 ..] $ \stage -> do
13 pkgs <- interpretWithStage stage getPackages
14 fmap concat . forM pkgs $ \pkg -> do
15 let target = PartialTarget stage pkg
16 buildPath = targetPath stage pkg -/- "build"
17 libName <- interpretPartial target $ getPkgData LibName
18 needGhciLib <- interpretPartial target $ getPkgData BuildGhciLib
19 needHaddock <- interpretPartial target buildHaddock
20 let ghciLib = [ buildPath -/- "HS" ++ libName <.> "o"
21 | needGhciLib == "YES" && stage /= Stage0 ]
22 haddock = [ pkgHaddockFile pkg | needHaddock ]
23
24 ways <- interpretPartial target getWays
25 libs <- forM ways $ \way -> do
26 extension <- libsuf way
27 return $ buildPath -/- "libHS" ++ libName <.> extension
28
29 return $ ghciLib ++ libs ++ haddock
30
31 need $ reverse targets
32
33 -- TODO: add Stage2 (compiler only?)
34 packageRules :: Rules ()
35 packageRules = do
36 resources <- resourceRules
37 forM_ [Stage0, Stage1] $ \stage ->
38 forM_ knownPackages $ \pkg ->
39 buildPackage resources $ PartialTarget stage pkg