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