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