Factor out Context from Target.
[hadrian.git] / src / Rules / Register.hs
1 {-# LANGUAGE RecordWildCards #-}
2 module Rules.Register (registerPackage) where
3
4 import Data.Char
5
6 import Base
7 import Context
8 import Expression
9 import GHC
10 import Rules.Actions
11 import Rules.Libffi
12 import Rules.Resources
13 import Settings
14 import Settings.Packages.Rts
15 import Target
16
17 -- TODO: Use way from Context, #207
18 -- Build package-data.mk by using GhcCabal to process pkgCabal file
19 registerPackage :: Resources -> Context -> Rules ()
20 registerPackage rs context @ (Context {..}) = do
21 let oldPath = pkgPath package -/- targetDirectory stage package -- TODO: remove, #113
22 pkgConf = packageDbDirectory stage -/- pkgNameString package
23 match f = case stripPrefix (pkgConf ++ "-") f of
24 Nothing -> False
25 Just suf -> dropWhile (\c -> isDigit c || c == '.') suf == "conf"
26
27 when (stage <= Stage1) $ match ?> \conf -> do
28 -- This produces pkgConfig. TODO: Add explicit tracking
29 need [pkgDataFile stage package]
30
31 -- Post-process inplace-pkg-config. TODO: remove, see #113, #148
32 let pkgConfig = oldPath -/- "inplace-pkg-config"
33 fixPkgConf = unlines
34 . map (replace oldPath (targetPath stage package)
35 . replace (replaceSeparators '\\' $ oldPath)
36 (targetPath stage package) )
37 . lines
38
39 fixFile pkgConfig fixPkgConf
40
41 buildWithResources [(resPackageDb rs, resPackageDbLimit)] $
42 Target context (GhcPkg stage) [pkgConfig] [conf]
43
44 when (package == rts && stage == Stage1) $ do
45 packageDbDirectory Stage1 -/- "rts.conf" %> \conf -> do
46 need [rtsConf]
47 buildWithResources [(resPackageDb rs, resPackageDbLimit)] $
48 Target context (GhcPkg stage) [rtsConf] [conf]
49
50 rtsConf %> \_ -> do
51 need [ pkgDataFile Stage1 rts, rtsConfIn ]
52 build $ Target context HsCpp [rtsConfIn] [rtsConf]
53
54 let fixRtsConf = unlines
55 . map
56 ( replace "\"\"" ""
57 . replace "rts/dist/build" rtsBuildPath )
58 . filter (not . null)
59 . lines
60
61 fixFile rtsConf fixRtsConf