Implement buildPackageDependencies rule.
[hadrian.git] / src / Settings / Util.hs
1 module Settings.Util (
2 -- Primitive settings elements
3 arg, argM,
4 argSetting, argSettingList,
5 getFlag, getSetting, getSettingList,
6 getPkgData, getPkgDataList,
7 appendCcArgs,
8 needBuilder
9 -- argBuilderPath, argStagedBuilderPath,
10 -- argPackageKey, argPackageDeps, argPackageDepKeys, argSrcDirs,
11 -- argIncludeDirs, argDepIncludeDirs,
12 -- argConcat, argConcatPath, argConcatSpace,
13 -- argPairs, argPrefix, argPrefixPath,
14 -- argPackageConstraints,
15 ) where
16
17 import Builder
18 import Expression
19 import Oracles.Base
20 import Oracles.Flag
21 import Oracles.Setting
22 import Oracles.PackageData
23 import Settings.User
24 import Settings.TargetDirectory
25
26 -- A single argument.
27 arg :: String -> Args
28 arg = append . return
29
30 argM :: Action String -> Args
31 argM = appendM . fmap return
32
33 argSetting :: Setting -> Args
34 argSetting = argM . setting
35
36 argSettingList :: SettingList -> Args
37 argSettingList = appendM . settingList
38
39 getFlag :: Flag -> Expr Bool
40 getFlag = lift . flag
41
42 getSetting :: Setting -> Expr String
43 getSetting = lift . setting
44
45 getSettingList :: SettingList -> Expr [String]
46 getSettingList = lift . settingList
47
48 getPkgData :: (FilePath -> PackageData) -> Expr String
49 getPkgData key = do
50 stage <- getStage
51 pkg <- getPackage
52 lift . pkgData . key $ targetPath stage pkg
53
54 getPkgDataList :: (FilePath -> PackageDataList) -> Expr [String]
55 getPkgDataList key = do
56 stage <- getStage
57 pkg <- getPackage
58 lift . pkgDataList . key $ targetPath stage pkg
59
60 -- Pass arguments to Gcc and corresponding lists of sub-arguments of GhcCabal
61 appendCcArgs :: [String] -> Args
62 appendCcArgs xs = do
63 stage <- getStage
64 mconcat [ builder (Gcc stage) ? append xs
65 , builder (GccM stage) ? append xs
66 , builder GhcCabal ? appendSub "--configure-option=CFLAGS" xs
67 , builder GhcCabal ? appendSub "--gcc-options" xs ]
68
69 -- Make sure a builder exists on the given path and rebuild it if out of date.
70 -- If laxDependencies is true (Settings/User.hs) then we do not rebuild GHC
71 -- even if it is out of date (can save a lot of build time when changing GHC).
72 needBuilder :: Builder -> Action ()
73 needBuilder ghc @ (Ghc stage) = do
74 path <- builderPath ghc
75 if laxDependencies then orderOnly [path] else need [path]
76
77 needBuilder builder = do
78 path <- builderPath builder
79 need [path]
80
81 -- TODO: do '-ticky' in all debug ways?
82 -- wayHcArgs :: Way -> Args
83 -- wayHcArgs (Way _ units) = args
84 -- [ if (Dynamic `elem` units)
85 -- then args ["-fPIC", "-dynamic"]
86 -- else arg "-static"
87 -- , when (Threaded `elem` units) $ arg "-optc-DTHREADED_RTS"
88 -- , when (Debug `elem` units) $ arg "-optc-DDEBUG"
89 -- , when (Profiling `elem` units) $ arg "-prof"
90 -- , when (Logging `elem` units) $ arg "-eventlog"
91 -- , when (Parallel `elem` units) $ arg "-parallel"
92 -- , when (GranSim `elem` units) $ arg "-gransim"
93 -- , when (units == [Debug] || units == [Debug, Dynamic]) $
94 -- args ["-ticky", "-DTICKY_TICKY"] ]