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

3
import Base
Andrey Mokhov's avatar
Andrey Mokhov committed
4
import Expression
Andrey Mokhov's avatar
Andrey Mokhov committed
5
import Oracles.PackageData
6
import Rules.Package
7
import Rules.Resources
Andrey Mokhov's avatar
Andrey Mokhov committed
8
import Settings.Packages
Andrey Mokhov's avatar
Andrey Mokhov committed
9
import Settings.User
Andrey Mokhov's avatar
Andrey Mokhov committed
10
import Settings.Util
Andrey Mokhov's avatar
Andrey Mokhov committed
11
12
import Settings.Ways
import Target (PartialTarget (..))
13

Andrey Mokhov's avatar
Andrey Mokhov committed
14
-- generateTargets needs top-level build targets
15
generateTargets :: Rules ()
16
17
generateTargets = action $ do
    targets <- fmap concat . forM [Stage0 ..] $ \stage -> do
18
        pkgs <- interpretWithStage stage getPackages
Andrey Mokhov's avatar
Andrey Mokhov committed
19
        fmap concat . forM pkgs $ \pkg -> do
20
            let target    = PartialTarget stage pkg
Andrey Mokhov's avatar
Andrey Mokhov committed
21
                buildPath = targetPath stage pkg -/- "build"
22
23
24
            libName     <- interpretPartial target $ getPkgData LibName
            needGhciLib <- interpretPartial target $ getPkgData BuildGhciLib
            needHaddock <- interpretPartial target buildHaddock
Andrey Mokhov's avatar
Andrey Mokhov committed
25
26
27
            let ghciLib = [ buildPath -/- "HS" ++ libName <.> "o"
                          | needGhciLib == "YES" && stage /= Stage0 ]
                haddock = [ pkgHaddockFile pkg | needHaddock ]
Andrey Mokhov's avatar
Andrey Mokhov committed
28

29
            ways <- interpretPartial target getWays
Andrey Mokhov's avatar
Andrey Mokhov committed
30
31
            libs <- forM ways $ \way -> do
                extension <- libsuf way
Andrey Mokhov's avatar
Andrey Mokhov committed
32
                return $ buildPath -/- "libHS" ++ libName <.> extension
Andrey Mokhov's avatar
Andrey Mokhov committed
33

Andrey Mokhov's avatar
Andrey Mokhov committed
34
            return $ ghciLib ++ libs ++ haddock
Andrey Mokhov's avatar
Andrey Mokhov committed
35

36
    need $ reverse targets
37

38
-- TODO: add Stage2 (compiler only?)
39
packageRules :: Rules ()
40
41
packageRules = do
    resources <- resourceRules
42
43
44
    forM_ [Stage0, Stage1] $ \stage ->
        forM_ knownPackages $ \pkg ->
            buildPackage resources $ PartialTarget stage pkg