Rules.hs 1.62 KB
Newer Older
1
module Rules (topLevelTargets, 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 hiding (haddock)
7
import qualified 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
17
18
19
20
21
22
23
topLevelTargets :: Rules ()
topLevelTargets = do

    want $ Rules.Generate.installTargets

    -- TODO: do we want libffiLibrary to be a top-level target?

    action $ do -- TODO: Add support for all rtsWays
24
25
        rtsLib    <- pkgLibraryFile Stage1 rts vanilla
        rtsThrLib <- pkgLibraryFile Stage1 rts threaded
26
27
28
29
        need [ rtsLib, rtsThrLib ]

    for_ allStages $ \stage ->
        for_ (knownPackages \\ [rts, libffi]) $ \pkg -> action $ do
30
31
            let context = vanillaContext stage pkg
            activePackages <- interpretInContext context getPackages
32
33
34
            when (pkg `elem` activePackages) $
                if isLibrary pkg
                then do -- build a library
35
                    ways    <- interpretInContext context getLibraryWays
36
                    libs    <- traverse (pkgLibraryFile stage pkg) ways
37
                    haddock <- interpretInContext context buildHaddock
38
39
40
                    need $ libs ++ [ pkgHaddockFile pkg | haddock && stage == Stage1 ]
                else do -- otherwise build a program
                    need [ fromJust $ programPath stage pkg ] -- TODO: drop fromJust
quchen's avatar
quchen committed
41

42
packageRules :: Rules ()
43
44
packageRules = do
    resources <- resourceRules
quchen's avatar
quchen committed
45
    for_ allStages $ \stage ->
quchen's avatar
quchen committed
46
        for_ knownPackages $ \pkg ->
47
            buildPackage resources $ vanillaContext stage pkg