Rules.hs 2.69 KB
Newer Older
1
module Rules (topLevelTargets, buildRules) where
2

quchen's avatar
quchen committed
3
import Data.Foldable
4
5

import Base
Andrey Mokhov's avatar
Andrey Mokhov committed
6
import Expression
7
import GHC
8
9
10
11
import qualified Rules.Compile
import qualified Rules.Data
import qualified Rules.Dependencies
import qualified Rules.Documentation
12
import qualified Rules.Generate
13
14
15
16
import qualified Rules.Resources
import qualified Rules.Cabal
import qualified Rules.Gmp
import qualified Rules.Libffi
17
import qualified Rules.Library
18
import qualified Rules.Perl
19
20
import qualified Rules.Program
import qualified Rules.Register
21
import qualified Rules.Setup
Andrey Mokhov's avatar
Andrey Mokhov committed
22
import Settings
23

quchen's avatar
quchen committed
24
allStages :: [Stage]
quchen's avatar
quchen committed
25
allStages = [minBound ..]
quchen's avatar
quchen committed
26
27

-- | 'need' all top-level build targets
28
29
30
31
32
33
34
35
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
36
37
        rtsLib    <- pkgLibraryFile Stage1 rts vanilla
        rtsThrLib <- pkgLibraryFile Stage1 rts threaded
38
39
40
41
        need [ rtsLib, rtsThrLib ]

    for_ allStages $ \stage ->
        for_ (knownPackages \\ [rts, libffi]) $ \pkg -> action $ do
42
43
            let context = vanillaContext stage pkg
            activePackages <- interpretInContext context getPackages
44
45
46
            when (pkg `elem` activePackages) $
                if isLibrary pkg
                then do -- build a library
47
48
49
50
                    ways <- interpretInContext context getLibraryWays
                    libs <- traverse (pkgLibraryFile stage pkg) ways
                    docs <- interpretInContext context buildHaddock
                    need $ libs ++ [ pkgHaddockFile pkg | docs && stage == Stage1 ]
51
52
                else do -- otherwise build a program
                    need [ fromJust $ programPath stage pkg ] -- TODO: drop fromJust
quchen's avatar
quchen committed
53

54
packageRules :: Rules ()
55
packageRules = do
56
    resources <- Rules.Resources.resourceRules
quchen's avatar
quchen committed
57
    for_ allStages $ \stage ->
58
59
60
61
62
63
64
65
66
67
        for_ knownPackages $ \package -> do
            let context = vanillaContext stage package
            Rules.Compile.compilePackage resources context
            Rules.Data.buildPackageData context
            Rules.Dependencies.buildPackageDependencies resources context
            Rules.Documentation.buildPackageDocumentation context
            Rules.Generate.generatePackageCode context
            Rules.Library.buildPackageLibrary context
            Rules.Program.buildProgram context
            Rules.Register.registerPackage resources context
68
69
70
71
72
73
74
75
76
77
78

buildRules :: Rules ()
buildRules = mconcat
    [ Rules.Cabal.cabalRules
    , Rules.Generate.generateRules
    , Rules.Generate.copyRules
    , Rules.Gmp.gmpRules
    , Rules.Libffi.libffiRules
    , Rules.Perl.perlScriptRules
    , Rules.Setup.setupRules
    , Rules.packageRules ]