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