Implement buildPackageDependencies rule.
[hadrian.git] / src / Rules / Data.hs
1 module Rules.Data (buildPackageData) where
2
3 import Util
4 import Package
5 import Builder
6 import Switches
7 import Expression
8 import qualified Target
9 import Settings.TargetDirectory
10 import Rules.Actions
11 import Control.Applicative
12 import Control.Monad.Extra
13 import Development.Shake
14
15 -- Build package-data.mk by using GhcCabal to process pkgCabal file
16 buildPackageData :: StagePackageTarget -> Rules ()
17 buildPackageData target =
18 let stage = Target.stage target
19 pkg = Target.package target
20 path = targetPath stage pkg
21 in
22 (path -/-) <$>
23 [ "package-data.mk"
24 , "haddock-prologue.txt"
25 , "inplace-pkg-config"
26 , "setup-config"
27 , "build" -/- "autogen" -/- "cabal_macros.h"
28 -- TODO: Is this needed? Also check out Paths_cpsa.hs.
29 -- , "build" -/- "autogen" -/- ("Paths_" ++ name) <.> "hs"
30 ] &%> \files -> do
31 let configure = pkgPath pkg -/- "configure"
32 -- GhcCabal will run the configure script, so we depend on it
33 need [pkgPath pkg -/- pkgCabal pkg]
34 -- We still don't know who built the configure script from configure.ac
35 whenM (doesFileExist $ configure <.> "ac") $ need [configure]
36 build $ fullTarget target files GhcCabal
37 buildWhen registerPackage $ fullTarget target files (GhcPkg stage)
38 postProcessPackageData $ path -/- "package-data.mk"
39
40 -- Prepare a given 'packaga-data.mk' file for parsing by readConfigFile:
41 -- 1) Drop lines containing '$'
42 -- For example, get rid of
43 -- libraries/Win32_dist-install_CMM_SRCS := $(addprefix cbits/,$(notdir ...
44 -- Reason: we don't need them and we can't parse them.
45 -- 2) Replace '/' and '\' with '_' before '='
46 -- For example libraries/deepseq/dist-install_VERSION = 1.4.0.0
47 -- is replaced by libraries_deepseq_dist-install_VERSION = 1.4.0.0
48 -- Reason: Shake's built-in makefile parser doesn't recognise slashes
49
50 postProcessPackageData :: FilePath -> Action ()
51 postProcessPackageData file = do
52 pkgData <- (filter ('$' `notElem`) . lines) <$> liftIO (readFile file)
53 length pkgData `seq` writeFileLines file $ map processLine pkgData
54 where
55 processLine line = replaceSeparators '_' prefix ++ suffix
56 where
57 (prefix, suffix) = break (== '=') line