Remove notP and (??) Predicate functions.
[hadrian.git] / src / Settings / Builders / GhcCabal.hs
1 module Settings.Builders.GhcCabal (
2 cabalArgs, ghcCabalHsColourArgs,
3 bootPackageDbArgs, customPackageArgs
4 ) where
5
6 import Way
7 import Stage
8 import Builder
9 import Package
10 import Expression
11 import Predicates
12 import Oracles
13 import Settings
14
15 cabalArgs :: Args
16 cabalArgs = builder GhcCabal ? do
17 path <- getPackagePath
18 dir <- getTargetDirectory
19 mconcat [ arg "configure"
20 , arg path
21 , arg dir
22 , dllArgs
23 , withStaged Ghc
24 , withStaged GhcPkg
25 , stage0 ? bootPackageDbArgs
26 , libraryArgs
27 , with HsColour
28 , configureArgs
29 , packageConstraints
30 , withStaged Gcc
31 , notStage0 ? with Ld
32 , with Ar
33 , with Alex
34 , with Happy ]
35
36 ghcCabalHsColourArgs :: Args
37 ghcCabalHsColourArgs = builder GhcCabalHsColour ? do
38 path <- getPackagePath
39 dir <- getTargetDirectory
40 mconcat [ arg "hscolour"
41 , arg path
42 , arg dir ]
43
44 -- TODO: Isn't vanilla always built? If yes, some conditions are redundant.
45 -- TODO: Need compiler_stage1_CONFIGURE_OPTS += --disable-library-for-ghci?
46 libraryArgs :: Args
47 libraryArgs = do
48 ways <- getWays
49 ghcInt <- lift $ ghcWithInterpreter
50 append [ if vanilla `elem` ways
51 then "--enable-library-vanilla"
52 else "--disable-library-vanilla"
53 , if vanilla `elem` ways && ghcInt && not dynamicGhcPrograms
54 then "--enable-library-for-ghci"
55 else "--disable-library-for-ghci"
56 , if profiling `elem` ways
57 then "--enable-library-profiling"
58 else "--disable-library-profiling"
59 , if dynamic `elem` ways
60 then "--enable-shared"
61 else "--disable-shared" ]
62
63 configureArgs :: Args
64 configureArgs = do
65 let conf key = appendSubD $ "--configure-option=" ++ key
66 cFlags = mconcat [ ccArgs
67 , remove ["-Werror"]
68 , argStagedSettingList ConfCcArgs ]
69 ldFlags = ldArgs <> (argStagedSettingList ConfGccLinkerArgs)
70 cppFlags = cppArgs <> (argStagedSettingList ConfCppArgs)
71 mconcat
72 [ conf "CFLAGS" cFlags
73 , conf "LDFLAGS" ldFlags
74 , conf "CPPFLAGS" cppFlags
75 , appendSubD "--gcc-options" $ cFlags <> ldFlags
76 , conf "--with-iconv-includes" $ argSettingList IconvIncludeDirs
77 , conf "--with-iconv-libraries" $ argSettingList IconvLibDirs
78 , conf "--with-gmp-includes" $ argSettingList GmpIncludeDirs
79 , conf "--with-gmp-libraries" $ argSettingList GmpLibDirs
80 -- TODO: why TargetPlatformFull and not host?
81 , crossCompiling ? (conf "--host" $ argSetting TargetPlatformFull)
82 , conf "--with-cc" $ argStagedBuilderPath Gcc ]
83
84 bootPackageDbArgs :: Args
85 bootPackageDbArgs = do
86 path <- getSetting GhcSourcePath
87 arg $ "--package-db=" ++ path -/- "libraries/bootstrapping.conf"
88
89 -- This is a positional argument, hence:
90 -- * if it is empty, we need to emit one empty string argument;
91 -- * otherwise, we must collapse it into one space-separated string.
92 -- TODO: should be non-empty for compiler
93 dllArgs :: Args
94 dllArgs = arg ""
95
96 packageConstraints :: Args
97 packageConstraints = stage0 ? do
98 constraints <- lift . readFileLines $ bootPackageConstraints
99 append $ concat [ ["--constraint", c] | c <- constraints ]
100
101 -- TODO: should be in a different file
102 -- TODO: put all validating options together in one file
103 ccArgs :: Args
104 ccArgs = validating ? do
105 let notClang = fmap not gccIsClang
106 mconcat [ arg "-Werror"
107 , arg "-Wall"
108 , gccIsClang ? arg "-Wno-unknown-pragmas"
109 , notClang ? gccGe46 ? notWindowsHost ? arg "-Werror=unused-but-set-variable"
110 , notClang ? gccGe46 ? arg "-Wno-error=inline" ]
111
112 ldArgs :: Args
113 ldArgs = mempty
114
115 ghcIncludeDirs :: [FilePath]
116 ghcIncludeDirs = [ "includes", "includes/dist"
117 , "includes/dist-derivedconstants/header"
118 , "includes/dist-ghcconstants/header" ]
119
120 cppArgs :: Args
121 cppArgs = append $ map ("-I" ++) ghcIncludeDirs
122
123 -- TODO: Is this needed?
124 -- ifeq "$(GMP_PREFER_FRAMEWORK)" "YES"
125 -- libraries/integer-gmp_CONFIGURE_OPTS += --with-gmp-framework-preferred
126 -- endif
127
128 -- TODO: move this somewhere
129 customPackageArgs :: Args
130 customPackageArgs = do
131 nextStage <- fmap succ getStage
132 rtsWays <- getRtsWays
133 mconcat
134 [ package integerGmp ?
135 mconcat [ windowsHost ? builder GhcCabal ?
136 arg "--configure-option=--with-intree-gmp"
137 , appendCcArgs ["-I" ++ pkgPath integerGmp -/- "gmp"] ]
138
139 , package base ?
140 builder GhcCabal ?
141 arg ("--flags=" ++ takeFileName (pkgPath integerLibrary))
142
143 , package ghcPrim ?
144 builder GhcCabal ? arg "--flag=include-ghc-prim"
145
146 , package compiler ?
147 builder GhcCabal ?
148 mconcat [ arg $ "--ghc-option=-DSTAGE=" ++ show nextStage
149 , arg $ "--flags=stage" ++ show nextStage
150 , arg "--disable-library-for-ghci"
151 , targetOs "openbsd" ? arg "--ld-options=-E"
152 , flag GhcUnregisterised ? arg "--ghc-option=-DNO_REGS"
153 , fmap not ghcWithSMP ? arg "--ghc-option=-DNOSMP"
154 , fmap not ghcWithSMP ? arg "--ghc-option=-optc-DNOSMP"
155 , (threaded `elem` rtsWays) ?
156 notStage0 ? arg "--ghc-option=-optc-DTHREADED_RTS"
157 , ghcWithNativeCodeGen ? arg "--flags=ncg"
158 , ghcWithInterpreter ?
159 notStage0 ? arg "--flags=ghci"
160 , ghcWithInterpreter ?
161 ghcEnableTablesNextToCode ?
162 fmap not (flag GhcUnregisterised) ?
163 notStage0 ? arg "--ghc-option=-DGHCI_TABLES_NEXT_TO_CODE"
164 , ghcWithInterpreter ?
165 ghciWithDebugger ?
166 notStage0 ? arg "--ghc-option=-DDEBUGGER"
167 , ghcProfiled ?
168 notStage0 ? arg "--ghc-pkg-option=--force"
169 ]
170 ]
171
172 withBuilderKey :: Builder -> String
173 withBuilderKey b = case b of
174 Ar -> "--with-ar="
175 Ld -> "--with-ld="
176 Gcc _ -> "--with-gcc="
177 Ghc _ -> "--with-ghc="
178 Alex -> "--with-alex="
179 Happy -> "--with-happy="
180 GhcPkg _ -> "--with-ghc-pkg="
181 HsColour -> "--with-hscolour="
182 _ -> error "withBuilderKey: not supported builder"
183
184 -- Expression 'with Gcc' appends "--with-gcc=/path/to/gcc" and needs Gcc.
185 with :: Builder -> Args
186 with b = specified b ? do
187 path <- lift $ builderPath b
188 lift $ needBuilder laxDependencies b
189 append [withBuilderKey b ++ path]
190
191 withStaged :: (Stage -> Builder) -> Args
192 withStaged sb = (with . sb) =<< getStage