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