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