Decompose Settings/Builders/GhcCabal.hs (see #60).
[hadrian.git] / src / Settings / Builders / Common.hs
1 module Settings.Builders.Common (
2 includesArgs, cIncludeArgs, cArgs, cWarnings,
3 argSetting, argSettingList, argStagedBuilderPath, argStagedSettingList
4 ) where
5
6 import Base
7 import Expression
8 import Oracles.Config.Flag
9 import Oracles.Config.Setting
10 import Oracles.PackageData
11 import Settings
12
13 includes :: [FilePath]
14 includes = [ "includes", "includes/dist-derivedconstants/header" ]
15
16 includesArgs :: Args
17 includesArgs = append $ map ("-I" ++) includes
18
19 cIncludeArgs :: Args
20 cIncludeArgs = do
21 stage <- getStage
22 pkg <- getPackage
23 incDirs <- getPkgDataList IncludeDirs
24 depDirs <- getPkgDataList DepIncludeDirs
25 let buildPath = targetPath stage pkg -/- "build"
26 mconcat [ arg $ "-I" ++ buildPath
27 , arg $ "-I" ++ buildPath -/- "autogen"
28 , append [ "-I" ++ pkgPath pkg -/- dir | dir <- incDirs ]
29 , append [ "-I" ++ dir | dir <- depDirs ] ]
30
31 -- TODO: put all validating options together in one file
32 cArgs :: Args
33 cArgs = validating ? cWarnings
34
35 -- TODO: should be in a different file
36 cWarnings :: Args
37 cWarnings = do
38 let gccGe46 = notM $ (flag GccIsClang ||^ flag GccLt46)
39 mconcat [ turnWarningsIntoErrors ? arg "-Werror"
40 , arg "-Wall"
41 , flag GccIsClang ? arg "-Wno-unknown-pragmas"
42 , gccGe46 ? notM windowsHost ? arg "-Werror=unused-but-set-variable"
43 , gccGe46 ? arg "-Wno-error=inline" ]
44
45 argM :: Action String -> Args
46 argM = (arg =<<) . lift
47
48 argSetting :: Setting -> Args
49 argSetting = argM . setting
50
51 argSettingList :: SettingList -> Args
52 argSettingList = (append =<<) . lift . settingList
53
54 argStagedSettingList :: (Stage -> SettingList) -> Args
55 argStagedSettingList ss = (argSettingList . ss) =<< getStage
56
57 argStagedBuilderPath :: (Stage -> Builder) -> Args
58 argStagedBuilderPath sb = (argM . builderPath . sb) =<< getStage