Continue major refactoring for expression-based build system.
[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 whenPackageKey :: BuildPredicate
15 whenPackageKey = supportsPackageKey && notStage Stage0
16
17 packageSettings :: Settings
18 packageSettings = mconcat
19 [ args ["-hide-all-packages", "-no-user-package-db", "-include-pkg-deps"]
20 , stage Stage0 ? args ["-package-db libraries/bootstrapping.conf"]
21 , whenPackageKey ??
22 ( argPackageKey "-this-package-key" <> argPackageDepKeys "-package-key"
23 , argPackageKey "-package-name" <> argPackageDeps "-package" )]
24
25 librarySettings :: Ways -> Settings
26 librarySettings ways = mconcat
27 [ whenExists vanilla ways ?? ( arg "--enable-library-vanilla"
28 , arg "--disable-library-vanilla" )
29 , (ghcWithInterpreter
30 && not dynamicGhcPrograms
31 && whenExists vanilla ways) ?? ( arg "--enable-library-for-ghci"
32 , arg "--disable-library-for-ghci" )
33 , whenExists profiling ways ?? ( arg "--enable-library-profiling"
34 , arg "--disable-library-profiling" )
35 , whenExists dynamic ways ?? ( arg "--enable-shared"
36 , arg "--disable-shared" )]
37
38 validating :: BuildPredicate
39 validating = false
40
41 ccSettings :: Settings
42 ccSettings = mconcat
43 [ package integerLibrary ? arg "-Ilibraries/integer-gmp2/gmp"
44 , builder GhcCabal ? argConfigStaged "conf-cc-args"
45 , validating ? mconcat
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 ]
54
55 ldSettings :: Settings
56 ldSettings = builder GhcCabal ? argConfigStaged "conf-gcc-linker-args"
57
58 cppSettings :: Settings
59 cppSettings = builder GhcCabal ? argConfigStaged "conf-cpp-args"
60
61 configureSettings :: Settings
62 configureSettings =
63 let conf key = argComplex $ "--configure-option=" ++ key ++ "="
64 in
65 mconcat [ conf "CFLAGS" ccSettings
66 , conf "LDFLAGS" ldSettings
67 , conf "CPPFLAGS" cppSettings
68 , argComplex "--gcc-options=" (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 = mconcat
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 -- bootPackageDb
94 bootPackageDbSettings :: Settings
95 bootPackageDbSettings =
96 stage Stage0 ?
97 argPath "--package-db="
98 (argConfig "ghc-source-path" <> arg "libraries/bootstrapping.conf")
99
100 cabalSettings :: Settings
101 cabalSettings =
102 argsOrdered ["configure", argBuildPath, argBuildDist, dllSettings]
103 `fence`
104 mconcat
105 [ argStagedBuilderPath Ghc -- TODO: used to be limited to max stage1 GHC
106 , argStagedBuilderPath GhcPkg
107 , customConfigureSettings
108 , bootPackageDbSettings
109 , librarySettings targetWays
110 , configNonEmpty "hscolour" ? argBuilderPath HsColour -- TODO: more reuse
111 , configureSettings
112 , stage Stage0 ? argBootPkgConstraints
113 , argStagedBuilderPath Gcc
114 , notStage Stage0 ? argBuilderPath Ld
115 , argBuilderPath Ar
116 , argBuilderPath Alex
117 , argBuilderPath Happy ] -- TODO: reorder with's
118
119 ghcPkgSettings :: Settings
120 ghcPkgSettings =
121 arg "update"
122 `fence` mconcat
123 [ arg "--force"
124 , argPath "" $
125 mconcat [argBuildPath, argBuildDist, arg "inplace-pkg-config"]
126 , bootPackageDbSettings ]