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

import Way
import Base
import Util
import Builder
import Expression
import qualified Target
import Oracles.DependencyList
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
        cDeps <- dependencyList cDepsFile (takeFileName obj -<.> "o")
        if not (null cDeps)
        then do -- obj is produced from a C source file
            need cDeps
            build $ fullTarget target cDeps (Gcc stage) [obj]
        else do -- obj is produced from a Haskell source file
            hDeps <- dependencyList hDepsFile obj
            when (null hDeps) . putError $
                "No dependencies found for '" ++ obj ++ "'."
            let way  = detectWay obj
                hSrc = head hDeps
            unless ("//*hs" ?== hSrc) . putError $
                "No Haskell source file found for '" ++ obj ++ "'."
            need hDeps
            build $ fullTargetWithWay target [hSrc] (Ghc stage) way [obj]
Andrey Mokhov's avatar
Andrey Mokhov committed
45
46
47

    matchBuildResult buildPath "o-boot" ?> \obj -> do
        hDeps <- dependencyList hDepsFile obj
48
49
50
51
52
53
        when (null hDeps) . putError $
            "No dependencies found for '" ++ obj ++ "'."
        let way  = detectWay obj
            hSrc = head hDeps
        unless ("//*.hs-boot" ?== hSrc) . putError $
            "No Haskell source file found for '" ++ obj ++ "'."
Andrey Mokhov's avatar
Andrey Mokhov committed
54
        need hDeps
55
        build $ fullTargetWithWay target [hSrc] (Ghc stage) way [obj]