Refactor treatment of wildcards
[ghc.git] / compiler / ghc.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009-2012 The University of Glasgow
4 #
5 # This file is part of the GHC build system.
6 #
7 # To understand how the build system works and how to modify it, see
8 # http://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://ghc.haskell.org/trac/ghc/wiki/Building/Modifying
10 #
11 # -----------------------------------------------------------------------------
12
13 # -----------------------------------------------------------------------------
14 # Create compiler configuration
15 #
16 # The 'echo' commands simply spit the values of various make variables
17 # into Config.hs, whence they can be compiled and used by GHC itself
18
19 # This is just to avoid generating a warning when generating deps
20 # involving RtsFlags.h
21 compiler_stage1_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES
22 compiler_stage2_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES
23 compiler_stage3_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES
24
25 compiler_stage1_C_FILES_NODEPS = compiler/parser/cutils.c
26
27 # This package doesn't pass the Cabal checks because include-dirs
28 # points outside the source directory. This isn't a real problem, so
29 # we just skip the check.
30 compiler_NO_CHECK = YES
31
32 ifneq "$(BINDIST)" "YES"
33 compiler/stage1/package-data.mk : compiler/stage1/build/Config.hs
34 compiler/stage2/package-data.mk : compiler/stage2/build/Config.hs
35 compiler/stage3/package-data.mk : compiler/stage3/build/Config.hs
36
37 compiler/stage1/build/PlatformConstants.o: $(includes_GHCCONSTANTS_HASKELL_TYPE)
38 compiler/stage2/build/PlatformConstants.o: $(includes_GHCCONSTANTS_HASKELL_TYPE)
39 compiler/stage3/build/PlatformConstants.o: $(includes_GHCCONSTANTS_HASKELL_TYPE)
40 compiler/stage1/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_EXPORTS)
41 compiler/stage2/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_EXPORTS)
42 compiler/stage3/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_EXPORTS)
43 compiler/stage1/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
44 compiler/stage2/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
45 compiler/stage3/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
46 endif
47
48 compiler/stage%/build/Config.hs : mk/config.mk mk/project.mk | $$(dir $$@)/.
49 $(call removeFiles,$@)
50 @echo 'Creating $@ ... '
51 @echo '{-# LANGUAGE CPP #-}' >> $@
52 @echo 'module Config where' >> $@
53 @echo >> $@
54 @echo '#include "ghc_boot_platform.h"' >> $@
55 @echo >> $@
56 @echo 'data IntegerLibrary = IntegerGMP' >> $@
57 @echo ' | IntegerSimple' >> $@
58 @echo ' deriving Eq' >> $@
59 @echo >> $@
60 @echo 'cBuildPlatformString :: String' >> $@
61 @echo 'cBuildPlatformString = BuildPlatform_NAME' >> $@
62 @echo 'cHostPlatformString :: String' >> $@
63 @echo 'cHostPlatformString = HostPlatform_NAME' >> $@
64 @echo 'cTargetPlatformString :: String' >> $@
65 @echo 'cTargetPlatformString = TargetPlatform_NAME' >> $@
66 @echo >> $@
67 @echo 'cProjectName :: String' >> $@
68 @echo 'cProjectName = "$(ProjectName)"' >> $@
69 @echo 'cProjectGitCommitId :: String' >> $@
70 @echo 'cProjectGitCommitId = "$(ProjectGitCommitId)"' >> $@
71 @echo 'cProjectVersion :: String' >> $@
72 @echo 'cProjectVersion = "$(ProjectVersion)"' >> $@
73 @echo 'cProjectVersionInt :: String' >> $@
74 @echo 'cProjectVersionInt = "$(ProjectVersionInt)"' >> $@
75 @echo 'cProjectPatchLevel :: String' >> $@
76 @echo 'cProjectPatchLevel = "$(ProjectPatchLevel)"' >> $@
77 @echo 'cProjectPatchLevel1 :: String' >> $@
78 @echo 'cProjectPatchLevel1 = "$(ProjectPatchLevel1)"' >> $@
79 @echo 'cProjectPatchLevel2 :: String' >> $@
80 @echo 'cProjectPatchLevel2 = "$(ProjectPatchLevel2)"' >> $@
81 @echo 'cBooterVersion :: String' >> $@
82 @echo 'cBooterVersion = "$(GhcVersion)"' >> $@
83 @echo 'cStage :: String' >> $@
84 @echo 'cStage = show (STAGE :: Int)' >> $@
85 @echo 'cIntegerLibrary :: String' >> $@
86 @echo 'cIntegerLibrary = "$(INTEGER_LIBRARY)"' >> $@
87 @echo 'cIntegerLibraryType :: IntegerLibrary' >> $@
88 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
89 @echo 'cIntegerLibraryType = IntegerGMP' >> $@
90 else ifeq "$(INTEGER_LIBRARY)" "integer-simple"
91 @echo 'cIntegerLibraryType = IntegerSimple' >> $@
92 else ifneq "$(CLEANING)" "YES"
93 $(error Unknown integer library)
94 endif
95 @echo 'cSupportsSplitObjs :: String' >> $@
96 @echo 'cSupportsSplitObjs = "$(SupportsSplitObjs)"' >> $@
97 @echo 'cGhcWithInterpreter :: String' >> $@
98 @echo 'cGhcWithInterpreter = "$(GhcWithInterpreter)"' >> $@
99 @echo 'cGhcWithNativeCodeGen :: String' >> $@
100 @echo 'cGhcWithNativeCodeGen = "$(GhcWithNativeCodeGen)"' >> $@
101 @echo 'cGhcWithSMP :: String' >> $@
102 @echo 'cGhcWithSMP = "$(GhcWithSMP)"' >> $@
103 @echo 'cGhcRTSWays :: String' >> $@
104 @echo 'cGhcRTSWays = "$(GhcRTSWays)"' >> $@
105 @echo 'cGhcRtsWithLibdw :: String' >> $@
106 @echo 'cGhcRtsWithLibdw = "$(GhcRtsWithLibdw)"' >> $@
107 @echo 'cGhcEnableTablesNextToCode :: String' >> $@
108 @echo 'cGhcEnableTablesNextToCode = "$(GhcEnableTablesNextToCode)"' >> $@
109 @echo 'cLeadingUnderscore :: String' >> $@
110 @echo 'cLeadingUnderscore = "$(LeadingUnderscore)"' >> $@
111 @echo 'cGHC_UNLIT_PGM :: String' >> $@
112 @echo 'cGHC_UNLIT_PGM = "$(utils/unlit_dist_PROG)"' >> $@
113 @echo 'cGHC_SPLIT_PGM :: String' >> $@
114 @echo 'cGHC_SPLIT_PGM = "$(driver/split_dist_PROG)"' >> $@
115 @echo 'cLibFFI :: Bool' >> $@
116 ifeq "$(UseLibFFIForAdjustors)" "YES"
117 @echo 'cLibFFI = True' >> $@
118 else
119 @echo 'cLibFFI = False' >> $@
120 endif
121 # Note that GhcThreaded just reflects the Makefile variable setting.
122 # In particular, the stage1 compiler is never actually compiled with
123 # -threaded, but it will nevertheless have cGhcThreaded = True.
124 # The "+RTS --info" output will show what RTS GHC is really using.
125 @echo 'cGhcThreaded :: Bool' >> $@
126 ifeq "$(GhcThreaded)" "YES"
127 @echo 'cGhcThreaded = True' >> $@
128 else
129 @echo 'cGhcThreaded = False' >> $@
130 endif
131 @echo 'cGhcDebugged :: Bool' >> $@
132 ifeq "$(GhcDebugged)" "YES"
133 @echo 'cGhcDebugged = True' >> $@
134 else
135 @echo 'cGhcDebugged = False' >> $@
136 endif
137 @echo done.
138
139 # -----------------------------------------------------------------------------
140 # Create platform includes
141
142 # Here we generate a little header file containing CPP symbols that GHC
143 # uses to determine which platform it is building on/for. The platforms
144 # can differ between stage1 and stage2 if we're cross-compiling, so we
145 # need one of these header files per stage.
146
147 PLATFORM_H = ghc_boot_platform.h
148
149 compiler/stage1/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
150 $(call removeFiles,$@)
151 @echo "Creating $@..."
152 @echo "#ifndef __PLATFORM_H__" >> $@
153 @echo "#define __PLATFORM_H__" >> $@
154 @echo >> $@
155 @echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
156 @echo "#define HostPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
157 @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
158 @echo >> $@
159 @echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
160 @echo "#define $(HostPlatform_CPP)_HOST 1" >> $@
161 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
162 @echo >> $@
163 @echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
164 @echo "#define $(HostArch_CPP)_HOST_ARCH 1" >> $@
165 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
166 @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
167 @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
168 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
169 @echo >> $@
170 @echo "#define $(BuildOS_CPP)_BUILD_OS 1" >> $@
171 @echo "#define $(HostOS_CPP)_HOST_OS 1" >> $@
172 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
173 @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
174 @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
175 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
176 ifeq "$(TargetOS_CPP)" "irix"
177 @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS" >> $@
178 @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
179 @echo "#endif" >> $@
180 endif
181 @echo >> $@
182 @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
183 @echo "#define $(HostVendor_CPP)_HOST_VENDOR 1" >> $@
184 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
185 @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
186 @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
187 @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
188 @echo >> $@
189 @echo "#endif /* __PLATFORM_H__ */" >> $@
190 @echo "Done."
191
192 # For stage2 and above, the BUILD platform is the HOST of stage1, and
193 # the HOST platform is the TARGET of stage1. The TARGET remains the same
194 # (stage1 is the cross-compiler, not stage2).
195 compiler/stage2/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
196 $(call removeFiles,$@)
197 @echo "Creating $@..."
198 @echo "#ifndef __PLATFORM_H__" >> $@
199 @echo "#define __PLATFORM_H__" >> $@
200 @echo >> $@
201 @echo "#define BuildPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
202 @echo "#define HostPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
203 @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
204 @echo >> $@
205 @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
206 @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
207 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
208 @echo >> $@
209 @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
210 @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
211 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
212 @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
213 @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
214 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
215 @echo >> $@
216 @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
217 @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
218 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
219 @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
220 @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
221 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
222 ifeq "$(TargetOS_CPP)" "irix"
223 @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS" >> $@
224 @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
225 @echo "#endif" >> $@
226 endif
227 @echo >> $@
228 @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
229 @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
230 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
231 @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
232 @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
233 @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
234 @echo >> $@
235 @echo "#endif /* __PLATFORM_H__ */" >> $@
236 @echo "Done."
237
238 compiler/stage3/$(PLATFORM_H) : compiler/stage2/$(PLATFORM_H)
239 "$(CP)" $< $@
240
241 # ----------------------------------------------------------------------------
242 # Generate supporting stuff for prelude/PrimOp.lhs
243 # from prelude/primops.txt
244
245 PRIMOP_BITS_NAMES = primop-data-decl.hs-incl \
246 primop-tag.hs-incl \
247 primop-list.hs-incl \
248 primop-has-side-effects.hs-incl \
249 primop-out-of-line.hs-incl \
250 primop-commutable.hs-incl \
251 primop-code-size.hs-incl \
252 primop-can-fail.hs-incl \
253 primop-strictness.hs-incl \
254 primop-fixity.hs-incl \
255 primop-primop-info.hs-incl \
256 primop-vector-uniques.hs-incl \
257 primop-vector-tys.hs-incl \
258 primop-vector-tys-exports.hs-incl \
259 primop-vector-tycons.hs-incl
260
261 PRIMOP_BITS_STAGE1 = $(addprefix compiler/stage1/build/,$(PRIMOP_BITS_NAMES))
262 PRIMOP_BITS_STAGE2 = $(addprefix compiler/stage2/build/,$(PRIMOP_BITS_NAMES))
263 PRIMOP_BITS_STAGE3 = $(addprefix compiler/stage3/build/,$(PRIMOP_BITS_NAMES))
264
265 compiler_CPP_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
266 compiler_CPP_OPTS += ${GhcCppOpts}
267
268 define preprocessCompilerFiles
269 # $0 = stage
270 compiler/stage$1/build/primops.txt: compiler/prelude/primops.txt.pp compiler/stage$1/$$(PLATFORM_H)
271 $$(HS_CPP) -P $$(compiler_CPP_OPTS) -Icompiler/stage$1 -x c $$< | grep -v '^#pragma GCC' > $$@
272
273 compiler/stage$1/build/primop-data-decl.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
274 "$$(genprimopcode_INPLACE)" --data-decl < $$< > $$@
275 compiler/stage$1/build/primop-tag.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
276 "$$(genprimopcode_INPLACE)" --primop-tag < $$< > $$@
277 compiler/stage$1/build/primop-list.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
278 "$$(genprimopcode_INPLACE)" --primop-list < $$< > $$@
279 compiler/stage$1/build/primop-has-side-effects.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
280 "$$(genprimopcode_INPLACE)" --has-side-effects < $$< > $$@
281 compiler/stage$1/build/primop-out-of-line.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
282 "$$(genprimopcode_INPLACE)" --out-of-line < $$< > $$@
283 compiler/stage$1/build/primop-commutable.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
284 "$$(genprimopcode_INPLACE)" --commutable < $$< > $$@
285 compiler/stage$1/build/primop-code-size.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
286 "$$(genprimopcode_INPLACE)" --code-size < $$< > $$@
287 compiler/stage$1/build/primop-can-fail.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
288 "$$(genprimopcode_INPLACE)" --can-fail < $$< > $$@
289 compiler/stage$1/build/primop-strictness.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
290 "$$(genprimopcode_INPLACE)" --strictness < $$< > $$@
291 compiler/stage$1/build/primop-fixity.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
292 "$$(genprimopcode_INPLACE)" --fixity < $$< > $$@
293 compiler/stage$1/build/primop-primop-info.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
294 "$$(genprimopcode_INPLACE)" --primop-primop-info < $$< > $$@
295 compiler/stage$1/build/primop-vector-uniques.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
296 "$$(genprimopcode_INPLACE)" --primop-vector-uniques < $$< > $$@
297 compiler/stage$1/build/primop-vector-tys.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
298 "$$(genprimopcode_INPLACE)" --primop-vector-tys < $$< > $$@
299 compiler/stage$1/build/primop-vector-tys-exports.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
300 "$$(genprimopcode_INPLACE)" --primop-vector-tys-exports < $$< > $$@
301 compiler/stage$1/build/primop-vector-tycons.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
302 "$$(genprimopcode_INPLACE)" --primop-vector-tycons < $$< > $$@
303
304 # Usages aren't used any more; but the generator
305 # can still generate them if we want them back
306 compiler/stage$1/build/primop-usage.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
307 "$$(genprimopcode_INPLACE)" --usage < $$< > $$@
308
309 endef
310
311 $(eval $(call preprocessCompilerFiles,1))
312 $(eval $(call preprocessCompilerFiles,2))
313 $(eval $(call preprocessCompilerFiles,3))
314
315 # -----------------------------------------------------------------------------
316 # Configuration
317
318 compiler_stage1_CONFIGURE_OPTS += --flags=stage1
319 compiler_stage2_CONFIGURE_OPTS += --flags=stage2
320 compiler_stage3_CONFIGURE_OPTS += --flags=stage3
321
322 ifeq "$(GhcThreaded)" "YES"
323 # We pass THREADED_RTS to the stage2 C files so that cbits/genSym.c will bring
324 # the threaded version of atomic_inc() into scope.
325 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-optc-DTHREADED_RTS
326 endif
327
328 ifeq "$(GhcWithNativeCodeGen)" "YES"
329 compiler_stage1_CONFIGURE_OPTS += --flags=ncg
330 compiler_stage2_CONFIGURE_OPTS += --flags=ncg
331 endif
332
333 ifeq "$(GhcWithInterpreter)" "YES"
334 compiler_stage2_CONFIGURE_OPTS += --flags=ghci
335
336 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
337 # Should GHCI be building info tables in the TABLES_NEXT_TO_CODE style
338 # or not?
339 # XXX This should logically be a CPP option, but there doesn't seem to
340 # be a flag for that
341 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DGHCI_TABLES_NEXT_TO_CODE
342 endif
343
344 # Should the debugger commands be enabled?
345 ifeq "$(GhciWithDebugger)" "YES"
346 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DDEBUGGER
347 endif
348
349 endif
350
351 ifeq "$(TargetOS_CPP)" "openbsd"
352 compiler_CONFIGURE_OPTS += --ld-options=-E
353 endif
354
355 ifeq "$(GhcUnregisterised)" "NO"
356 else
357 compiler_CONFIGURE_OPTS += --ghc-option=-DNO_REGS
358 endif
359
360 ifneq "$(GhcWithSMP)" "YES"
361 compiler_CONFIGURE_OPTS += --ghc-option=-DNOSMP
362 compiler_CONFIGURE_OPTS += --ghc-option=-optc-DNOSMP
363 endif
364
365 # Careful optimisation of the parser: we don't want to throw everything
366 # at it, because that takes too long and doesn't buy much, but we do want
367 # to inline certain key external functions, so we instruct GHC not to
368 # throw away inlinings as it would normally do in -O0 mode.
369 compiler/stage1/build/Parser_HC_OPTS += -O0 -fno-ignore-interface-pragmas
370 # If we're bootstrapping the compiler during stage2, or we're being
371 # built by a GHC whose version is > 7.8, we need -fcmm-sink to be
372 # passed to the compiler. This is required on x86 to avoid the
373 # register allocator running out of stack slots when compiling this
374 # module with -fPIC -dynamic.
375 # See #8182 for all the details
376 ifeq "$(CMM_SINK_BOOTSTRAP_IS_NEEDED)" "YES"
377 compiler/stage1/build/Parser_HC_OPTS += -fcmm-sink
378 endif
379 # We also pass -fcmm-sink to every stage != 1
380 compiler/stage2/build/Parser_HC_OPTS += -O0 -fno-ignore-interface-pragmas -fcmm-sink
381 compiler/stage3/build/Parser_HC_OPTS += -O0 -fno-ignore-interface-pragmas -fcmm-sink
382
383 # On IBM AIX we need to wrokaround XCOFF's TOC limitations (see also
384 # comment in `aclocal.m4` about `-mminimal-toc` for more details)
385 # However, Parser.hc defines so many symbols that `-mminimal-toc`
386 # generates instructions with offsets exceeding the PPC offset
387 # addressing limits. So we need to counter-act this via `-mfull-toc`
388 # which disables a preceding `-mminimal-toc` again.
389 ifeq "$(HostOS_CPP)" "aix"
390 compiler/stage1/build/Parser_HC_OPTS += -optc-mfull-toc
391 endif
392 ifeq "$(TargetOS_CPP)" "aix"
393 compiler/stage2/build/Parser_HC_OPTS += -optc-mfull-toc
394 compiler/stage3/build/Parser_HC_OPTS += -optc-mfull-toc
395 endif
396
397 ifeq "$(GhcProfiled)" "YES"
398 # If we're profiling GHC then we want SCCs. However, adding -auto-all
399 # everywhere tends to give a hard-to-read profile, and adds lots of
400 # overhead. A better approach is to proceed top-down; identify the
401 # parts of the compiler of interest, and then add further cost centres
402 # as necessary. Turn on -fprof-auto for individual modules like this:
403
404 # compiler/main/DriverPipeline_HC_OPTS += -fprof-auto
405 compiler/main/GhcMake_HC_OPTS += -fprof-auto
406 compiler/main/GHC_HC_OPTS += -fprof-auto
407
408 # or alternatively add {-# OPTIONS_GHC -fprof-auto #-} to the top of
409 # modules you're interested in.
410
411 # We seem to still build the vanilla libraries even if we say
412 # --disable-library-vanilla, but installation then fails, as Cabal
413 # doesn't copy the vanilla .hi files, but ghc-pkg complains about
414 # their absence when we register the package. So for now, we just
415 # leave the vanilla libraries enabled.
416 # compiler_stage2_CONFIGURE_OPTS += --disable-library-vanilla
417 compiler_stage2_CONFIGURE_OPTS += --ghc-pkg-option=--force
418 endif
419
420 compiler_stage3_CONFIGURE_OPTS := $(compiler_stage2_CONFIGURE_OPTS)
421
422 compiler_stage1_CONFIGURE_OPTS += --ghc-option=-DSTAGE=1
423 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DSTAGE=2
424 compiler_stage3_CONFIGURE_OPTS += --ghc-option=-DSTAGE=3
425 compiler_stage2_HADDOCK_OPTS += --optghc=-DSTAGE=2
426
427 compiler/stage1/package-data.mk : compiler/ghc.mk
428 compiler/stage2/package-data.mk : compiler/ghc.mk
429 compiler/stage3/package-data.mk : compiler/ghc.mk
430
431 # -----------------------------------------------------------------------------
432 # And build the package
433
434 compiler_PACKAGE = ghc
435
436 # Note [fiddle-stage1-version]
437 # The version of the GHC package changes every day, since the
438 # patchlevel is the current date. We don't want to force
439 # recompilation of the entire compiler when this happens, so for stage
440 # 1 we omit the patchlevel from the version number. For stage 2 we
441 # have to include the patchlevel since this is the package we install,
442 # however.
443 #
444 # Note: we also have to tweak the version number of the package itself
445 # when it gets registered; see Note [munge-stage1-package-config]
446 # below.
447 # The ProjectPatchLevel > 20000000 iff it's a date. If it's e.g. 6.12.1
448 # then we don't want to remove it
449 ifneq "$(CLEANING)" "YES"
450 ifeq "$(shell [ $(ProjectPatchLevel) -gt 20000000 ] && echo YES)" "YES"
451 compiler_stage1_VERSION_MUNGED = YES
452 endif
453 endif
454
455 ifeq "$(compiler_stage1_VERSION_MUNGED)" "YES"
456 compiler_stage1_MUNGED_VERSION = $(subst .$(ProjectPatchLevel),,$(ProjectVersion))
457 define compiler_PACKAGE_MAGIC
458 compiler_stage1_VERSION = $(compiler_stage1_MUNGED_VERSION)
459 compiler_stage1_COMPONENT_ID = $(subst .$(ProjectPatchLevel),,$(compiler_stage1_COMPONENT_ID))
460 endef
461
462 # NB: the COMPONENT_ID munging has no effect for new-style unit ids
463 # (which indeed, have nothing version like in them, but are important for
464 # old-style unit ids which do.) The subst operation is idempotent, so
465 # as long as we do it at least once we should be good.
466
467 # Don't register the non-munged package
468 compiler_stage1_REGISTER_PACKAGE = NO
469
470 endif
471
472 # Don't do splitting for the GHC package, it takes too long and
473 # there's not much benefit.
474 compiler_stage1_SplitObjs = NO
475 compiler_stage2_SplitObjs = NO
476 compiler_stage3_SplitObjs = NO
477 compiler_stage1_SplitSections = NO
478 compiler_stage2_SplitSections = NO
479 compiler_stage3_SplitSections = NO
480
481 # There are too many symbols in the ghc package for a Windows DLL.
482 # We therefore need to split some of the modules off into a separate
483 # DLL. This clump are the modules reachable from DynFlags:
484 compiler_stage2_dll0_START_MODULE = DynFlags
485 compiler_stage2_dll0_MODULES = \
486 Annotations \
487 ApiAnnotation \
488 Avail \
489 Bag \
490 BasicTypes \
491 Binary \
492 BooleanFormula \
493 BreakArray \
494 BufWrite \
495 Class \
496 CmdLineParser \
497 CmmType \
498 CoAxiom \
499 ConLike \
500 Coercion \
501 Config \
502 Constants \
503 CoreArity \
504 CoreFVs \
505 CoreSubst \
506 CoreSyn \
507 CoreTidy \
508 CoreUnfold \
509 CoreUtils \
510 CoreSeq \
511 CoreStats \
512 CostCentre \
513 DataCon \
514 Demand \
515 Digraph \
516 DriverPhases \
517 DynFlags \
518 Encoding \
519 ErrUtils \
520 Exception \
521 FamInstEnv \
522 FastFunctions \
523 FastMutInt \
524 FastString \
525 FastStringEnv \
526 FieldLabel \
527 Fingerprint \
528 FiniteMap \
529 ForeignCall \
530 FV \
531 Hooks \
532 HsBinds \
533 HsDecls \
534 HsDoc \
535 HsExpr \
536 HsImpExp \
537 HsLit \
538 PlaceHolder \
539 HsPat \
540 HsSyn \
541 HsTypes \
542 HsUtils \
543 HscTypes \
544 IOEnv \
545 Id \
546 IdInfo \
547 IfaceSyn \
548 IfaceType \
549 InstEnv \
550 Kind \
551 Lexeme \
552 ListSetOps \
553 Literal \
554 Maybes \
555 MkCore \
556 MkId \
557 Module \
558 MonadUtils \
559 Name \
560 NameEnv \
561 NameSet \
562 OccName \
563 OccurAnal \
564 OptCoercion \
565 OrdList \
566 Outputable \
567 PackageConfig \
568 Packages \
569 Pair \
570 Panic \
571 PatSyn \
572 PipelineMonad \
573 Platform \
574 PlatformConstants \
575 PprCore \
576 PrelNames \
577 PrelRules \
578 Pretty \
579 PrimOp \
580 RdrName \
581 Rules \
582 Serialized \
583 SrcLoc \
584 StaticFlags \
585 StringBuffer \
586 TcEvidence \
587 TcRnTypes \
588 TcType \
589 TrieMap \
590 TyCon \
591 Type \
592 TypeRep \
593 TysPrim \
594 TysWiredIn \
595 Unify \
596 UniqDFM \
597 UniqDSet \
598 UniqFM \
599 UniqSet \
600 UniqSupply \
601 Unique \
602 Util \
603 Var \
604 VarEnv \
605 VarSet
606
607 ifeq "$(GhcWithInterpreter)" "YES"
608 # These files are reacheable from DynFlags
609 # only by GHCi-enabled code (see #9552)
610 compiler_stage2_dll0_MODULES += \
611 Bitmap \
612 BlockId \
613 ByteCodeAsm \
614 ByteCodeInstr \
615 ByteCodeItbls \
616 CLabel \
617 Cmm \
618 CmmCallConv \
619 CmmExpr \
620 CmmInfo \
621 CmmMachOp \
622 CmmNode \
623 CmmSwitch \
624 CmmUtils \
625 CodeGen.Platform \
626 CodeGen.Platform.ARM \
627 CodeGen.Platform.ARM64 \
628 CodeGen.Platform.NoRegs \
629 CodeGen.Platform.PPC \
630 CodeGen.Platform.PPC_Darwin \
631 CodeGen.Platform.SPARC \
632 CodeGen.Platform.X86 \
633 CodeGen.Platform.X86_64 \
634 Hoopl \
635 Hoopl.Dataflow \
636 InteractiveEvalTypes \
637 MkGraph \
638 PprCmm \
639 PprCmmDecl \
640 PprCmmExpr \
641 Reg \
642 RegClass \
643 SMRep \
644 StgCmmArgRep \
645 StgCmmClosure \
646 StgCmmEnv \
647 StgCmmLayout \
648 StgCmmMonad \
649 StgCmmProf \
650 StgCmmTicky \
651 StgCmmUtils \
652 StgSyn \
653 Stream
654 endif
655
656 compiler_stage2_dll0_HS_OBJS = \
657 $(patsubst %,compiler/stage2/build/%.$(dyn_osuf),$(subst .,/,$(compiler_stage2_dll0_MODULES)))
658
659 # if stage is set to something other than "1" or "", disable stage 1
660 # See Note [Stage1Only vs stage=1] in mk/config.mk.in.
661 ifneq "$(filter-out 1,$(stage))" ""
662 compiler_stage1_NOT_NEEDED = YES
663 endif
664 # if stage is set to something other than "2" or "", disable stage 2
665 ifneq "$(filter-out 2,$(stage))" ""
666 compiler_stage2_NOT_NEEDED = YES
667 endif
668 # stage 3 has to be requested explicitly with stage=3
669 ifneq "$(stage)" "3"
670 compiler_stage3_NOT_NEEDED = YES
671 endif
672 $(eval $(call build-package,compiler,stage1,0))
673 $(eval $(call build-package,compiler,stage2,1))
674 $(eval $(call build-package,compiler,stage3,2))
675
676 # We only want to turn keepCAFs on if we will be loading dynamic
677 # Haskell libraries with GHCi. We therefore filter the object file
678 # out for non-dynamic ways.
679 define keepCAFsForGHCiDynOnly
680 # $1 = stage
681 # $2 = way
682 ifeq "$$(findstring dyn, $2)" ""
683 compiler_stage$1_$2_C_OBJS := $$(filter-out %/keepCAFsForGHCi.$$($2_osuf),$$(compiler_stage$1_$2_C_OBJS))
684 endif
685 endef
686 $(foreach w,$(compiler_stage1_WAYS),$(eval $(call keepCAFsForGHCiDynOnly,1,$w)))
687 $(foreach w,$(compiler_stage2_WAYS),$(eval $(call keepCAFsForGHCiDynOnly,2,$w)))
688 $(foreach w,$(compiler_stage3_WAYS),$(eval $(call keepCAFsForGHCiDynOnly,3,$w)))
689
690 # after build-package, because that adds --enable-library-for-ghci
691 # to compiler_stage*_CONFIGURE_OPTS:
692 # We don't build the GHCi library for the ghc package. We can load it
693 # the .a file instead, and as object splitting isn't on for the ghc
694 # package this isn't much slower.However, not building the package saves
695 # a significant chunk of disk space.
696 compiler_stage1_CONFIGURE_OPTS += --disable-library-for-ghci
697 compiler_stage2_CONFIGURE_OPTS += --disable-library-for-ghci
698 compiler_stage3_CONFIGURE_OPTS += --disable-library-for-ghci
699
700 # after build-package, because that sets compiler_stage1_HC_OPTS:
701 ifeq "$(V)" "0"
702 compiler_stage1_HC_OPTS += $(filter-out -Rghc-timing,$(GhcHcOpts)) $(GhcStage1HcOpts)
703 compiler_stage2_HC_OPTS += $(filter-out -Rghc-timing,$(GhcHcOpts)) $(GhcStage2HcOpts)
704 compiler_stage3_HC_OPTS += $(filter-out -Rghc-timing,$(GhcHcOpts)) $(GhcStage3HcOpts)
705 else
706 compiler_stage1_HC_OPTS += $(GhcHcOpts) $(GhcStage1HcOpts)
707 compiler_stage2_HC_OPTS += $(GhcHcOpts) $(GhcStage2HcOpts)
708 compiler_stage3_HC_OPTS += $(GhcHcOpts) $(GhcStage3HcOpts)
709 endif
710
711 ifneq "$(BINDIST)" "YES"
712
713 compiler_stage2_TAGS_HC_OPTS = -package ghc
714 $(eval $(call tags-package,compiler,stage2))
715
716 $(compiler_stage1_depfile_haskell) : compiler/stage1/$(PLATFORM_H)
717 $(compiler_stage2_depfile_haskell) : compiler/stage2/$(PLATFORM_H)
718 $(compiler_stage3_depfile_haskell) : compiler/stage3/$(PLATFORM_H)
719
720 COMPILER_INCLUDES_DEPS += $(includes_H_CONFIG)
721 COMPILER_INCLUDES_DEPS += $(includes_H_PLATFORM)
722 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS)
723 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_TYPE)
724 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
725 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_EXPORTS)
726 COMPILER_INCLUDES_DEPS += $(includes_DERIVEDCONSTANTS)
727
728 $(compiler_stage1_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE1)
729 $(compiler_stage2_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE2)
730 $(compiler_stage3_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE3)
731
732 $(foreach way,$(compiler_stage1_WAYS),\
733 compiler/stage1/build/PrimOp.$($(way)_osuf)) : $(PRIMOP_BITS_STAGE1)
734 $(foreach way,$(compiler_stage2_WAYS),\
735 compiler/stage2/build/PrimOp.$($(way)_osuf)) : $(PRIMOP_BITS_STAGE2)
736 $(foreach way,$(compiler_stage3_WAYS),\
737 compiler/stage3/build/PrimOp.$($(way)_osuf)) : $(PRIMOP_BITS_STAGE3)
738
739
740 # GHC itself doesn't know about the above dependencies, so we have to
741 # switch off the recompilation checker for that module:
742 compiler/prelude/PrimOp_HC_OPTS += -fforce-recomp
743
744 ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
745 compiler/utils/Util_HC_OPTS += -DDYNAMIC_GHC_PROGRAMS
746 endif
747
748 # LibFFI.hs #includes ffi.h
749 ifneq "$(UseSystemLibFFI)" "YES"
750 compiler/stage2/build/LibFFI.hs : $(libffi_HEADERS)
751 endif
752
753 # Note [munge-stage1-package-config]
754 # Strip the date/patchlevel from the version of stage1. See Note
755 # [fiddle-stage1-version] above.
756 # NB: The sed expression for hs-libraries is a bit weird to be POSIX-compliant.
757 ifeq "$(compiler_stage1_VERSION_MUNGED)" "YES"
758 compiler/stage1/inplace-pkg-config-munged: compiler/stage1/inplace-pkg-config
759 sed -e 's/^\(version: .*\)\.$(ProjectPatchLevel)$$/\1/' \
760 -e 's/^\(id: .*\)\.$(ProjectPatchLevel)$$/\1/' \
761 -e 's/^\(hs-libraries: HSghc-.*\)\.$(ProjectPatchLevel)\(-[A-Za-z0-9][A-Za-z0-9]*\)*$$/\1\2/' \
762 < $< > $@
763 "$(compiler_stage1_GHC_PKG)" update --force $(compiler_stage1_GHC_PKG_OPTS) $@
764
765 # We need to make sure the munged config is in the database before we
766 # try to configure ghc-bin
767 ghc/stage1/package-data.mk : compiler/stage1/inplace-pkg-config-munged
768 endif
769
770 endif
771