Rules.hs 1.29 KB
Newer Older
Andrey Mokhov's avatar
Andrey Mokhov committed
1
module Rules (generateTargets, packageRules) where
2

Ben Gamari's avatar
Ben Gamari committed
3
import Base
quchen's avatar
quchen committed
4
import Data.Foldable
Andrey Mokhov's avatar
Andrey Mokhov committed
5
import Expression
6
import GHC
7
import Rules.Generate
8
import Rules.Package
9
import Rules.Resources
Andrey Mokhov's avatar
Andrey Mokhov committed
10
import Settings
11

quchen's avatar
quchen committed
12
allStages :: [Stage]
quchen's avatar
quchen committed
13
allStages = [minBound ..]
quchen's avatar
quchen committed
14
15

-- | 'need' all top-level build targets
16
generateTargets :: Rules ()
17
generateTargets = action $ do
18
19
20
21
    targets   <- fmap concat (traverse targetsForStage allStages)
    rtsLib    <- pkgLibraryFile Stage1 rts "rts" vanilla
    rtsThrLib <- pkgLibraryFile Stage1 rts "rts" threaded
    need $ targets ++ installTargets ++ [ rtsLib, rtsThrLib ]
22

quchen's avatar
quchen committed
23
24
25
26
targetsForStage :: Stage -> Action [String]
targetsForStage stage = do
    pkgs <- interpretWithStage stage getPackages
    let libPkgs = filter isLibrary pkgs \\ [rts, libffi]
27
    libTargets <- fmap concat . forM libPkgs $ \pkg -> do
quchen's avatar
quchen committed
28
29
30
31
        let target = PartialTarget stage pkg
        needHaddock <- interpretPartial target buildHaddock
        return [ pkgHaddockFile pkg | needHaddock && stage == Stage1 ]
    let programTargets = [ prog | Just prog <- programPath stage <$> pkgs ]
32
    return $ libTargets ++ programTargets
quchen's avatar
quchen committed
33

34
packageRules :: Rules ()
35
36
packageRules = do
    resources <- resourceRules
quchen's avatar
quchen committed
37
    for_ allStages $ \stage ->
quchen's avatar
quchen committed
38
        for_ knownPackages $ \pkg ->
39
            buildPackage resources $ PartialTarget stage pkg