Compile.hs 2.76 KB
Newer Older
1
{-# LANGUAGE NoImplicitPrelude #-}
Andrey Mokhov's avatar
Andrey Mokhov committed
2
3
4
5
6
module Package.Compile (buildPackageCompile) where

import Package.Base
import Development.Shake.Util

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{- "inplace/bin/ghc-stage1.exe" -hisuf hi -osuf  o -hcsuf hc
-static  -H32m -O
-this-package-key deeps_FT5iVCELxOr62eHY0nbvnU -hide-all-packages
-i -ilibraries/deepseq/. -ilibraries/deepseq/dist-install/build
-ilibraries/deepseq/dist-install/build/autogen
-Ilibraries/deepseq/dist-install/build
-Ilibraries/deepseq/dist-install/build/autogen
-Ilibraries/deepseq/.    
-optP-include -optPlibraries/deepseq/dist-install/build/autogen/cabal_macros.h
-package-key array_3w0nMK0JfaFJPpLFn2yWAJ
-package-key base_469rOtLAqwTGFEOGWxSUiQ
-package-key ghcpr_FgrV6cgh2JHBlbcx1OSlwt
-Wall -XHaskell2010 -O2  -no-user-package-db -rtsopts      
-odir libraries/deepseq/dist-install/build
-hidir libraries/deepseq/dist-install/build
-stubdir libraries/deepseq/dist-install/build
-split-objs 
-c libraries/deepseq/./Control/DeepSeq.hs
-o libraries/deepseq/dist-install/build/Control/DeepSeq.o -}
Andrey Mokhov's avatar
Andrey Mokhov committed
26
27

suffixArgs :: Way -> Args
28
29
30
suffixArgs way = arg ["-hisuf", hisuf way]
              <> arg [ "-osuf",  osuf way]
              <> arg ["-hcsuf", hcsuf way]
Andrey Mokhov's avatar
Andrey Mokhov committed
31

Andrey Mokhov's avatar
Andrey Mokhov committed
32
33
oRule :: Package -> TodoItem -> Rules ()
oRule (Package name path _) (stage, dist, settings) =
34
35
36
    let buildDir = path </> dist </> "build"
        pkgData  = path </> dist </> "package-data.mk"
        depFile  = buildDir </> name <.> "m"
Andrey Mokhov's avatar
Andrey Mokhov committed
37
    in
38
    (buildDir <//> "*o") %> \out -> do
Andrey Mokhov's avatar
Andrey Mokhov committed
39
        let way  = detectWay $ tail $ takeExtension out
40
        need ["shake/src/Package/Compile.hs"]
Andrey Mokhov's avatar
Andrey Mokhov committed
41
42
43
        need [depFile]
        depContents <- parseMakefile <$> (liftIO $ readFile depFile)
        let deps = concat $ snd $ unzip $ filter ((== out) . fst) depContents
44
            srcs = filter ("//*hs" ?==) deps -- TODO: handle *.c sources
Andrey Mokhov's avatar
Andrey Mokhov committed
45
        need deps
46
        terseRun (Ghc stage) $ suffixArgs way
Andrey Mokhov's avatar
Andrey Mokhov committed
47
48
49
            <> wayHcArgs way
            <> arg SrcHcOpts
            <> packageArgs stage pkgData
50
            <> includeArgs path dist
51
            <> concatArgs ["-optP"] (CppOpts pkgData) 
52
53
54
            -- TODO: now we have both -O and -O2
            <> arg ["-Wall", "-XHaskell2010", "-O2"]
            <> productArgs ["-odir", "-hidir", "-stubdir"] buildDir
55
            <> when (splitObjects stage) (arg "-split-objs")
Andrey Mokhov's avatar
Andrey Mokhov committed
56
            <> arg ("-c":srcs)
Andrey Mokhov's avatar
Andrey Mokhov committed
57
            <> arg ["-o", toStandard out]
Andrey Mokhov's avatar
Andrey Mokhov committed
58

59
-- TODO: This rule looks hacky... combine it with the above?
Andrey Mokhov's avatar
Andrey Mokhov committed
60
61
62
63
64
65
66
67
68
69
70
hiRule :: Package -> TodoItem -> Rules ()
hiRule (Package name path _) (stage, dist, settings) =
    let buildDir = path </> dist </> "build"
    in
    (buildDir <//> "*hi") %> \out -> do
        let way  = detectWay $ tail $ takeExtension out
            oFile = out -<.> osuf way
        need [oFile]

buildPackageCompile :: Package -> TodoItem -> Rules ()
buildPackageCompile = oRule <> hiRule