Add support for non-library packages.
[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 let (libPkgs, programPkgs) = partition isLibrary pkgs
15 libTargets <- fmap concat . forM libPkgs $ \pkg -> do
16 let target = PartialTarget stage pkg
17 buildPath = targetPath stage pkg -/- "build"
18 libName <- interpretPartial target $ getPkgData LibName
19 needGhciLib <- interpretPartial target $ getPkgData BuildGhciLib
20 needHaddock <- interpretPartial target buildHaddock
21 ways <- interpretPartial target getWays
22 let ghciLib = buildPath -/- "HS" ++ libName <.> "o"
23 haddock = pkgHaddockFile pkg
24 libs <- forM ways $ \way -> do
25 extension <- libsuf way
26 return $ buildPath -/- "libHS" ++ libName <.> extension
27
28 return $ [ ghciLib | needGhciLib == "YES" && stage == Stage1 ]
29 ++ [ haddock | needHaddock && stage == Stage1 ]
30 ++ libs
31
32 let programTargets = map (fromJust . programPath stage) programPkgs
33
34 return $ libTargets ++ programTargets
35
36 need $ reverse targets
37
38 -- TODO: add Stage2 (compiler only?)
39 packageRules :: Rules ()
40 packageRules = do
41 resources <- resourceRules
42 forM_ [Stage0, Stage1] $ \stage ->
43 forM_ knownPackages $ \pkg ->
44 buildPackage resources $ PartialTarget stage pkg