a0754af5c2e4a59a930eb1e0a893f48ea51abdfb
[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://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
10 #
11 # -----------------------------------------------------------------------------
12
13 # -----------------------------------------------------------------------------
14 # For expressing extra dependencies on source files
15
16 define compiler-hs-dependency # args: $1 = module, $2 = dependency
17
18 $$(foreach stage,1 2 3,\
19 $$(foreach way,$$(compiler_stage$$(stage)_WAYS),\
20 compiler/stage$$(stage)/build/$1.$$($$(way)_osuf))) : $2
21
22 endef
23
24 # -----------------------------------------------------------------------------
25 # Create compiler configuration
26 #
27 # The 'echo' commands simply spit the values of various make variables
28 # into Config.hs, whence they can be compiled and used by GHC itself
29
30 # This is just to avoid generating a warning when generating deps
31 # involving RtsFlags.h
32 compiler_stage1_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES
33 compiler_stage2_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES
34 compiler_stage3_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES
35
36 compiler_stage1_C_FILES_NODEPS = compiler/parser/cutils.c
37
38 ifneq "$(BINDIST)" "YES"
39 compiler/stage1/package-data.mk : compiler/stage1/build/Config.hs
40 compiler/stage2/package-data.mk : compiler/stage2/build/Config.hs
41 compiler/stage3/package-data.mk : compiler/stage3/build/Config.hs
42 endif
43
44 compiler/stage%/build/Config.hs : mk/config.mk mk/project.mk | $$(dir $$@)/.
45 $(call removeFiles,$@)
46 @echo 'Creating $@ ... '
47 @echo '{-# LANGUAGE CPP #-}' >> $@
48 @echo 'module Config where' >> $@
49 @echo >> $@
50 @echo '#include "ghc_boot_platform.h"' >> $@
51 @echo >> $@
52 @echo 'data IntegerLibrary = IntegerGMP | IntegerSimple' >> $@
53 @echo ' deriving Eq' >> $@
54 @echo >> $@
55 @echo 'cBuildPlatformString :: String' >> $@
56 @echo 'cBuildPlatformString = BuildPlatform_NAME' >> $@
57 @echo 'cHostPlatformString :: String' >> $@
58 @echo 'cHostPlatformString = HostPlatform_NAME' >> $@
59 @echo 'cTargetPlatformString :: String' >> $@
60 @echo 'cTargetPlatformString = TargetPlatform_NAME' >> $@
61 @echo >> $@
62 @echo 'cProjectName :: String' >> $@
63 @echo 'cProjectName = "$(ProjectName)"' >> $@
64 @echo 'cProjectVersion :: String' >> $@
65 @echo 'cProjectVersion = "$(ProjectVersion)"' >> $@
66 @echo 'cProjectVersionInt :: String' >> $@
67 @echo 'cProjectVersionInt = "$(ProjectVersionInt)"' >> $@
68 @echo 'cProjectPatchLevel :: String' >> $@
69 @echo 'cProjectPatchLevel = "$(ProjectPatchLevel)"' >> $@
70 @echo 'cBooterVersion :: String' >> $@
71 @echo 'cBooterVersion = "$(GhcVersion)"' >> $@
72 @echo 'cStage :: String' >> $@
73 @echo 'cStage = show (STAGE :: Int)' >> $@
74 @echo 'cIntegerLibrary :: String' >> $@
75 @echo 'cIntegerLibrary = "$(INTEGER_LIBRARY)"' >> $@
76 @echo 'cIntegerLibraryType :: IntegerLibrary' >> $@
77 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
78 @echo 'cIntegerLibraryType = IntegerGMP' >> $@
79 else ifeq "$(INTEGER_LIBRARY)" "integer-simple"
80 @echo 'cIntegerLibraryType = IntegerSimple' >> $@
81 else ifneq "$(CLEANING)" "YES"
82 $(error Unknown integer library)
83 endif
84 @echo 'cSupportsSplitObjs :: String' >> $@
85 @echo 'cSupportsSplitObjs = "$(SupportsSplitObjs)"' >> $@
86 @echo 'cGhcWithInterpreter :: String' >> $@
87 @echo 'cGhcWithInterpreter = "$(GhcWithInterpreter)"' >> $@
88 @echo 'cGhcWithNativeCodeGen :: String' >> $@
89 @echo 'cGhcWithNativeCodeGen = "$(GhcWithNativeCodeGen)"' >> $@
90 @echo 'cGhcWithSMP :: String' >> $@
91 @echo 'cGhcWithSMP = "$(GhcWithSMP)"' >> $@
92 @echo 'cGhcRTSWays :: String' >> $@
93 @echo 'cGhcRTSWays = "$(GhcRTSWays)"' >> $@
94 @echo 'cGhcEnableTablesNextToCode :: String' >> $@
95 @echo 'cGhcEnableTablesNextToCode = "$(GhcEnableTablesNextToCode)"' >> $@
96 @echo 'cLeadingUnderscore :: String' >> $@
97 @echo 'cLeadingUnderscore = "$(LeadingUnderscore)"' >> $@
98 @echo 'cRAWCPP_FLAGS :: String' >> $@
99 @echo 'cRAWCPP_FLAGS = "$(RAWCPP_FLAGS)"' >> $@
100 @echo 'cGHC_DRIVER_DIR :: String' >> $@
101 @echo 'cGHC_DRIVER_DIR = "$(GHC_DRIVER_DIR)"' >> $@
102 @echo 'cGHC_UNLIT_PGM :: String' >> $@
103 @echo 'cGHC_UNLIT_PGM = "$(GHC_UNLIT_PGM)"' >> $@
104 @echo 'cGHC_UNLIT_DIR :: String' >> $@
105 @echo 'cGHC_UNLIT_DIR = "$(GHC_UNLIT_DIR)"' >> $@
106 @echo 'cGHC_SPLIT_PGM :: String' >> $@
107 @echo 'cGHC_SPLIT_PGM = "$(GHC_SPLIT_PGM)"' >> $@
108 @echo 'cGHC_SPLIT_DIR :: String' >> $@
109 @echo 'cGHC_SPLIT_DIR = "$(GHC_SPLIT_DIR)"' >> $@
110 @echo 'cGHC_SYSMAN_PGM :: String' >> $@
111 @echo 'cGHC_SYSMAN_PGM = "$(GHC_SYSMAN)"' >> $@
112 @echo 'cGHC_SYSMAN_DIR :: String' >> $@
113 @echo 'cGHC_SYSMAN_DIR = "$(GHC_SYSMAN_DIR)"' >> $@
114 @echo 'cDEFAULT_TMPDIR :: String' >> $@
115 @echo 'cDEFAULT_TMPDIR = "$(DEFAULT_TMPDIR)"' >> $@
116 @echo 'cLibFFI :: Bool' >> $@
117 ifeq "$(UseLibFFIForAdjustors)" "YES"
118 @echo 'cLibFFI = True' >> $@
119 else
120 @echo 'cLibFFI = False' >> $@
121 endif
122 @echo done.
123
124 # -----------------------------------------------------------------------------
125 # Create platform includes
126
127 # Here we generate a little header file containing CPP symbols that GHC
128 # uses to determine which platform it is building on/for. The platforms
129 # can differ between stage1 and stage2 if we're cross-compiling, so we
130 # need one of these header files per stage.
131
132 PLATFORM_H = ghc_boot_platform.h
133
134 ifeq "$(BuildingCrossCompiler)" "YES"
135 compiler/stage1/$(PLATFORM_H) : compiler/stage2/$(PLATFORM_H)
136 cp $< $@
137 else
138 compiler/stage1/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
139 $(call removeFiles,$@)
140 @echo "Creating $@..."
141 @echo "#ifndef __PLATFORM_H__" >> $@
142 @echo "#define __PLATFORM_H__" >> $@
143 @echo >> $@
144 @echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
145 @echo "#define HostPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
146 @echo "#define TargetPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
147 @echo >> $@
148 @echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
149 @echo "#define $(BuildPlatform_CPP)_HOST 1" >> $@
150 @echo "#define $(HostPlatform_CPP)_TARGET 1" >> $@
151 @echo >> $@
152 @echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
153 @echo "#define $(BuildArch_CPP)_HOST_ARCH 1" >> $@
154 @echo "#define $(HostArch_CPP)_TARGET_ARCH 1" >> $@
155 @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
156 @echo "#define HOST_ARCH \"$(BuildArch_CPP)\"" >> $@
157 @echo "#define TARGET_ARCH \"$(HostArch_CPP)\"" >> $@
158 @echo >> $@
159 @echo "#define $(BuildOS_CPP)_BUILD_OS 1" >> $@
160 @echo "#define $(BuildOS_CPP)_HOST_OS 1" >> $@
161 @echo "#define $(HostOS_CPP)_TARGET_OS 1" >> $@
162 @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
163 @echo "#define HOST_OS \"$(BuildOS_CPP)\"" >> $@
164 @echo "#define TARGET_OS \"$(HostOS_CPP)\"" >> $@
165 ifeq "$(HostOS_CPP)" "irix"
166 @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS" >> $@
167 @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
168 @echo "#endif" >> $@
169 endif
170 @echo >> $@
171 @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
172 @echo "#define $(BuildVendor_CPP)_HOST_VENDOR 1" >> $@
173 @echo "#define $(HostVendor_CPP)_TARGET_VENDOR 1" >> $@
174 @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
175 @echo "#define HOST_VENDOR \"$(BuildVendor_CPP)\"" >> $@
176 @echo "#define TARGET_VENDOR \"$(HostVendor_CPP)\"" >> $@
177 @echo >> $@
178 @echo "#endif /* __PLATFORM_H__ */" >> $@
179 @echo "Done."
180 endif
181
182 # For stage2 and above, the BUILD platform is the HOST of stage1, and
183 # the HOST platform is the TARGET of stage1. The TARGET remains the same
184 # (stage1 is the cross-compiler, not stage2).
185 compiler/stage2/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
186 $(call removeFiles,$@)
187 @echo "Creating $@..."
188 @echo "#ifndef __PLATFORM_H__" >> $@
189 @echo "#define __PLATFORM_H__" >> $@
190 @echo >> $@
191 @echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
192 @echo "#define HostPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
193 @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
194 @echo >> $@
195 @echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
196 @echo "#define $(HostPlatform_CPP)_HOST 1" >> $@
197 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
198 @echo >> $@
199 @echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
200 @echo "#define $(HostArch_CPP)_HOST_ARCH 1" >> $@
201 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
202 @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
203 @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
204 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
205 @echo >> $@
206 @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
207 @echo "#define $(HostOS_CPP)_HOST_OS 1" >> $@
208 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
209 @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
210 @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
211 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
212 ifeq "$(TargetOS_CPP)" "irix"
213 @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS" >> $@
214 @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
215 @echo "#endif" >> $@
216 endif
217 @echo >> $@
218 @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
219 @echo "#define $(HostVendor_CPP)_HOST_VENDOR 1" >> $@
220 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
221 @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
222 @echo "#define HOST_VENDOR \"$(HostVendor_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.lhs
233 # from prelude/primops.txt
234
235 # XXX: these should go in stage1/stage2/stage3
236 PRIMOP_BITS = compiler/primop-data-decl.hs-incl \
237 compiler/primop-tag.hs-incl \
238 compiler/primop-list.hs-incl \
239 compiler/primop-has-side-effects.hs-incl \
240 compiler/primop-out-of-line.hs-incl \
241 compiler/primop-commutable.hs-incl \
242 compiler/primop-code-size.hs-incl \
243 compiler/primop-can-fail.hs-incl \
244 compiler/primop-strictness.hs-incl \
245 compiler/primop-primop-info.hs-incl
246
247 compiler_CPP_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
248 compiler_CPP_OPTS += ${GhcCppOpts}
249
250 $(PRIMOPS_TXT) compiler/parser/Parser.y: %: %.pp compiler/stage1/$(PLATFORM_H)
251 $(CPP) $(RAWCPP_FLAGS) -P $(compiler_CPP_OPTS) -x c $< | grep -v '^#pragma GCC' > $@
252
253 $(eval $(call clean-target,compiler,primop, $(PRIMOPS_TXT) compiler/parser/Parser.y $(PRIMOP_BITS)))
254
255 ifneq "$(BootingFromHc)" "YES"
256 compiler/primop-data-decl.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
257 "$(GENPRIMOP_INPLACE)" --data-decl < $< > $@
258 compiler/primop-tag.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
259 "$(GENPRIMOP_INPLACE)" --primop-tag < $< > $@
260 compiler/primop-list.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
261 "$(GENPRIMOP_INPLACE)" --primop-list < $< > $@
262 compiler/primop-has-side-effects.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
263 "$(GENPRIMOP_INPLACE)" --has-side-effects < $< > $@
264 compiler/primop-out-of-line.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
265 "$(GENPRIMOP_INPLACE)" --out-of-line < $< > $@
266 compiler/primop-commutable.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
267 "$(GENPRIMOP_INPLACE)" --commutable < $< > $@
268 compiler/primop-code-size.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
269 "$(GENPRIMOP_INPLACE)" --code-size < $< > $@
270 compiler/primop-can-fail.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
271 "$(GENPRIMOP_INPLACE)" --can-fail < $< > $@
272 compiler/primop-strictness.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
273 "$(GENPRIMOP_INPLACE)" --strictness < $< > $@
274 compiler/primop-primop-info.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
275 "$(GENPRIMOP_INPLACE)" --primop-primop-info < $< > $@
276
277 # Usages aren't used any more; but the generator
278 # can still generate them if we want them back
279 compiler/primop-usage.hs-incl: $(PRIMOPS_TXT)
280 "$(GENPRIMOP_INPLACE)" --usage < $< > $@
281 endif
282
283 # -----------------------------------------------------------------------------
284 # Configuration
285
286 compiler_stage1_CONFIGURE_OPTS += --flags=stage1
287 compiler_stage2_CONFIGURE_OPTS += --flags=stage2
288 compiler_stage3_CONFIGURE_OPTS += --flags=stage3
289
290 ifeq "$(GhcWithNativeCodeGen)" "YES"
291 compiler_stage1_CONFIGURE_OPTS += --flags=ncg
292 compiler_stage2_CONFIGURE_OPTS += --flags=ncg
293 endif
294
295 ifeq "$(GhcWithInterpreter)" "YES"
296 compiler_stage2_CONFIGURE_OPTS += --flags=ghci
297
298 ifeq "$(BuildSharedLibs)" "YES"
299 # There are too many symbols to make a Windows DLL for the ghc package,
300 # so we don't build it the dyn way; see trac #5987
301 ifneq "$(TargetOS_CPP)" "mingw32"
302 compiler_stage2_CONFIGURE_OPTS += --enable-shared
303 # If we are going to use dynamic libraries instead of .o files for ghci,
304 # we will need to always retain CAFs in the compiler.
305 # ghci/keepCAFsForGHCi contains a GNU C __attribute__((constructor))
306 # function which sets the keepCAFs flag for the RTS before any Haskell
307 # code is run.
308 compiler_stage2_CONFIGURE_OPTS += --flags=dynlibs
309 endif
310 endif
311
312 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
313 # Should GHCI be building info tables in the TABLES_NEXT_TO_CODE style
314 # or not?
315 # XXX This should logically be a CPP option, but there doesn't seem to
316 # be a flag for that
317 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DGHCI_TABLES_NEXT_TO_CODE
318 endif
319
320 # Should the debugger commands be enabled?
321 ifeq "$(GhciWithDebugger)" "YES"
322 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DDEBUGGER
323 endif
324
325 endif
326
327 ifeq "$(TargetOS_CPP)" "openbsd"
328 compiler_CONFIGURE_OPTS += --ld-options=-E
329 endif
330
331 ifeq "$(GhcUnregisterised)" "NO"
332 else
333 compiler_CONFIGURE_OPTS += --ghc-option=-DNO_REGS
334 endif
335
336 ifeq "$(GhcProfiled)" "YES"
337
338 # If we're profiling GHC then we want SCCs. However, adding -auto-all
339 # everywhere tends to give a hard-to-read profile, and adds lots of
340 # overhead. A better approach is to proceed top-down; identify the
341 # parts of the compiler of interest, and then add further cost centres
342 # as necessary. Turn on -auto-all for individual modules like this:
343
344 # compiler/main/DriverPipeline_HC_OPTS += -auto-all
345 compiler/main/GhcMake_HC_OPTS += -auto-all
346 compiler/main/GHC_HC_OPTS += -auto-all
347
348 # or alternatively add {-# OPTIONS_GHC -auto-all #-} to the top of
349 # modules you're interested in.
350
351 # We seem to still build the vanilla libraries even if we say
352 # --disable-library-vanilla, but installation then fails, as Cabal
353 # doesn't copy the vanilla .hi files, but ghc-pkg complains about
354 # their absence when we register the package. So for now, we just
355 # leave the vanilla libraries enabled.
356 # compiler_stage2_CONFIGURE_OPTS += --disable-library-vanilla
357 compiler_stage2_CONFIGURE_OPTS += --ghc-pkg-option=--force
358 endif
359
360 compiler_stage3_CONFIGURE_OPTS := $(compiler_stage2_CONFIGURE_OPTS)
361
362 compiler_stage1_CONFIGURE_OPTS += --ghc-option=-DSTAGE=1
363 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DSTAGE=2
364 compiler_stage3_CONFIGURE_OPTS += --ghc-option=-DSTAGE=3
365 compiler_stage2_HADDOCK_OPTS += --optghc=-DSTAGE=2
366
367 compiler/stage1/package-data.mk : compiler/ghc.mk
368 compiler/stage2/package-data.mk : compiler/ghc.mk
369 compiler/stage3/package-data.mk : compiler/ghc.mk
370
371 # -----------------------------------------------------------------------------
372 # And build the package
373
374 compiler_PACKAGE = ghc
375
376 # Note [fiddle-stage1-version]
377 # The version of the GHC package changes every day, since the
378 # patchlevel is the current date. We don't want to force
379 # recompilation of the entire compiler when this happens, so for stage
380 # 1 we omit the patchlevel from the version number. For stage 2 we
381 # have to include the patchlevel since this is the package we install,
382 # however.
383 #
384 # Note: we also have to tweak the version number of the package itself
385 # when it gets registered; see Note [munge-stage1-package-config]
386 # below.
387 # The ProjectPatchLevel > 20000000 iff it's a date. If it's e.g. 6.12.1
388 # then we don't want to remove it
389 ifneq "$(CLEANING)" "YES"
390 ifeq "$(shell [ $(ProjectPatchLevel) -gt 20000000 ] && echo YES)" "YES"
391 compiler_stage1_VERSION_MUNGED = YES
392 endif
393 endif
394
395 ifeq "$(compiler_stage1_VERSION_MUNGED)" "YES"
396 compiler_stage1_MUNGED_VERSION = $(subst .$(ProjectPatchLevel),,$(ProjectVersion))
397 define compiler_PACKAGE_MAGIC
398 compiler_stage1_VERSION = $(compiler_stage1_MUNGED_VERSION)
399 endef
400
401 # Don't register the non-munged package
402 compiler_stage1_REGISTER_PACKAGE = NO
403
404 endif
405
406 # haddocking only happens for stage2
407 compiler_stage1_DO_HADDOCK = NO
408 compiler_stage3_DO_HADDOCK = NO
409
410 # Don't do splitting for the GHC package, it takes too long and
411 # there's not much benefit.
412 compiler_stage1_SplitObjs = NO
413 compiler_stage2_SplitObjs = NO
414 compiler_stage3_SplitObjs = NO
415
416 ifeq "$(TargetOS_CPP)" "mingw32"
417 # There are too many symbols to make a Windows DLL for the ghc package,
418 # so we don't build it the dyn way; see trac #5987
419 compiler_stage1_EXCLUDED_WAYS := dyn
420 compiler_stage2_EXCLUDED_WAYS := dyn
421 compiler_stage3_EXCLUDED_WAYS := dyn
422 endif
423
424 # if stage is set to something other than "1" or "", disable stage 1
425 ifneq "$(filter-out 1,$(stage))" ""
426 compiler_stage1_NOT_NEEDED = YES
427 endif
428 # if stage is set to something other than "2" or "", disable stage 2
429 ifneq "$(filter-out 2,$(stage))" ""
430 compiler_stage2_NOT_NEEDED = YES
431 endif
432 # stage 3 has to be requested explicitly with stage=3
433 ifneq "$(stage)" "3"
434 compiler_stage3_NOT_NEEDED = YES
435 endif
436 $(eval $(call build-package,compiler,stage1,0))
437 $(eval $(call build-package,compiler,stage2,1))
438 $(eval $(call build-package,compiler,stage3,2))
439
440 # after build-package, because that adds --enable-library-for-ghci
441 # to compiler_stage*_CONFIGURE_OPTS:
442 # We don't build the GHCi library for the ghc package. We can load it
443 # the .a file instead, and as object splitting isn't on for the ghc
444 # package this isn't much slower.However, not building the package saves
445 # a significant chunk of disk space.
446 compiler_stage1_CONFIGURE_OPTS += --disable-library-for-ghci
447 compiler_stage2_CONFIGURE_OPTS += --disable-library-for-ghci
448 compiler_stage3_CONFIGURE_OPTS += --disable-library-for-ghci
449
450 # after build-package, because that sets compiler_stage1_HC_OPTS:
451 compiler_stage1_HC_OPTS += $(GhcStage1HcOpts)
452 compiler_stage2_HC_OPTS += $(GhcStage2HcOpts)
453 compiler_stage3_HC_OPTS += $(GhcStage3HcOpts)
454
455 ifneq "$(BINDIST)" "YES"
456
457 compiler_stage2_TAGS_HC_OPTS = -package ghc
458 $(eval $(call tags-package,compiler,stage2))
459
460 $(compiler_stage1_depfile_haskell) : compiler/stage1/$(PLATFORM_H)
461 $(compiler_stage2_depfile_haskell) : compiler/stage2/$(PLATFORM_H)
462 $(compiler_stage3_depfile_haskell) : compiler/stage3/$(PLATFORM_H)
463
464 COMPILER_INCLUDES_DEPS += $(includes_H_CONFIG)
465 COMPILER_INCLUDES_DEPS += $(includes_H_PLATFORM)
466 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS)
467 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_TYPE)
468 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
469 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_EXPORTS)
470 COMPILER_INCLUDES_DEPS += $(includes_DERIVEDCONSTANTS)
471 COMPILER_INCLUDES_DEPS += $(PRIMOP_BITS)
472
473 $(compiler_stage1_depfile_haskell) : $(COMPILER_INCLUDES_DEPS)
474 $(compiler_stage2_depfile_haskell) : $(COMPILER_INCLUDES_DEPS)
475 $(compiler_stage3_depfile_haskell) : $(COMPILER_INCLUDES_DEPS)
476
477 # Every PrimOp.o object file depends on $(PRIMOP_BITS):
478 $(eval $(call compiler-hs-dependency,PrimOp,$(PRIMOP_BITS)))
479
480 # GHC itself doesn't know about the above dependencies, so we have to
481 # switch off the recompilation checker for that module:
482 compiler/prelude/PrimOp_HC_OPTS += -fforce-recomp
483
484 # LibFFI.hs #includes ffi.h
485 compiler/stage2/build/LibFFI.hs : $(libffi_HEADERS)
486 # On Windows it seems we also need to link directly to libffi
487 ifeq "$(HostOS_CPP)" "mingw32"
488 define windowsDynLinkToFfi
489 # $1 = way
490 ifneq "$$(findstring dyn, $1)" ""
491 compiler_stage2_$1_ALL_HC_OPTS += -l$$(LIBFFI_WINDOWS_LIB)
492 endif
493 endef
494 $(foreach way,$(GhcLibWays),$(eval $(call windowsDynLinkToFfi,$(way))))
495 endif
496
497 # Note [munge-stage1-package-config]
498 # Strip the date/patchlevel from the version of stage1. See Note
499 # [fiddle-stage1-version] above.
500 ifeq "$(compiler_stage1_VERSION_MUNGED)" "YES"
501 compiler/stage1/inplace-pkg-config-munged: compiler/stage1/inplace-pkg-config
502 sed -e 's/^\(version: .*\)\.$(ProjectPatchLevel)$$/\1/' \
503 -e 's/^\(id: .*\)\.$(ProjectPatchLevel)$$/\1/' \
504 -e 's/^\(hs-libraries: HSghc-.*\)\.$(ProjectPatchLevel)$$/\1/' \
505 < $< > $@
506 "$(compiler_stage1_GHC_PKG)" update --force $(compiler_stage1_GHC_PKG_OPTS) $@
507
508 # We need to make sure the munged config is in the database before we
509 # try to configure ghc-bin
510 ghc/stage1/package-data.mk : compiler/stage1/inplace-pkg-config-munged
511 endif
512
513 endif
514