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