Improve isReflexiveCo performance
[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 'import GhcPrelude' >> $@
55 @echo >> $@
56 @echo '#include "ghc_boot_platform.h"' >> $@
57 @echo >> $@
58 @echo 'data IntegerLibrary = IntegerGMP' >> $@
59 @echo ' | IntegerSimple' >> $@
60 @echo ' deriving Eq' >> $@
61 @echo >> $@
62 @echo 'cBuildPlatformString :: String' >> $@
63 @echo 'cBuildPlatformString = BuildPlatform_NAME' >> $@
64 @echo 'cHostPlatformString :: String' >> $@
65 @echo 'cHostPlatformString = HostPlatform_NAME' >> $@
66 @echo 'cTargetPlatformString :: String' >> $@
67 @echo 'cTargetPlatformString = TargetPlatform_NAME' >> $@
68 @echo >> $@
69 @echo 'cProjectName :: String' >> $@
70 @echo 'cProjectName = "$(ProjectName)"' >> $@
71 @echo 'cProjectGitCommitId :: String' >> $@
72 @echo 'cProjectGitCommitId = "$(ProjectGitCommitId)"' >> $@
73 @echo 'cProjectVersion :: String' >> $@
74 @echo 'cProjectVersion = "$(ProjectVersion)"' >> $@
75 @echo 'cProjectVersionInt :: String' >> $@
76 @echo 'cProjectVersionInt = "$(ProjectVersionInt)"' >> $@
77 @echo 'cProjectPatchLevel :: String' >> $@
78 @echo 'cProjectPatchLevel = "$(ProjectPatchLevel)"' >> $@
79 @echo 'cProjectPatchLevel1 :: String' >> $@
80 @echo 'cProjectPatchLevel1 = "$(ProjectPatchLevel1)"' >> $@
81 @echo 'cProjectPatchLevel2 :: String' >> $@
82 @echo 'cProjectPatchLevel2 = "$(ProjectPatchLevel2)"' >> $@
83 @echo 'cBooterVersion :: String' >> $@
84 @echo 'cBooterVersion = "$(GhcVersion)"' >> $@
85 @echo 'cStage :: String' >> $@
86 @echo 'cStage = show (STAGE :: Int)' >> $@
87 @echo 'cIntegerLibrary :: String' >> $@
88 @echo 'cIntegerLibrary = "$(INTEGER_LIBRARY)"' >> $@
89 @echo 'cIntegerLibraryType :: IntegerLibrary' >> $@
90 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
91 @echo 'cIntegerLibraryType = IntegerGMP' >> $@
92 else ifeq "$(INTEGER_LIBRARY)" "integer-simple"
93 @echo 'cIntegerLibraryType = IntegerSimple' >> $@
94 else ifneq "$(CLEANING)" "YES"
95 $(error Unknown integer library)
96 endif
97 @echo 'cSupportsSplitObjs :: String' >> $@
98 @echo 'cSupportsSplitObjs = "$(SupportsSplitObjs)"' >> $@
99 @echo 'cGhcWithInterpreter :: String' >> $@
100 @echo 'cGhcWithInterpreter = "$(GhcWithInterpreter)"' >> $@
101 @echo 'cGhcWithNativeCodeGen :: String' >> $@
102 @echo 'cGhcWithNativeCodeGen = "$(GhcWithNativeCodeGen)"' >> $@
103 @echo 'cGhcWithSMP :: String' >> $@
104 @echo 'cGhcWithSMP = "$(GhcWithSMP)"' >> $@
105 @echo 'cGhcRTSWays :: String' >> $@
106 @echo 'cGhcRTSWays = "$(GhcRTSWays)"' >> $@
107 @echo 'cGhcRtsWithLibdw :: Bool' >> $@
108 ifeq "$(GhcRtsWithLibdw)" "YES"
109 @echo 'cGhcRtsWithLibdw = True' >> $@
110 else
111 @echo 'cGhcRtsWithLibdw = False' >> $@
112 endif
113 @echo 'cGhcEnableTablesNextToCode :: String' >> $@
114 @echo 'cGhcEnableTablesNextToCode = "$(GhcEnableTablesNextToCode)"' >> $@
115 @echo 'cLeadingUnderscore :: String' >> $@
116 @echo 'cLeadingUnderscore = "$(LeadingUnderscore)"' >> $@
117 @echo 'cGHC_UNLIT_PGM :: String' >> $@
118 @echo 'cGHC_UNLIT_PGM = "$(utils/unlit_dist_PROG)"' >> $@
119 @echo 'cGHC_SPLIT_PGM :: String' >> $@
120 @echo 'cGHC_SPLIT_PGM = "$(driver/split_dist_PROG)"' >> $@
121 @echo 'cLibFFI :: Bool' >> $@
122 ifeq "$(UseLibFFIForAdjustors)" "YES"
123 @echo 'cLibFFI = True' >> $@
124 else
125 @echo 'cLibFFI = False' >> $@
126 endif
127 # Note that GhcThreaded just reflects the Makefile variable setting.
128 # In particular, the stage1 compiler is never actually compiled with
129 # -threaded, but it will nevertheless have cGhcThreaded = True.
130 # The "+RTS --info" output will show what RTS GHC is really using.
131 @echo 'cGhcThreaded :: Bool' >> $@
132 ifeq "$(GhcThreaded)" "YES"
133 @echo 'cGhcThreaded = True' >> $@
134 else
135 @echo 'cGhcThreaded = False' >> $@
136 endif
137 @echo 'cGhcDebugged :: Bool' >> $@
138 ifeq "$(GhcDebugged)" "YES"
139 @echo 'cGhcDebugged = True' >> $@
140 else
141 @echo 'cGhcDebugged = False' >> $@
142 endif
143 @echo done.
144
145 # -----------------------------------------------------------------------------
146 # Create platform includes
147
148 # Here we generate a little header file containing CPP symbols that GHC
149 # uses to determine which platform it is building on/for. The platforms
150 # can differ between stage1 and stage2 if we're cross-compiling, so we
151 # need one of these header files per stage.
152
153 PLATFORM_H = ghc_boot_platform.h
154
155 compiler/stage1/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
156 $(call removeFiles,$@)
157 @echo "Creating $@..."
158 @echo "#ifndef __PLATFORM_H__" >> $@
159 @echo "#define __PLATFORM_H__" >> $@
160 @echo >> $@
161 @echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
162 @echo "#define HostPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
163 @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
164 @echo >> $@
165 @echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
166 @echo "#define $(HostPlatform_CPP)_HOST 1" >> $@
167 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
168 @echo >> $@
169 @echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
170 @echo "#define $(HostArch_CPP)_HOST_ARCH 1" >> $@
171 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
172 @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
173 @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
174 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
175 @echo "#define LLVM_TARGET \"$(LLVMTarget_CPP)\"" >> $@
176 @echo >> $@
177 @echo "#define $(BuildOS_CPP)_BUILD_OS 1" >> $@
178 @echo "#define $(HostOS_CPP)_HOST_OS 1" >> $@
179 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
180 @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
181 @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
182 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
183 @echo >> $@
184 @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
185 @echo "#define $(HostVendor_CPP)_HOST_VENDOR 1" >> $@
186 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
187 @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
188 @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
189 @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
190 @echo >> $@
191 @echo "#endif /* __PLATFORM_H__ */" >> $@
192 @echo "Done."
193
194 # For stage2 and above, the BUILD platform is the HOST of stage1, and
195 # the HOST platform is the TARGET of stage1. The TARGET remains the same
196 # (stage1 is the cross-compiler, not stage2).
197 compiler/stage2/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
198 $(call removeFiles,$@)
199 @echo "Creating $@..."
200 @echo "#ifndef __PLATFORM_H__" >> $@
201 @echo "#define __PLATFORM_H__" >> $@
202 @echo >> $@
203 @echo "#define BuildPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
204 @echo "#define HostPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
205 @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
206 @echo >> $@
207 @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
208 @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
209 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
210 @echo >> $@
211 @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
212 @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
213 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
214 @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
215 @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
216 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
217 @echo "#define LLVM_TARGET \"$(LLVMTarget_CPP)\"" >> $@
218 @echo >> $@
219 @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
220 @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
221 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
222 @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
223 @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
224 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
225 @echo >> $@
226 @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
227 @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
228 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
229 @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
230 @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
231 @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
232 @echo >> $@
233 @echo "#endif /* __PLATFORM_H__ */" >> $@
234 @echo "Done."
235
236 compiler/stage3/$(PLATFORM_H) : compiler/stage2/$(PLATFORM_H)
237 "$(CP)" $< $@
238
239 # ----------------------------------------------------------------------------
240 # Generate supporting stuff for prelude/PrimOp.hs
241 # from prelude/primops.txt
242
243 PRIMOP_BITS_NAMES = primop-data-decl.hs-incl \
244 primop-tag.hs-incl \
245 primop-list.hs-incl \
246 primop-has-side-effects.hs-incl \
247 primop-out-of-line.hs-incl \
248 primop-commutable.hs-incl \
249 primop-code-size.hs-incl \
250 primop-can-fail.hs-incl \
251 primop-strictness.hs-incl \
252 primop-fixity.hs-incl \
253 primop-primop-info.hs-incl \
254 primop-vector-uniques.hs-incl \
255 primop-vector-tys.hs-incl \
256 primop-vector-tys-exports.hs-incl \
257 primop-vector-tycons.hs-incl
258
259 PRIMOP_BITS_STAGE1 = $(addprefix compiler/stage1/build/,$(PRIMOP_BITS_NAMES))
260 PRIMOP_BITS_STAGE2 = $(addprefix compiler/stage2/build/,$(PRIMOP_BITS_NAMES))
261 PRIMOP_BITS_STAGE3 = $(addprefix compiler/stage3/build/,$(PRIMOP_BITS_NAMES))
262
263 compiler_CPP_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
264 compiler_CPP_OPTS += ${GhcCppOpts}
265
266 # We add these paths to the Haskell compiler's #include search path list since
267 # we must avoid #including files by paths relative to the source file as Hadrian
268 # moves the build artifacts out of the source tree. See #8040.
269 compiler_HC_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
270
271 define preprocessCompilerFiles
272 # $0 = stage
273 compiler/stage$1/build/primops.txt: compiler/prelude/primops.txt.pp compiler/stage$1/$$(PLATFORM_H)
274 $$(HS_CPP) -P $$(compiler_CPP_OPTS) -Icompiler/stage$1 -x c $$< | grep -v '^#pragma GCC' > $$@
275
276 compiler/stage$1/build/primop-data-decl.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
277 "$$(genprimopcode_INPLACE)" --data-decl < $$< > $$@
278 compiler/stage$1/build/primop-tag.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
279 "$$(genprimopcode_INPLACE)" --primop-tag < $$< > $$@
280 compiler/stage$1/build/primop-list.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
281 "$$(genprimopcode_INPLACE)" --primop-list < $$< > $$@
282 compiler/stage$1/build/primop-has-side-effects.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
283 "$$(genprimopcode_INPLACE)" --has-side-effects < $$< > $$@
284 compiler/stage$1/build/primop-out-of-line.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
285 "$$(genprimopcode_INPLACE)" --out-of-line < $$< > $$@
286 compiler/stage$1/build/primop-commutable.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
287 "$$(genprimopcode_INPLACE)" --commutable < $$< > $$@
288 compiler/stage$1/build/primop-code-size.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
289 "$$(genprimopcode_INPLACE)" --code-size < $$< > $$@
290 compiler/stage$1/build/primop-can-fail.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
291 "$$(genprimopcode_INPLACE)" --can-fail < $$< > $$@
292 compiler/stage$1/build/primop-strictness.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
293 "$$(genprimopcode_INPLACE)" --strictness < $$< > $$@
294 compiler/stage$1/build/primop-fixity.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
295 "$$(genprimopcode_INPLACE)" --fixity < $$< > $$@
296 compiler/stage$1/build/primop-primop-info.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
297 "$$(genprimopcode_INPLACE)" --primop-primop-info < $$< > $$@
298 compiler/stage$1/build/primop-vector-uniques.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
299 "$$(genprimopcode_INPLACE)" --primop-vector-uniques < $$< > $$@
300 compiler/stage$1/build/primop-vector-tys.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
301 "$$(genprimopcode_INPLACE)" --primop-vector-tys < $$< > $$@
302 compiler/stage$1/build/primop-vector-tys-exports.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
303 "$$(genprimopcode_INPLACE)" --primop-vector-tys-exports < $$< > $$@
304 compiler/stage$1/build/primop-vector-tycons.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
305 "$$(genprimopcode_INPLACE)" --primop-vector-tycons < $$< > $$@
306
307 # Usages aren't used any more; but the generator
308 # can still generate them if we want them back
309 compiler/stage$1/build/primop-usage.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
310 "$$(genprimopcode_INPLACE)" --usage < $$< > $$@
311
312 endef
313
314 $(eval $(call preprocessCompilerFiles,1))
315 $(eval $(call preprocessCompilerFiles,2))
316 $(eval $(call preprocessCompilerFiles,3))
317
318 # -----------------------------------------------------------------------------
319 # Configuration
320
321 compiler_stage1_CONFIGURE_OPTS += --flags=stage1
322 compiler_stage2_CONFIGURE_OPTS += --flags=stage2
323 compiler_stage3_CONFIGURE_OPTS += --flags=stage3
324
325 ifeq "$(GhcThreaded)" "YES"
326 # We pass THREADED_RTS to the stage2 C files so that cbits/genSym.c will bring
327 # the threaded version of atomic_inc() into scope.
328 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-optc-DTHREADED_RTS
329 endif
330
331 ifeq "$(GhcWithNativeCodeGen)" "YES"
332 compiler_stage1_CONFIGURE_OPTS += --flags=ncg
333 compiler_stage2_CONFIGURE_OPTS += --flags=ncg
334 endif
335
336 ifeq "$(GhcWithInterpreter)" "YES"
337 compiler_stage2_CONFIGURE_OPTS += --flags=ghci
338
339 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
340 # Should GHCI be building info tables in the TABLES_NEXT_TO_CODE style
341 # or not?
342 # XXX This should logically be a CPP option, but there doesn't seem to
343 # be a flag for that
344 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DGHCI_TABLES_NEXT_TO_CODE
345 endif
346
347 # Should the debugger commands be enabled?
348 ifeq "$(GhciWithDebugger)" "YES"
349 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DDEBUGGER
350 endif
351
352 endif
353
354 ifeq "$(TargetOS_CPP)" "openbsd"
355 compiler_CONFIGURE_OPTS += --ld-options=-E
356 endif
357
358 ifeq "$(GhcUnregisterised)" "NO"
359 else
360 compiler_CONFIGURE_OPTS += --ghc-option=-DNO_REGS
361 endif
362
363 ifneq "$(GhcWithSMP)" "YES"
364 compiler_CONFIGURE_OPTS += --ghc-option=-DNOSMP
365 compiler_CONFIGURE_OPTS += --ghc-option=-optc-DNOSMP
366 endif
367
368 ifeq "$(WITH_TERMINFO)" "NO"
369 compiler_stage2_CONFIGURE_OPTS += --flags=-terminfo
370 endif
371
372 # Careful optimisation of the parser: we don't want to throw everything
373 # at it, because that takes too long and doesn't buy much, but we do want
374 # to inline certain key external functions, so we instruct GHC not to
375 # throw away inlinings as it would normally do in -O0 mode.
376 # Since GHC version 7.8, we need -fcmm-sink to be
377 # passed to the compiler. This is required on x86 to avoid the
378 # register allocator running out of stack slots when compiling this
379 # module with -fPIC -dynamic.
380 # See #8182 for all the details
381 compiler/stage1/build/Parser_HC_OPTS += -O0 -fno-ignore-interface-pragmas -fcmm-sink
382 compiler/stage2/build/Parser_HC_OPTS += -O0 -fno-ignore-interface-pragmas -fcmm-sink
383 compiler/stage3/build/Parser_HC_OPTS += -O0 -fno-ignore-interface-pragmas -fcmm-sink
384
385 ifeq "$(GhcProfiled)" "YES"
386 # If we're profiling GHC then we want SCCs. However, adding -auto-all
387 # everywhere tends to give a hard-to-read profile, and adds lots of
388 # overhead. A better approach is to proceed top-down; identify the
389 # parts of the compiler of interest, and then add further cost centres
390 # as necessary. Turn on -fprof-auto for individual modules like this:
391
392 # compiler/main/DriverPipeline_HC_OPTS += -fprof-auto
393 compiler/main/GhcMake_HC_OPTS += -fprof-auto
394 compiler/main/GHC_HC_OPTS += -fprof-auto
395
396 # or alternatively add {-# OPTIONS_GHC -fprof-auto #-} to the top of
397 # modules you're interested in.
398
399 # We seem to still build the vanilla libraries even if we say
400 # --disable-library-vanilla, but installation then fails, as Cabal
401 # doesn't copy the vanilla .hi files, but ghc-pkg complains about
402 # their absence when we register the package. So for now, we just
403 # leave the vanilla libraries enabled.
404 # compiler_stage2_CONFIGURE_OPTS += --disable-library-vanilla
405 compiler_stage2_CONFIGURE_OPTS += --ghc-pkg-option=--force
406 endif
407
408 compiler_stage3_CONFIGURE_OPTS := $(compiler_stage2_CONFIGURE_OPTS)
409
410 compiler_stage1_CONFIGURE_OPTS += --ghc-option=-DSTAGE=1
411 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DSTAGE=2
412 compiler_stage3_CONFIGURE_OPTS += --ghc-option=-DSTAGE=3
413 compiler_stage2_HADDOCK_OPTS += --optghc=-DSTAGE=2
414
415 compiler/stage1/package-data.mk : compiler/ghc.mk
416 compiler/stage2/package-data.mk : compiler/ghc.mk
417 compiler/stage3/package-data.mk : compiler/ghc.mk
418
419 # -----------------------------------------------------------------------------
420 # And build the package
421
422 compiler_PACKAGE = ghc
423
424 # Don't do splitting for the GHC package, it takes too long and
425 # there's not much benefit.
426 compiler_stage1_SplitObjs = NO
427 compiler_stage2_SplitObjs = NO
428 compiler_stage3_SplitObjs = NO
429 compiler_stage1_SplitSections = NO
430 compiler_stage2_SplitSections = NO
431 compiler_stage3_SplitSections = NO
432
433 # if stage is set to something other than "1" or "", disable stage 1
434 # See Note [Stage1Only vs stage=1] in mk/config.mk.in.
435 ifneq "$(filter-out 1,$(stage))" ""
436 compiler_stage1_NOT_NEEDED = YES
437 endif
438 # if stage is set to something other than "2" or "", disable stage 2
439 ifneq "$(filter-out 2,$(stage))" ""
440 compiler_stage2_NOT_NEEDED = YES
441 endif
442 # stage 3 has to be requested explicitly with stage=3
443 ifneq "$(stage)" "3"
444 compiler_stage3_NOT_NEEDED = YES
445 endif
446 $(eval $(call build-package,compiler,stage1,0))
447 $(eval $(call build-package,compiler,stage2,1))
448 $(eval $(call build-package,compiler,stage3,2))
449
450 # We only want to turn keepCAFs on if we will be loading dynamic
451 # Haskell libraries with GHCi. We therefore filter the object file
452 # out for non-dynamic ways.
453 define keepCAFsForGHCiDynOnly
454 # $1 = stage
455 # $2 = way
456 ifeq "$$(findstring dyn, $2)" ""
457 compiler_stage$1_$2_C_OBJS := $$(filter-out %/keepCAFsForGHCi.$$($2_osuf),$$(compiler_stage$1_$2_C_OBJS))
458 endif
459 endef
460 $(foreach w,$(compiler_stage1_WAYS),$(eval $(call keepCAFsForGHCiDynOnly,1,$w)))
461 $(foreach w,$(compiler_stage2_WAYS),$(eval $(call keepCAFsForGHCiDynOnly,2,$w)))
462 $(foreach w,$(compiler_stage3_WAYS),$(eval $(call keepCAFsForGHCiDynOnly,3,$w)))
463
464 # after build-package, because that adds --enable-library-for-ghci
465 # to compiler_stage*_CONFIGURE_OPTS:
466 # We don't build the GHCi library for the ghc package. We can load it
467 # the .a file instead, and as object splitting isn't on for the ghc
468 # package this isn't much slower.However, not building the package saves
469 # a significant chunk of disk space.
470 compiler_stage1_CONFIGURE_OPTS += --disable-library-for-ghci
471 compiler_stage2_CONFIGURE_OPTS += --disable-library-for-ghci
472 compiler_stage3_CONFIGURE_OPTS += --disable-library-for-ghci
473
474 # after build-package, because that sets compiler_stage1_HC_OPTS:
475 ifeq "$(V)" "0"
476 compiler_stage1_HC_OPTS += $(filter-out -Rghc-timing,$(GhcHcOpts)) $(GhcStage1HcOpts)
477 compiler_stage2_HC_OPTS += $(filter-out -Rghc-timing,$(GhcHcOpts)) $(GhcStage2HcOpts)
478 compiler_stage3_HC_OPTS += $(filter-out -Rghc-timing,$(GhcHcOpts)) $(GhcStage3HcOpts)
479 else
480 compiler_stage1_HC_OPTS += $(GhcHcOpts) $(GhcStage1HcOpts)
481 compiler_stage2_HC_OPTS += $(GhcHcOpts) $(GhcStage2HcOpts)
482 compiler_stage3_HC_OPTS += $(GhcHcOpts) $(GhcStage3HcOpts)
483 endif
484
485 ifneq "$(BINDIST)" "YES"
486
487 compiler_stage2_TAGS_HC_OPTS = -package ghc
488 $(eval $(call tags-package,compiler,stage2))
489
490 $(compiler_stage1_depfile_haskell) : compiler/stage1/$(PLATFORM_H)
491 $(compiler_stage2_depfile_haskell) : compiler/stage2/$(PLATFORM_H)
492 $(compiler_stage3_depfile_haskell) : compiler/stage3/$(PLATFORM_H)
493
494 COMPILER_INCLUDES_DEPS += $(includes_H_CONFIG)
495 COMPILER_INCLUDES_DEPS += $(includes_H_PLATFORM)
496 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS)
497 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_TYPE)
498 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
499 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_EXPORTS)
500 COMPILER_INCLUDES_DEPS += $(includes_DERIVEDCONSTANTS)
501
502 $(compiler_stage1_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE1)
503 $(compiler_stage2_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE2)
504 $(compiler_stage3_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE3)
505
506 $(foreach way,$(compiler_stage1_WAYS),\
507 compiler/stage1/build/PrimOp.$($(way)_osuf)) : $(PRIMOP_BITS_STAGE1)
508 $(foreach way,$(compiler_stage2_WAYS),\
509 compiler/stage2/build/PrimOp.$($(way)_osuf)) : $(PRIMOP_BITS_STAGE2)
510 $(foreach way,$(compiler_stage3_WAYS),\
511 compiler/stage3/build/PrimOp.$($(way)_osuf)) : $(PRIMOP_BITS_STAGE3)
512
513
514 # GHC itself doesn't know about the above dependencies, so we have to
515 # switch off the recompilation checker for that module:
516 compiler/prelude/PrimOp_HC_OPTS += -fforce-recomp
517
518 ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
519 compiler/utils/Util_HC_OPTS += -DDYNAMIC_GHC_PROGRAMS
520 endif
521
522 endif