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