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