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