463ac3e80caf88ddbf2f6948ac777090567272de
[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 "cGhcWithSMP           :: String" >> $@
71         @echo "cGhcWithSMP           = \"$(GhcWithSMP)\"" >> $@
72         @echo "cGhcRTSWays           :: String" >> $@
73         @echo "cGhcRTSWays           = \"$(GhcRTSWays)\"" >> $@
74         @echo "cGhcUnregisterised    :: String" >> $@
75         @echo "cGhcUnregisterised    = \"$(GhcUnregisterised)\"" >> $@
76         @echo "cGhcEnableTablesNextToCode :: String" >> $@
77         @echo "cGhcEnableTablesNextToCode = \"$(GhcEnableTablesNextToCode)\"" >> $@
78         @echo "cLeadingUnderscore    :: String" >> $@
79         @echo "cLeadingUnderscore    = \"$(LeadingUnderscore)\"" >> $@
80         @echo "cRAWCPP_FLAGS         :: String" >> $@
81         @echo "cRAWCPP_FLAGS         = \"$(RAWCPP_FLAGS)\"" >> $@
82         @echo "cGCC                  :: String" >> $@
83         @echo "cGCC                  = \"$(WhatGccIsCalled)\"" >> $@
84         @echo "cMKDLL                :: String" >> $@
85         @echo "cMKDLL                = \"$(BLD_DLL)\"" >> $@
86         @echo "cLdIsGNULd            :: String" >> $@
87         @echo "cLdIsGNULd            = \"$(LdIsGNULd)\"" >> $@
88         @echo "cLD_X                 :: String" >> $@
89         @echo "cLD_X                 = \"$(LD_X)\"" >> $@
90         @echo "cGHC_DRIVER_DIR       :: String" >> $@
91         @echo "cGHC_DRIVER_DIR       = \"$(GHC_DRIVER_DIR)\"" >> $@
92         @echo "cGHC_TOUCHY_PGM       :: String" >> $@
93         @echo "cGHC_TOUCHY_PGM       = \"$(GHC_TOUCHY_PGM)\"" >> $@
94         @echo "cGHC_TOUCHY_DIR       :: String" >> $@
95         @echo "cGHC_TOUCHY_DIR       = \"$(GHC_TOUCHY_DIR)\"" >> $@
96         @echo "cGHC_UNLIT_PGM        :: String" >> $@
97         @echo "cGHC_UNLIT_PGM        = \"$(GHC_UNLIT_PGM)\"" >> $@
98         @echo "cGHC_UNLIT_DIR        :: String" >> $@
99         @echo "cGHC_UNLIT_DIR        = \"$(GHC_UNLIT_DIR)\"" >> $@
100         @echo "cGHC_MANGLER_PGM      :: String" >> $@
101         @echo "cGHC_MANGLER_PGM      = \"$(GHC_MANGLER_PGM)\"" >> $@
102         @echo "cGHC_MANGLER_DIR      :: String" >> $@
103         @echo "cGHC_MANGLER_DIR      = \"$(GHC_MANGLER_DIR)\"" >> $@
104         @echo "cGHC_SPLIT_PGM        :: String" >> $@
105         @echo "cGHC_SPLIT_PGM        = \"$(GHC_SPLIT_PGM)\"" >> $@
106         @echo "cGHC_SPLIT_DIR        :: String" >> $@
107         @echo "cGHC_SPLIT_DIR        = \"$(GHC_SPLIT_DIR)\"" >> $@
108         @echo "cGHC_SYSMAN_PGM       :: String" >> $@
109         @echo "cGHC_SYSMAN_PGM       = \"$(GHC_SYSMAN)\"" >> $@
110         @echo "cGHC_SYSMAN_DIR       :: String" >> $@
111         @echo "cGHC_SYSMAN_DIR       = \"$(GHC_SYSMAN_DIR)\"" >> $@
112         @echo "cGHC_PERL             :: String" >> $@
113         @echo "cGHC_PERL             = \"$(GHC_PERL)\"" >> $@
114         @echo "cCONTEXT_DIFF         :: String" >> $@
115         @echo "cCONTEXT_DIFF         = \"$(CONTEXT_DIFF)\"" >> $@
116         @echo "cUSER_WAY_NAMES       :: String" >> $@
117         @echo "cUSER_WAY_NAMES       = \"$(USER_WAY_NAMES)\"" >> $@
118         @echo "cUSER_WAY_OPTS        :: String" >> $@
119         @echo "cUSER_WAY_OPTS        = \"$(USER_WAY_OPTS)\"" >> $@
120         @echo "cDEFAULT_TMPDIR       :: String" >> $@
121         @echo "cDEFAULT_TMPDIR       = \"$(DEFAULT_TMPDIR)\"" >> $@
122         @echo "cRelocatableBuild     :: Bool"                 >> $@
123 ifeq "$(RelocatableBuild)" "YES"
124         @echo "cRelocatableBuild     = True"                  >> $@
125 else
126         @echo "cRelocatableBuild     = False"                 >> $@
127 endif
128         @echo "cLibFFI               :: Bool"                 >> $@
129 ifeq "$(UseLibFFIForAdjustors)" "YES"
130         @echo "cLibFFI               = True"                  >> $@
131 else
132         @echo "cLibFFI               = False"                 >> $@
133 endif
134         @echo done.
135
136 $(eval $(call clean-target,compiler,config_hs,$(compiler_CONFIG_HS)))
137
138 # -----------------------------------------------------------------------------
139 # Create platform includes
140
141 # Here we generate a little header file containing CPP symbols that GHC
142 # uses to determine which platform it is building on/for.  The platforms
143 # can differ between stage1 and stage2 if we're cross-compiling, so we
144 # need one of these header files per stage.
145
146 PLATFORM_H = ghc_boot_platform.h
147
148 compiler/stage1/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
149         "$(RM)" $(RM_OPTS) $@
150         @echo "Creating $@..."
151         @echo "#ifndef __PLATFORM_H__"  >$@
152         @echo "#define __PLATFORM_H__" >>$@
153         @echo >> $@
154         @echo "#define BuildPlatform_NAME  \"$(BUILDPLATFORM)\"" >> $@
155         @echo "#define HostPlatform_NAME   \"$(HOSTPLATFORM)\"" >> $@
156         @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
157         @echo >> $@
158         @echo "#define $(BuildPlatform_CPP)_BUILD       1" >> $@
159         @echo "#define $(HostPlatform_CPP)_HOST         1" >> $@
160         @echo "#define $(TargetPlatform_CPP)_TARGET     1" >> $@
161         @echo >> $@
162         @echo "#define $(BuildArch_CPP)_BUILD_ARCH      1" >> $@
163         @echo "#define $(HostArch_CPP)_HOST_ARCH        1" >> $@
164         @echo "#define $(TargetArch_CPP)_TARGET_ARCH    1" >> $@
165         @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
166         @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
167         @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
168         @echo >> $@
169         @echo "#define $(BuildOS_CPP)_BUILD_OS          1" >> $@
170         @echo "#define $(HostOS_CPP)_HOST_OS            1" >> $@
171         @echo "#define $(TargetOS_CPP)_TARGET_OS        1" >> $@  
172         @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
173         @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
174         @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
175 ifeq "$(HostOS_CPP)" "irix"
176         @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS           " >> $@  
177         @echo "#define $(IRIX_MAJOR)_TARGET_OS          1" >> $@  
178         @echo "#endif                                    " >> $@  
179 endif
180         @echo >> $@
181         @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR  1" >> $@
182         @echo "#define $(HostVendor_CPP)_HOST_VENDOR    1" >> $@
183         @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR  1" >> $@
184         @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
185         @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
186         @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
187         @echo >> $@
188         @echo "#endif /* __PLATFORM_H__ */"          >> $@
189         @echo "Done."
190
191 # For stage2 and above, the BUILD platform is the HOST of stage1, and
192 # the HOST platform is the TARGET of stage1.  The TARGET remains the same
193 # (stage1 is the cross-compiler, not stage2).
194 compiler/stage2/$(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  \"$(HOSTPLATFORM)\"" >> $@
201         @echo "#define HostPlatform_NAME   \"$(TARGETPLATFORM)\"" >> $@
202         @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
203         @echo >> $@
204         @echo "#define $(HostPlatform_CPP)_BUILD        1" >> $@
205         @echo "#define $(TargetPlatform_CPP)_HOST               1" >> $@
206         @echo "#define $(TargetPlatform_CPP)_TARGET     1" >> $@
207         @echo >> $@
208         @echo "#define $(HostArch_CPP)_BUILD_ARCH       1" >> $@
209         @echo "#define $(TargetArch_CPP)_HOST_ARCH      1" >> $@
210         @echo "#define $(TargetArch_CPP)_TARGET_ARCH    1" >> $@
211         @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
212         @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
213         @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
214         @echo >> $@
215         @echo "#define $(HostOS_CPP)_BUILD_OS           1" >> $@
216         @echo "#define $(TargetOS_CPP)_HOST_OS          1" >> $@
217         @echo "#define $(TargetOS_CPP)_TARGET_OS        1" >> $@  
218         @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
219         @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
220         @echo "#define TARGET_OS \"$(TargetOS_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 $(HostVendor_CPP)_BUILD_VENDOR   1" >> $@
228         @echo "#define $(TargetVendor_CPP)_HOST_VENDOR  1" >> $@
229         @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR  1" >> $@
230         @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
231         @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
232         @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
233         @echo >> $@
234         @echo "#endif /* __PLATFORM_H__ */"          >> $@
235         @echo "Done."
236
237 compiler/stage3/$(PLATFORM_H) : compiler/stage2/$(PLATFORM_H)
238         "$(CP)" $< $@
239
240 # ----------------------------------------------------------------------------
241 #               Generate supporting stuff for prelude/PrimOp.lhs 
242 #               from prelude/primops.txt
243
244 # XXX: these should go in stage1/stage2/stage3
245 PRIMOP_BITS = compiler/primop-data-decl.hs-incl        \
246               compiler/primop-tag.hs-incl              \
247               compiler/primop-list.hs-incl             \
248               compiler/primop-has-side-effects.hs-incl \
249               compiler/primop-out-of-line.hs-incl      \
250               compiler/primop-commutable.hs-incl       \
251               compiler/primop-needs-wrapper.hs-incl    \
252               compiler/primop-can-fail.hs-incl         \
253               compiler/primop-strictness.hs-incl       \
254               compiler/primop-primop-info.hs-incl
255
256 compiler_CPP_OPTS += -I$(GHC_INCLUDE_DIR)
257 compiler_CPP_OPTS += ${GhcCppOpts}
258
259 $(PRIMOPS_TXT) compiler/parser/Parser.y: %: %.pp compiler/stage1/$(PLATFORM_H)
260         $(CPP) $(RAWCPP_FLAGS) -P $(compiler_CPP_OPTS) -x c $< | grep -v '^#pragma GCC' > $@
261
262 $(eval $(call clean-target,compiler,primop, $(PRIMOPS_TXT) compiler/parser/Parser.y $(PRIMOP_BITS)))
263
264 ifneq "$(BootingFromHc)" "YES"
265 compiler/primop-data-decl.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
266         "$(GENPRIMOP_INPLACE)" --data-decl          < $< > $@
267 compiler/primop-tag.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
268         "$(GENPRIMOP_INPLACE)" --primop-tag         < $< > $@
269 compiler/primop-list.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
270         "$(GENPRIMOP_INPLACE)" --primop-list        < $< > $@
271 compiler/primop-has-side-effects.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
272         "$(GENPRIMOP_INPLACE)" --has-side-effects   < $< > $@
273 compiler/primop-out-of-line.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
274         "$(GENPRIMOP_INPLACE)" --out-of-line        < $< > $@
275 compiler/primop-commutable.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
276         "$(GENPRIMOP_INPLACE)" --commutable         < $< > $@
277 compiler/primop-needs-wrapper.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
278         "$(GENPRIMOP_INPLACE)" --needs-wrapper      < $< > $@
279 compiler/primop-can-fail.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
280         "$(GENPRIMOP_INPLACE)" --can-fail           < $< > $@
281 compiler/primop-strictness.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
282         "$(GENPRIMOP_INPLACE)" --strictness         < $< > $@
283 compiler/primop-primop-info.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
284         "$(GENPRIMOP_INPLACE)" --primop-primop-info < $< > $@
285
286 # Usages aren't used any more; but the generator 
287 # can still generate them if we want them back
288 compiler/primop-usage.hs-incl: $(PRIMOPS_TXT)
289         "$(GENPRIMOP_INPLACE)" --usage              < $< > $@
290 endif
291
292 # -----------------------------------------------------------------------------
293 # Configuration
294
295 compiler_stage1_CONFIGURE_OPTS += --flags=stage1
296 compiler_stage2_CONFIGURE_OPTS += --flags=stage2
297 compiler_stage3_CONFIGURE_OPTS += --flags=stage3
298
299 ifeq "$(GhcWithNativeCodeGen)" "YES"
300 compiler_stage1_CONFIGURE_OPTS += --flags=ncg
301 compiler_stage2_CONFIGURE_OPTS += --flags=ncg
302 endif
303
304 ifeq "$(GhcWithInterpreter)" "YES"
305 compiler_stage2_CONFIGURE_OPTS += --flags=ghci
306
307 ifeq "$(BuildSharedLibs)" "YES"
308 compiler_stage2_CONFIGURE_OPTS += --enable-shared
309 # If we are going to use dynamic libraries instead of .o files for ghci,
310 # we will need to always retain CAFs in the compiler.
311 # ghci/keepCAFsForGHCi contains a GNU C __attribute__((constructor))
312 # function which sets the keepCAFs flag for the RTS before any Haskell
313 # code is run.
314 compiler_stage2_CONFIGURE_OPTS += --flags=dynlibs
315 endif
316
317 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
318 # Should GHCI be building info tables in the TABLES_NEXT_TO_CODE style
319 # or not?
320 # XXX This should logically be a CPP option, but there doesn't seem to
321 # be a flag for that
322 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DGHCI_TABLES_NEXT_TO_CODE
323 endif
324
325 # Should the debugger commands be enabled?
326 ifeq "$(GhciWithDebugger)" "YES"
327 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DDEBUGGER
328 endif
329
330 endif
331
332 ifeq "$(GhcWithNativeCodeGen)" "NO"
333 # XXX This should logically be a CPP option, but there doesn't seem to
334 # be a flag for that
335 compiler_CONFIGURE_OPTS += --ghc-option=-DOMIT_NATIVE_CODEGEN
336 endif
337
338 ifeq "$(TargetOS_CPP)" "openbsd"
339 compiler_CONFIGURE_OPTS += --ld-options=-E
340 endif
341
342 ifeq "$(GhcUnregisterised)" "NO"
343 ifeq "$(HOSTPLATFORM)" "ia64-unknown-linux"
344 # needed for generating proper relocation in large binaries: trac #856
345 compiler_CONFIGURE_OPTS += --ld-option=-Wl,--relax
346 endif
347 endif
348
349 # We need to turn on profiling either if we have been asked to
350 # (GhcLibProfiled = YES) or if we want GHC itself to be compiled with
351 # profiling enabled (GhcProfiled = YES).
352 ifneq "$(GhcLibProfiled) $(GhcProfiled)" "NO NO"
353 compiler_stage2_CONFIGURE_OPTS += --enable-library-profiling
354 # And if we're profiling GHC then we want lots of SCCs.
355 # We also don't want to waste time building the non-profiling library,
356 # either normally or for ghci. Unfortunately this means that we have to
357 # tell ghc-pkg --force as it gets upset when libHSghc-6.9.a doesn't
358 # exist.
359 ifeq "$(GhcProfiled)" "YES"
360 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-auto-all
361 compiler_stage2_CONFIGURE_OPTS += --disable-library-vanilla
362 compiler_stage2_CONFIGURE_OPTS += --disable-library-for-ghci
363 compiler_stage2_CONFIGURE_OPTS += --ghc-pkg-option=--force
364 endif
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_CONFIGURE_OPTS += --ghc-options='$(GhcStage1HcOpts)'
397 compiler_stage2_CONFIGURE_OPTS += --ghc-options='$(GhcStage2HcOpts)'
398 compiler_stage3_CONFIGURE_OPTS += --ghc-options='$(GhcStage3HcOpts)'
399
400 compiler/stage1/package-data.mk : compiler/ghc.mk
401 compiler/stage2/package-data.mk : compiler/ghc.mk
402 compiler/stage3/package-data.mk : compiler/ghc.mk
403
404 # -----------------------------------------------------------------------------
405 # And build the package
406
407 compiler_PACKAGE = ghc
408
409 # Note [fiddle-stage1-version]
410 # The version of the GHC package changes every day, since the
411 # patchlevel is the current date.  We don't want to force
412 # recompilation of the entire compiler when this happens, so for stage
413 # 1 we omit the patchlevel from the version number.  For stage 2 we
414 # have to include the patchlevel since this is the package we install,
415 # however.
416 #
417 # Note: we also have to tweak the version number of the package itself
418 # when it gets registered; see Note [munge-stage1-package-config]
419 # below.
420 # The ProjectPatchLevel > 20000000 iff it's a date. If it's e.g. 6.12.1
421 # then we don't want to remove it
422 ifneq "$(CLEANING)" "YES"
423 ifeq "$(shell [ $(ProjectPatchLevel) -gt 20000000 ] && echo YES)" "YES"
424 compiler_stage1_VERSION_MUNGED = YES
425 endif
426 endif
427
428 ifeq "$(compiler_stage1_VERSION_MUNGED)" "YES"
429 define compiler_PACKAGE_MAGIC
430 compiler_stage1_VERSION = $(subst .$(ProjectPatchLevel),,$(ProjectVersion))
431 endef
432
433 # Don't register the non-munged package
434 compiler_stage1_REGISTER_PACKAGE = NO
435
436 endif
437
438 # haddocking only happens for stage2
439 compiler_stage1_DO_HADDOCK = NO
440 compiler_stage3_DO_HADDOCK = NO
441
442 # Don't do splitting for the GHC package, it takes too long and
443 # there's not much benefit.
444 compiler_stage1_SplitObjs = NO
445 compiler_stage2_SplitObjs = NO
446 compiler_stage3_SplitObjs = NO
447
448 # For now, bindists always use stage 2
449 ifneq "$(BINDIST)" "YES"
450 # stage 1 is enabled unless $(stage) is set to something other than 1
451 ifeq "$(filter-out 1,$(stage))" ""
452 $(eval $(call build-package,compiler,stage1,0))
453 endif
454 endif
455
456 # stage 2 is enabled unless $(stage) is set to something other than 2
457 ifeq "$(filter-out 2,$(stage))" ""
458 $(eval $(call build-package,compiler,stage2,1))
459 endif
460
461 ifneq "$(BINDIST)" "YES"
462 # stage 3 has to be requested explicitly with stage=3
463 ifeq "$(stage)" "3"
464 $(eval $(call build-package,compiler,stage3,2))
465 endif
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/PrimOps_HC_OPTS += -fforce-recomp
487 compiler/main/Constants_HC_OPTS  += -fforce-recomp
488
489 # Note [munge-stage1-package-config]
490 # Strip the date/patchlevel from the version of stage1.  See Note
491 # [fiddle-stage1-version] above.
492 ifeq "$(compiler_stage1_VERSION_MUNGED)" "YES"
493 compiler/stage1/inplace-pkg-config-munged: compiler/stage1/inplace-pkg-config
494         sed -e 's/^\(version: .*\)\.$(ProjectPatchLevel)$$/\1/' \
495             -e 's/^\(id: .*\)\.$(ProjectPatchLevel)$$/\1/' \
496             -e 's/^\(hs-libraries: HSghc-.*\)\.$(ProjectPatchLevel)$$/\1/' \
497           < $< > $@
498         "$(compiler_stage1_GHC_PKG)" update --force $(compiler_stage1_GHC_PKG_OPTS) $@
499
500 $(compiler_stage1_v_LIB) : compiler/stage1/inplace-pkg-config-munged
501 endif
502
503 endif
504