Do not always add -Iincludes to C arguments (#610)
[hadrian.git] / src / Settings / Builders / Common.hs
1 module Settings.Builders.Common (
2 module Base,
3 module Expression,
4 module Oracles.Flag,
5 module Oracles.Setting,
6 module Settings,
7 module UserSettings,
8 cIncludeArgs, ldArgs, cArgs, cWarnings,
9 packageDatabaseArgs, bootPackageDatabaseArgs
10 ) where
11
12 import Base
13 import Expression
14 import GHC.Packages
15 import Hadrian.Haskell.Cabal.PackageData
16 import Oracles.Flag
17 import Oracles.Setting
18 import Settings
19 import UserSettings
20
21 cIncludeArgs :: Args
22 cIncludeArgs = do
23 pkg <- getPackage
24 root <- getBuildRoot
25 path <- getBuildPath
26 incDirs <- getPackageData includeDirs
27 depDirs <- getPackageData depIncludeDirs
28 iconvIncludeDir <- getSetting IconvIncludeDir
29 gmpIncludeDir <- getSetting GmpIncludeDir
30 ffiIncludeDir <- getSetting FfiIncludeDir
31 mconcat [ notStage0 ||^ package compiler ? arg "-Iincludes"
32 , arg $ "-I" ++ root -/- generatedDir
33 , arg $ "-I" ++ path
34 , pure . map ("-I"++) . filter (/= "") $ [iconvIncludeDir, gmpIncludeDir]
35 , flag UseSystemFfi ? arg ("-I" ++ ffiIncludeDir)
36 -- Add @incDirs@ in the build directory, since some files generated
37 -- with @autoconf@ may end up in the build directory.
38 , pure [ "-I" ++ path -/- dir | dir <- incDirs ]
39 -- Add @incDirs@ in the package directory for include files shipped
40 -- with the package.
41 , pure [ "-I" ++ pkgPath pkg -/- dir | dir <- incDirs ]
42 , pure [ "-I" ++ unifyPath dir | dir <- depDirs ] ]
43
44 ldArgs :: Args
45 ldArgs = mempty
46
47 cArgs :: Args
48 cArgs = mempty
49
50 -- TODO: should be in a different file
51 cWarnings :: Args
52 cWarnings = mconcat
53 [ arg "-Wall"
54 , flag GccIsClang ? arg "-Wno-unknown-pragmas"
55 , notM (flag GccIsClang) ? notM windowsHost ? arg "-Werror=unused-but-set-variable"
56 , notM (flag GccIsClang) ? arg "-Wno-error=inline" ]
57
58 packageDatabaseArgs :: Args
59 packageDatabaseArgs = do
60 stage <- getStage
61 dbPath <- expr (packageDbPath stage)
62 expr (need [dbPath -/- packageDbStamp])
63 root <- getBuildRoot
64 prefix <- ifM (builder Ghc) (return "-package-db ") (return "--package-db=")
65 arg $ prefix ++ root -/- relativePackageDbPath stage
66
67 bootPackageDatabaseArgs :: Args
68 bootPackageDatabaseArgs = do
69 stage <- getStage
70 dbPath <- expr $ packageDbPath stage
71 expr $ need [dbPath -/- packageDbStamp]
72 stage0 ? packageDatabaseArgs