Unify include and link paths
[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 pkg <- getPackage
22 path <- getBuildPath
23 incDirs <- getPkgDataList IncludeDirs
24 depDirs <- getPkgDataList DepIncludeDirs
25 mconcat [ arg $ "-I" ++ path
26 , arg $ "-I" ++ path -/- "autogen"
27 , append [ "-I" ++ pkgPath pkg -/- dir | dir <- incDirs ]
28 , append [ "-I" ++ unifyPath dir | dir <- depDirs ] ]
29
30 ldArgs :: Args
31 ldArgs = mempty
32
33 -- TODO: put all validating options together in one file
34 cArgs :: Args
35 cArgs = validating ? cWarnings
36
37 -- TODO: should be in a different file
38 cWarnings :: Args
39 cWarnings = do
40 let gccGe46 = notM $ (flag GccIsClang ||^ flag GccLt46)
41 mconcat [ turnWarningsIntoErrors ? arg "-Werror"
42 , arg "-Wall"
43 , flag GccIsClang ? arg "-Wno-unknown-pragmas"
44 , gccGe46 ? notM windowsHost ? arg "-Werror=unused-but-set-variable"
45 , gccGe46 ? arg "-Wno-error=inline" ]
46
47 argM :: Action String -> Args
48 argM = (arg =<<) . lift
49
50 argSetting :: Setting -> Args
51 argSetting = argM . setting
52
53 argSettingList :: SettingList -> Args
54 argSettingList = (append =<<) . getSettingList
55
56 argStagedSettingList :: (Stage -> SettingList) -> Args
57 argStagedSettingList ss = argSettingList . ss =<< getStage
58
59 argStagedBuilderPath :: (Stage -> Builder) -> Args
60 argStagedBuilderPath sb = argM . builderPath . sb =<< getStage