Add Simplify instances for PG and Predicate.
[hadrian.git] / src / Settings.hs
1 {-# LANGUAGE NoImplicitPrelude, FlexibleInstances #-}
2
3 module Settings (
4 -- IntegerLibrary (..), integerLibrary, integerLibraryName,
5 buildHaddock
6 ) where
7
8 import Base hiding (arg, args, Args)
9 import Targets
10 import Ways
11 import Oracles.Builder
12 import Expression.Base
13
14 validating :: BuildPredicate
15 validating = false
16
17 packageSettings :: Settings
18 packageSettings = msum
19 [ args ["-hide-all-packages", "-no-user-package-db", "-include-pkg-deps"]
20 , stage Stage0 ?
21 (arg "-package-db" |> argPath "libraries/bootstrapping.conf")
22 , supportsPackageKey && notStage Stage0 ??
23 ( argPairs "-this-package-key" argPackageKey <|>
24 argPairs "-package-key" argPackageDepKeys
25 , argPairs "-package-name" argPackageKey <|>
26 argPairs "-package" argPackageDeps )]
27
28 librarySettings :: Ways -> Settings
29 librarySettings ways = msum
30 [ whenExists vanilla ways ?? ( arg "--enable-library-vanilla"
31 , arg "--disable-library-vanilla" )
32 , (ghcWithInterpreter
33 && not dynamicGhcPrograms
34 && whenExists vanilla ways) ?? ( arg "--enable-library-for-ghci"
35 , arg "--disable-library-for-ghci" )
36 , whenExists profiling ways ?? ( arg "--enable-library-profiling"
37 , arg "--disable-library-profiling" )
38 , whenExists dynamic ways ?? ( arg "--enable-shared"
39 , arg "--disable-shared" )]
40
41 ccSettings :: Settings
42 ccSettings = msum
43 [ package integerLibrary ? argPath "-Ilibraries/integer-gmp2/gmp"
44 , builder GhcCabal ? argStagedConfig "conf-cc-args"
45 , validating ? msum
46 [ not (builder GhcCabal) ? arg "-Werror"
47 , arg "-Wall"
48 , gccIsClang ??
49 ( arg "-Wno-unknown-pragmas" <|>
50 not gccLt46 && windowsHost ? arg "-Werror=unused-but-set-variable"
51 , not gccLt46 ? arg "-Wno-error=inline" )]]
52
53 ldSettings :: Settings
54 ldSettings = builder GhcCabal ? argStagedConfig "conf-gcc-linker-args"
55
56 cppSettings :: Settings
57 cppSettings = builder GhcCabal ? argStagedConfig "conf-cpp-args"
58
59 configureSettings :: Settings
60 configureSettings =
61 let conf key = argPrefix ("--configure-option=" ++ key ++ "=")
62 . argConcatSpace
63 in
64 msum [ conf "CFLAGS" ccSettings
65 , conf "LDFLAGS" ldSettings
66 , conf "CPPFLAGS" cppSettings
67 , argPrefix "--gcc-options=" $
68 argConcatSpace (ccSettings <|> ldSettings)
69 , conf "--with-iconv-includes" (argConfig "iconv-include-dirs")
70 , conf "--with-iconv-libraries" (argConfig "iconv-lib-dirs")
71 , conf "--with-gmp-includes" (argConfig "gmp-include-dirs")
72 , conf "--with-gmp-libraries" (argConfig "gmp-lib-dirs")
73 -- TODO: why TargetPlatformFull and not host?
74 , crossCompiling ?
75 conf "--host" (argConfig "target-platform-full")
76 , conf "--with-cc" (argStagedBuilderPath Gcc) ]
77
78 -- this is a positional argument, hence:
79 -- * if it is empty, we need to emit one empty string argument
80 -- * otherwise, we must collapse it into one space-separated string
81 dllSettings :: Settings
82 dllSettings = arg ""
83
84 -- customConfArgs
85 customConfigureSettings :: Settings
86 customConfigureSettings = msum
87 [ package base ? arg ("--flags=" ++ integerLibraryName)
88 , package ghcPrim ? arg "--flag=include-ghc-prim"
89 , package integerLibrary && windowsHost ?
90 arg "--configure-option=--with-intree-gmp"
91 ]
92
93 bootPackageDbSettings :: Settings
94 bootPackageDbSettings =
95 stage Stage0 ?
96 argPrefix "--package-db="
97 (argConcatPath $ argConfig "ghc-source-path" |>
98 argPath "libraries/bootstrapping.conf")
99
100 cabalSettings :: Settings
101 cabalSettings =
102 mproduct
103 [ argBuilderPath GhcCabal
104 , arg "configure"
105 , argBuildPath
106 , argBuildDir
107 , dllSettings
108 , msum
109 [ argWithStagedBuilder Ghc -- TODO: used to be limited to max stage1 GHC
110 , argWithStagedBuilder GhcPkg
111 , customConfigureSettings
112 , stage Stage0 ? bootPackageDbSettings
113 , librarySettings targetWays
114 , configNonEmpty "hscolour" ? argWithBuilder HsColour -- TODO: more reuse
115 , configureSettings
116 , stage Stage0 ? argBootPkgConstraints
117 , argWithStagedBuilder Gcc
118 , notStage Stage0 ? argWithBuilder Ld
119 , argWithBuilder Ar
120 , argWithBuilder Alex
121 , argWithBuilder Happy ]] -- TODO: reorder with's
122
123 ghcPkgSettings :: Settings
124 ghcPkgSettings =
125 arg "update" |> msum
126 [ arg "--force"
127 , argConcatPath $
128 msum [argBuildPath, argBuildDir, arg "inplace-pkg-config"]
129 , bootPackageDbSettings ]