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