Don't generate in-tree directories by ghc-cabal
[hadrian.git] / src / Settings / Builders / Common.hs
1 module Settings.Builders.Common (
2 module Base,
3 module Expression,
4 module GHC,
5 module Oracles.Config.Flag,
6 module Oracles.Config.Setting,
7 module Oracles.PackageData,
8 module Oracles.Path,
9 module Predicate,
10 module Settings,
11 module Settings.Path,
12 module UserSettings,
13 cIncludeArgs, ldArgs, cArgs, cWarnings, argSetting, argSettingList,
14 argStagedBuilderPath, argStagedSettingList, bootPackageDatabaseArgs
15 ) where
16
17 import Base
18 import Expression
19 import GHC
20 import Oracles.Config.Flag
21 import Oracles.Config.Setting
22 import Oracles.PackageData
23 import Oracles.Path
24 import Predicate
25 import Settings
26 import Settings.Path
27 import UserSettings
28
29 cIncludeArgs :: Args
30 cIncludeArgs = do
31 pkg <- getPackage
32 path <- getBuildPath
33 incDirs <- getPkgDataList IncludeDirs
34 depDirs <- getPkgDataList DepIncludeDirs
35 mconcat [ arg "-Iincludes"
36 , arg $ "-I" ++ generatedPath
37 , arg $ "-I" ++ path
38 , append [ "-I" ++ pkgPath pkg -/- dir | dir <- incDirs ]
39 , append [ "-I" ++ unifyPath dir | dir <- depDirs ] ]
40
41 ldArgs :: Args
42 ldArgs = mempty
43
44 -- TODO: put all validating options together in one file
45 cArgs :: Args
46 cArgs = validating ? cWarnings
47
48 -- TODO: should be in a different file
49 cWarnings :: Args
50 cWarnings = do
51 let gccGe46 = notM $ (flag GccIsClang ||^ flag GccLt46)
52 mconcat [ turnWarningsIntoErrors ? arg "-Werror"
53 , arg "-Wall"
54 , flag GccIsClang ? arg "-Wno-unknown-pragmas"
55 , gccGe46 ? notM windowsHost ? arg "-Werror=unused-but-set-variable"
56 , gccGe46 ? arg "-Wno-error=inline" ]
57
58 argM :: Action String -> Args
59 argM = (arg =<<) . lift
60
61 argSetting :: Setting -> Args
62 argSetting = argM . setting
63
64 argSettingList :: SettingList -> Args
65 argSettingList = (append =<<) . getSettingList
66
67 argStagedSettingList :: (Stage -> SettingList) -> Args
68 argStagedSettingList ss = argSettingList . ss =<< getStage
69
70 argStagedBuilderPath :: (Stage -> Builder) -> Args
71 argStagedBuilderPath sb = argM . builderPath . sb =<< getStage
72
73 bootPackageDatabaseArgs :: Args
74 bootPackageDatabaseArgs = do
75 stage <- getStage
76 lift $ need [packageDbStamp stage]
77 stage0 ? do
78 path <- getTopDirectory
79 prefix <- ifM (builder Ghc) (return "-package-db ") (return "--package-db=")
80 arg $ prefix ++ path -/- packageDbDirectory Stage0