Put the generated Parser.y under compiler/stage<n>/build; fixes #7195
[ghc.git] / compiler / ghc.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009-2012 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 # This is just to avoid generating a warning when generating deps
31 # involving RtsFlags.h
32 compiler_stage1_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES
33 compiler_stage2_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES
34 compiler_stage3_MKDEPENDC_OPTS = -DMAKING_GHC_BUILD_SYSTEM_DEPENDENCIES
35
36 compiler_stage1_C_FILES_NODEPS = compiler/parser/cutils.c
37
38 ifneq "$(BINDIST)" "YES"
39 compiler/stage1/package-data.mk : compiler/stage1/build/Config.hs
40 compiler/stage2/package-data.mk : compiler/stage2/build/Config.hs
41 compiler/stage3/package-data.mk : compiler/stage3/build/Config.hs
42 endif
43
44 compiler/stage%/build/Config.hs : mk/config.mk mk/project.mk | $$(dir $$@)/.
45 $(call removeFiles,$@)
46 @echo 'Creating $@ ... '
47 @echo '{-# LANGUAGE CPP #-}' >> $@
48 @echo 'module Config where' >> $@
49 @echo >> $@
50 @echo '#include "ghc_boot_platform.h"' >> $@
51 @echo >> $@
52 @echo 'data IntegerLibrary = IntegerGMP | IntegerSimple' >> $@
53 @echo ' deriving Eq' >> $@
54 @echo >> $@
55 @echo 'cBuildPlatformString :: String' >> $@
56 @echo 'cBuildPlatformString = BuildPlatform_NAME' >> $@
57 @echo 'cHostPlatformString :: String' >> $@
58 @echo 'cHostPlatformString = HostPlatform_NAME' >> $@
59 @echo 'cTargetPlatformString :: String' >> $@
60 @echo 'cTargetPlatformString = TargetPlatform_NAME' >> $@
61 @echo >> $@
62 @echo 'cProjectName :: String' >> $@
63 @echo 'cProjectName = "$(ProjectName)"' >> $@
64 @echo 'cProjectVersion :: String' >> $@
65 @echo 'cProjectVersion = "$(ProjectVersion)"' >> $@
66 @echo 'cProjectVersionInt :: String' >> $@
67 @echo 'cProjectVersionInt = "$(ProjectVersionInt)"' >> $@
68 @echo 'cProjectPatchLevel :: String' >> $@
69 @echo 'cProjectPatchLevel = "$(ProjectPatchLevel)"' >> $@
70 @echo 'cBooterVersion :: String' >> $@
71 @echo 'cBooterVersion = "$(GhcVersion)"' >> $@
72 @echo 'cStage :: String' >> $@
73 @echo 'cStage = show (STAGE :: Int)' >> $@
74 @echo 'cIntegerLibrary :: String' >> $@
75 @echo 'cIntegerLibrary = "$(INTEGER_LIBRARY)"' >> $@
76 @echo 'cIntegerLibraryType :: IntegerLibrary' >> $@
77 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
78 @echo 'cIntegerLibraryType = IntegerGMP' >> $@
79 else ifeq "$(INTEGER_LIBRARY)" "integer-simple"
80 @echo 'cIntegerLibraryType = IntegerSimple' >> $@
81 else ifneq "$(CLEANING)" "YES"
82 $(error Unknown integer library)
83 endif
84 @echo 'cSupportsSplitObjs :: String' >> $@
85 @echo 'cSupportsSplitObjs = "$(SupportsSplitObjs)"' >> $@
86 @echo 'cGhcWithInterpreter :: String' >> $@
87 @echo 'cGhcWithInterpreter = "$(GhcWithInterpreter)"' >> $@
88 @echo 'cGhcWithNativeCodeGen :: String' >> $@
89 @echo 'cGhcWithNativeCodeGen = "$(GhcWithNativeCodeGen)"' >> $@
90 @echo 'cGhcWithSMP :: String' >> $@
91 @echo 'cGhcWithSMP = "$(GhcWithSMP)"' >> $@
92 @echo 'cGhcRTSWays :: String' >> $@
93 @echo 'cGhcRTSWays = "$(GhcRTSWays)"' >> $@
94 @echo 'cGhcEnableTablesNextToCode :: String' >> $@
95 @echo 'cGhcEnableTablesNextToCode = "$(GhcEnableTablesNextToCode)"' >> $@
96 @echo 'cLeadingUnderscore :: String' >> $@
97 @echo 'cLeadingUnderscore = "$(LeadingUnderscore)"' >> $@
98 @echo 'cRAWCPP_FLAGS :: String' >> $@
99 @echo 'cRAWCPP_FLAGS = "$(RAWCPP_FLAGS)"' >> $@
100 @echo 'cGHC_DRIVER_DIR :: String' >> $@
101 @echo 'cGHC_DRIVER_DIR = "$(GHC_DRIVER_DIR)"' >> $@
102 @echo 'cGHC_UNLIT_PGM :: String' >> $@
103 @echo 'cGHC_UNLIT_PGM = "$(GHC_UNLIT_PGM)"' >> $@
104 @echo 'cGHC_UNLIT_DIR :: String' >> $@
105 @echo 'cGHC_UNLIT_DIR = "$(GHC_UNLIT_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 'cDEFAULT_TMPDIR :: String' >> $@
115 @echo 'cDEFAULT_TMPDIR = "$(DEFAULT_TMPDIR)"' >> $@
116 @echo 'cLibFFI :: Bool' >> $@
117 ifeq "$(UseLibFFIForAdjustors)" "YES"
118 @echo 'cLibFFI = True' >> $@
119 else
120 @echo 'cLibFFI = False' >> $@
121 endif
122 @echo done.
123
124 # -----------------------------------------------------------------------------
125 # Create platform includes
126
127 # Here we generate a little header file containing CPP symbols that GHC
128 # uses to determine which platform it is building on/for. The platforms
129 # can differ between stage1 and stage2 if we're cross-compiling, so we
130 # need one of these header files per stage.
131
132 PLATFORM_H = ghc_boot_platform.h
133
134 ifeq "$(BuildingCrossCompiler)" "YES"
135 compiler/stage1/$(PLATFORM_H) : compiler/stage2/$(PLATFORM_H)
136 cp $< $@
137 else
138 compiler/stage1/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
139 $(call removeFiles,$@)
140 @echo "Creating $@..."
141 @echo "#ifndef __PLATFORM_H__" >> $@
142 @echo "#define __PLATFORM_H__" >> $@
143 @echo >> $@
144 @echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
145 @echo "#define HostPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
146 @echo "#define TargetPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
147 @echo >> $@
148 @echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
149 @echo "#define $(BuildPlatform_CPP)_HOST 1" >> $@
150 @echo "#define $(HostPlatform_CPP)_TARGET 1" >> $@
151 @echo >> $@
152 @echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
153 @echo "#define $(BuildArch_CPP)_HOST_ARCH 1" >> $@
154 @echo "#define $(HostArch_CPP)_TARGET_ARCH 1" >> $@
155 @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
156 @echo "#define HOST_ARCH \"$(BuildArch_CPP)\"" >> $@
157 @echo "#define TARGET_ARCH \"$(HostArch_CPP)\"" >> $@
158 @echo >> $@
159 @echo "#define $(BuildOS_CPP)_BUILD_OS 1" >> $@
160 @echo "#define $(BuildOS_CPP)_HOST_OS 1" >> $@
161 @echo "#define $(HostOS_CPP)_TARGET_OS 1" >> $@
162 @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
163 @echo "#define HOST_OS \"$(BuildOS_CPP)\"" >> $@
164 @echo "#define TARGET_OS \"$(HostOS_CPP)\"" >> $@
165 ifeq "$(HostOS_CPP)" "irix"
166 @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS" >> $@
167 @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
168 @echo "#endif" >> $@
169 endif
170 @echo >> $@
171 @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
172 @echo "#define $(BuildVendor_CPP)_HOST_VENDOR 1" >> $@
173 @echo "#define $(HostVendor_CPP)_TARGET_VENDOR 1" >> $@
174 @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
175 @echo "#define HOST_VENDOR \"$(BuildVendor_CPP)\"" >> $@
176 @echo "#define TARGET_VENDOR \"$(HostVendor_CPP)\"" >> $@
177 @echo >> $@
178 @echo "#endif /* __PLATFORM_H__ */" >> $@
179 @echo "Done."
180 endif
181
182 # For stage2 and above, the BUILD platform is the HOST of stage1, and
183 # the HOST platform is the TARGET of stage1. The TARGET remains the same
184 # (stage1 is the cross-compiler, not stage2).
185 compiler/stage2/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
186 $(call removeFiles,$@)
187 @echo "Creating $@..."
188 @echo "#ifndef __PLATFORM_H__" >> $@
189 @echo "#define __PLATFORM_H__" >> $@
190 @echo >> $@
191 @echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
192 @echo "#define HostPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
193 @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
194 @echo >> $@
195 @echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
196 @echo "#define $(HostPlatform_CPP)_HOST 1" >> $@
197 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
198 @echo >> $@
199 @echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
200 @echo "#define $(HostArch_CPP)_HOST_ARCH 1" >> $@
201 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
202 @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
203 @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
204 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
205 @echo >> $@
206 @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
207 @echo "#define $(HostOS_CPP)_HOST_OS 1" >> $@
208 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
209 @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
210 @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
211 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
212 ifeq "$(TargetOS_CPP)" "irix"
213 @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS" >> $@
214 @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
215 @echo "#endif" >> $@
216 endif
217 @echo >> $@
218 @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
219 @echo "#define $(HostVendor_CPP)_HOST_VENDOR 1" >> $@
220 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
221 @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
222 @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
223 @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
224 @echo >> $@
225 @echo "#endif /* __PLATFORM_H__ */" >> $@
226 @echo "Done."
227
228 compiler/stage3/$(PLATFORM_H) : compiler/stage2/$(PLATFORM_H)
229 "$(CP)" $< $@
230
231 # ----------------------------------------------------------------------------
232 # Generate supporting stuff for prelude/PrimOp.lhs
233 # from prelude/primops.txt
234
235 # XXX: these should go in stage1/stage2/stage3
236 PRIMOP_BITS = compiler/primop-data-decl.hs-incl \
237 compiler/primop-tag.hs-incl \
238 compiler/primop-list.hs-incl \
239 compiler/primop-has-side-effects.hs-incl \
240 compiler/primop-out-of-line.hs-incl \
241 compiler/primop-commutable.hs-incl \
242 compiler/primop-code-size.hs-incl \
243 compiler/primop-can-fail.hs-incl \
244 compiler/primop-strictness.hs-incl \
245 compiler/primop-primop-info.hs-incl
246
247 compiler_CPP_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
248 compiler_CPP_OPTS += ${GhcCppOpts}
249
250 define preprocessCompilerFiles
251 # $0 = stage
252 compiler/stage$1/build/Parser.y: compiler/parser/Parser.y.pp
253 $$(CPP) $$(RAWCPP_FLAGS) -P $$(compiler_CPP_OPTS) -x c $$< | grep -v '^#pragma GCC' > $$@
254 endef
255
256 $(eval $(call preprocessCompilerFiles,1))
257 $(eval $(call preprocessCompilerFiles,2))
258 $(eval $(call preprocessCompilerFiles,3))
259
260
261 $(PRIMOPS_TXT): %: %.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-code-size.hs-incl: $(PRIMOPS_TXT) $(GENPRIMOP_INPLACE)
280 "$(GENPRIMOP_INPLACE)" --code-size < $< > $@
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 # There are too many symbols to make a Windows DLL for the ghc package,
311 # so we don't build it the dyn way; see trac #5987
312 ifneq "$(TargetOS_CPP)" "mingw32"
313 compiler_stage2_CONFIGURE_OPTS += --enable-shared
314 # If we are going to use dynamic libraries instead of .o files for ghci,
315 # we will need to always retain CAFs in the compiler.
316 # ghci/keepCAFsForGHCi contains a GNU C __attribute__((constructor))
317 # function which sets the keepCAFs flag for the RTS before any Haskell
318 # code is run.
319 compiler_stage2_CONFIGURE_OPTS += --flags=dynlibs
320 endif
321 endif
322
323 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
324 # Should GHCI be building info tables in the TABLES_NEXT_TO_CODE style
325 # or not?
326 # XXX This should logically be a CPP option, but there doesn't seem to
327 # be a flag for that
328 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DGHCI_TABLES_NEXT_TO_CODE
329 endif
330
331 # Should the debugger commands be enabled?
332 ifeq "$(GhciWithDebugger)" "YES"
333 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DDEBUGGER
334 endif
335
336 endif
337
338 ifeq "$(TargetOS_CPP)" "openbsd"
339 compiler_CONFIGURE_OPTS += --ld-options=-E
340 endif
341
342 ifeq "$(GhcUnregisterised)" "NO"
343 else
344 compiler_CONFIGURE_OPTS += --ghc-option=-DNO_REGS
345 endif
346
347 ifeq "$(GhcProfiled)" "YES"
348
349 # If we're profiling GHC then we want SCCs. However, adding -auto-all
350 # everywhere tends to give a hard-to-read profile, and adds lots of
351 # overhead. A better approach is to proceed top-down; identify the
352 # parts of the compiler of interest, and then add further cost centres
353 # as necessary. Turn on -auto-all for individual modules like this:
354
355 # compiler/main/DriverPipeline_HC_OPTS += -auto-all
356 compiler/main/GhcMake_HC_OPTS += -auto-all
357 compiler/main/GHC_HC_OPTS += -auto-all
358
359 # or alternatively add {-# OPTIONS_GHC -auto-all #-} to the top of
360 # modules you're interested in.
361
362 # We seem to still build the vanilla libraries even if we say
363 # --disable-library-vanilla, but installation then fails, as Cabal
364 # doesn't copy the vanilla .hi files, but ghc-pkg complains about
365 # their absence when we register the package. So for now, we just
366 # leave the vanilla libraries enabled.
367 # compiler_stage2_CONFIGURE_OPTS += --disable-library-vanilla
368 compiler_stage2_CONFIGURE_OPTS += --ghc-pkg-option=--force
369 endif
370
371 compiler_stage3_CONFIGURE_OPTS := $(compiler_stage2_CONFIGURE_OPTS)
372
373 compiler_stage1_CONFIGURE_OPTS += --ghc-option=-DSTAGE=1
374 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DSTAGE=2
375 compiler_stage3_CONFIGURE_OPTS += --ghc-option=-DSTAGE=3
376 compiler_stage2_HADDOCK_OPTS += --optghc=-DSTAGE=2
377
378 compiler/stage1/package-data.mk : compiler/ghc.mk
379 compiler/stage2/package-data.mk : compiler/ghc.mk
380 compiler/stage3/package-data.mk : compiler/ghc.mk
381
382 # -----------------------------------------------------------------------------
383 # And build the package
384
385 compiler_PACKAGE = ghc
386
387 # Note [fiddle-stage1-version]
388 # The version of the GHC package changes every day, since the
389 # patchlevel is the current date. We don't want to force
390 # recompilation of the entire compiler when this happens, so for stage
391 # 1 we omit the patchlevel from the version number. For stage 2 we
392 # have to include the patchlevel since this is the package we install,
393 # however.
394 #
395 # Note: we also have to tweak the version number of the package itself
396 # when it gets registered; see Note [munge-stage1-package-config]
397 # below.
398 # The ProjectPatchLevel > 20000000 iff it's a date. If it's e.g. 6.12.1
399 # then we don't want to remove it
400 ifneq "$(CLEANING)" "YES"
401 ifeq "$(shell [ $(ProjectPatchLevel) -gt 20000000 ] && echo YES)" "YES"
402 compiler_stage1_VERSION_MUNGED = YES
403 endif
404 endif
405
406 ifeq "$(compiler_stage1_VERSION_MUNGED)" "YES"
407 compiler_stage1_MUNGED_VERSION = $(subst .$(ProjectPatchLevel),,$(ProjectVersion))
408 define compiler_PACKAGE_MAGIC
409 compiler_stage1_VERSION = $(compiler_stage1_MUNGED_VERSION)
410 endef
411
412 # Don't register the non-munged package
413 compiler_stage1_REGISTER_PACKAGE = NO
414
415 endif
416
417 # haddocking only happens for stage2
418 compiler_stage1_DO_HADDOCK = NO
419 compiler_stage3_DO_HADDOCK = NO
420
421 # Don't do splitting for the GHC package, it takes too long and
422 # there's not much benefit.
423 compiler_stage1_SplitObjs = NO
424 compiler_stage2_SplitObjs = NO
425 compiler_stage3_SplitObjs = NO
426
427 ifeq "$(TargetOS_CPP)" "mingw32"
428 # There are too many symbols to make a Windows DLL for the ghc package,
429 # so we don't build it the dyn way; see trac #5987
430 compiler_stage1_EXCLUDED_WAYS := dyn
431 compiler_stage2_EXCLUDED_WAYS := dyn
432 compiler_stage3_EXCLUDED_WAYS := dyn
433 endif
434
435 # if stage is set to something other than "1" or "", disable stage 1
436 ifneq "$(filter-out 1,$(stage))" ""
437 compiler_stage1_NOT_NEEDED = YES
438 endif
439 # if stage is set to something other than "2" or "", disable stage 2
440 ifneq "$(filter-out 2,$(stage))" ""
441 compiler_stage2_NOT_NEEDED = YES
442 endif
443 # stage 3 has to be requested explicitly with stage=3
444 ifneq "$(stage)" "3"
445 compiler_stage3_NOT_NEEDED = YES
446 endif
447 $(eval $(call build-package,compiler,stage1,0))
448 $(eval $(call build-package,compiler,stage2,1))
449 $(eval $(call build-package,compiler,stage3,2))
450
451 # after build-package, because that adds --enable-library-for-ghci
452 # to compiler_stage*_CONFIGURE_OPTS:
453 # We don't build the GHCi library for the ghc package. We can load it
454 # the .a file instead, and as object splitting isn't on for the ghc
455 # package this isn't much slower.However, not building the package saves
456 # a significant chunk of disk space.
457 compiler_stage1_CONFIGURE_OPTS += --disable-library-for-ghci
458 compiler_stage2_CONFIGURE_OPTS += --disable-library-for-ghci
459 compiler_stage3_CONFIGURE_OPTS += --disable-library-for-ghci
460
461 # after build-package, because that sets compiler_stage1_HC_OPTS:
462 compiler_stage1_HC_OPTS += $(GhcStage1HcOpts)
463 compiler_stage2_HC_OPTS += $(GhcStage2HcOpts)
464 compiler_stage3_HC_OPTS += $(GhcStage3HcOpts)
465
466 ifneq "$(BINDIST)" "YES"
467
468 compiler_stage2_TAGS_HC_OPTS = -package ghc
469 $(eval $(call tags-package,compiler,stage2))
470
471 $(compiler_stage1_depfile_haskell) : compiler/stage1/$(PLATFORM_H)
472 $(compiler_stage2_depfile_haskell) : compiler/stage2/$(PLATFORM_H)
473 $(compiler_stage3_depfile_haskell) : compiler/stage3/$(PLATFORM_H)
474
475 COMPILER_INCLUDES_DEPS += $(includes_H_CONFIG)
476 COMPILER_INCLUDES_DEPS += $(includes_H_PLATFORM)
477 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS)
478 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_TYPE)
479 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
480 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_EXPORTS)
481 COMPILER_INCLUDES_DEPS += $(includes_DERIVEDCONSTANTS)
482 COMPILER_INCLUDES_DEPS += $(PRIMOP_BITS)
483
484 $(compiler_stage1_depfile_haskell) : $(COMPILER_INCLUDES_DEPS)
485 $(compiler_stage2_depfile_haskell) : $(COMPILER_INCLUDES_DEPS)
486 $(compiler_stage3_depfile_haskell) : $(COMPILER_INCLUDES_DEPS)
487
488 # Every PrimOp.o object file depends on $(PRIMOP_BITS):
489 $(eval $(call compiler-hs-dependency,PrimOp,$(PRIMOP_BITS)))
490
491 # GHC itself doesn't know about the above dependencies, so we have to
492 # switch off the recompilation checker for that module:
493 compiler/prelude/PrimOp_HC_OPTS += -fforce-recomp
494
495 # LibFFI.hs #includes ffi.h
496 compiler/stage2/build/LibFFI.hs : $(libffi_HEADERS)
497 # On Windows it seems we also need to link directly to libffi
498 ifeq "$(HostOS_CPP)" "mingw32"
499 define windowsDynLinkToFfi
500 # $1 = way
501 ifneq "$$(findstring dyn, $1)" ""
502 compiler_stage2_$1_ALL_HC_OPTS += -l$$(LIBFFI_WINDOWS_LIB)
503 endif
504 endef
505 $(foreach way,$(GhcLibWays),$(eval $(call windowsDynLinkToFfi,$(way))))
506 endif
507
508 # Note [munge-stage1-package-config]
509 # Strip the date/patchlevel from the version of stage1. See Note
510 # [fiddle-stage1-version] above.
511 ifeq "$(compiler_stage1_VERSION_MUNGED)" "YES"
512 compiler/stage1/inplace-pkg-config-munged: compiler/stage1/inplace-pkg-config
513 sed -e 's/^\(version: .*\)\.$(ProjectPatchLevel)$$/\1/' \
514 -e 's/^\(id: .*\)\.$(ProjectPatchLevel)$$/\1/' \
515 -e 's/^\(hs-libraries: HSghc-.*\)\.$(ProjectPatchLevel)$$/\1/' \
516 < $< > $@
517 "$(compiler_stage1_GHC_PKG)" update --force $(compiler_stage1_GHC_PKG_OPTS) $@
518
519 # We need to make sure the munged config is in the database before we
520 # try to configure ghc-bin
521 ghc/stage1/package-data.mk : compiler/stage1/inplace-pkg-config-munged
522 endif
523
524 endif
525