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