Refactor paths using Context.
[hadrian.git] / src / Settings / Builders / Common.hs
1 module Settings.Builders.Common (
2 includesArgs, cIncludeArgs, ldArgs, 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 context <- getContext
22 pkg <- getPackage
23 incDirs <- getPkgDataList IncludeDirs
24 depDirs <- getPkgDataList DepIncludeDirs
25 let buildPath = contextPath context -/- "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 ldArgs :: Args
32 ldArgs = mempty
33
34 -- TODO: put all validating options together in one file
35 cArgs :: Args
36 cArgs = validating ? cWarnings
37
38 -- TODO: should be in a different file
39 cWarnings :: Args
40 cWarnings = do
41 let gccGe46 = notM $ (flag GccIsClang ||^ flag GccLt46)
42 mconcat [ turnWarningsIntoErrors ? arg "-Werror"
43 , arg "-Wall"
44 , flag GccIsClang ? arg "-Wno-unknown-pragmas"
45 , gccGe46 ? notM windowsHost ? arg "-Werror=unused-but-set-variable"
46 , gccGe46 ? arg "-Wno-error=inline" ]
47
48 argM :: Action String -> Args
49 argM = (arg =<<) . lift
50
51 argSetting :: Setting -> Args
52 argSetting = argM . setting
53
54 argSettingList :: SettingList -> Args
55 argSettingList = (append =<<) . lift . settingList
56
57 argStagedSettingList :: (Stage -> SettingList) -> Args
58 argStagedSettingList ss = (argSettingList . ss) =<< getStage
59
60 argStagedBuilderPath :: (Stage -> Builder) -> Args
61 argStagedBuilderPath sb = (argM . builderPath . sb) =<< getStage