Compile.hs 1.49 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
import Data.Maybe

15
16
17
18
19
20
21
22
23
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"

24
25
26
    matchBuildResult buildPath "hi" ?> \hi -> do
        let way = fromJust . detectWay $ hi -- fromJust is safe
        need [hi -<.> osuf way]
27

28
29
30
31
32
33
    matchBuildResult buildPath "o" ?> \obj -> do
        let way        = fromJust . detectWay $ obj -- fromJust is safe
            vanillaObj = takeFileName obj -<.> "o"
        cDeps <- dependencyList cDepsFile vanillaObj
        hDeps <- dependencyList hDepsFile obj
        let hSrcDeps = filter ("//*hs" ?==) hDeps
34

35
36
        when (null cDeps && null hDeps) $
            putError $ "Cannot determine sources for '" ++ obj ++ "'."
37

38
39
40
41
42
        when (not (null cDeps) && not (null hDeps)) $
            putError $ "Both .c and .hs sources found for '" ++ obj ++ "'."

        need $ hDeps ++ cDeps

43
44
45
        if null cDeps
        then build $ fullTargetWithWay target hSrcDeps (Ghc stage) way [obj]
        else build $ fullTarget        target cDeps    (Gcc stage)     [obj]