Compile.hs 1.32 KB
Newer Older
1 2 3 4 5 6 7 8
module Rules.Compile (compilePackage) where

import Way
import Base
import Util
import Builder
import Expression
import qualified Target
Andrey Mokhov's avatar
Andrey Mokhov committed
9
import Oracles.Dependencies
10 11 12
import Settings.TargetDirectory
import Rules.Actions
import Rules.Resources
13

14 15 16 17 18 19 20 21 22
compilePackage :: Resources -> StagePackageTarget -> Rules ()
compilePackage _ target = do
    let stage     = Target.stage target
        pkg       = Target.package target
        path      = targetPath stage pkg
        buildPath = path -/- "build"
        cDepsFile = buildPath -/- "c.deps"
        hDepsFile = buildPath -/- "haskell.deps"

Andrey Mokhov's avatar
Andrey Mokhov committed
23 24 25 26 27
    matchBuildResult buildPath "hi" ?> \hi ->
        need [ hi -<.> osuf (detectWay hi) ]

    matchBuildResult buildPath "hi-boot" ?> \hiboot ->
        need [ hiboot -<.> obootsuf (detectWay hiboot) ]
28

29
    matchBuildResult buildPath "o" ?> \obj -> do
Andrey Mokhov's avatar
Andrey Mokhov committed
30 31 32 33 34 35 36
        (src, deps) <- dependencies buildPath obj
        need deps
        if ("//*.c" ?== src)
        then build $ fullTarget target (Gcc stage) [src] [obj]
        else do
            let way = detectWay obj
            build $ fullTargetWithWay target (Ghc stage) way [src] [obj]
Andrey Mokhov's avatar
Andrey Mokhov committed
37 38

    matchBuildResult buildPath "o-boot" ?> \obj -> do
Andrey Mokhov's avatar
Andrey Mokhov committed
39 40 41 42
        (src, deps) <- dependencies buildPath obj
        need deps
        let way = detectWay obj
        build $ fullTargetWithWay target (Ghc stage) way [src] [obj]