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