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