compiler/ghc.mk: restore GhcHcOpts variable handling (Trac #8787)
[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://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://ghc.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 # This package doesn't pass the Cabal checks because include-dirs
28 # points outside the source directory. This isn't a real problem, so
29 # we just skip the check.
30 compiler_NO_CHECK = YES
31
32 ifneq "$(BINDIST)" "YES"
33 compiler/stage1/package-data.mk : compiler/stage1/build/Config.hs
34 compiler/stage2/package-data.mk : compiler/stage2/build/Config.hs
35 compiler/stage3/package-data.mk : compiler/stage3/build/Config.hs
36
37 compiler/stage1/build/PlatformConstants.o: $(includes_GHCCONSTANTS_HASKELL_TYPE)
38 compiler/stage2/build/PlatformConstants.o: $(includes_GHCCONSTANTS_HASKELL_TYPE)
39 compiler/stage3/build/PlatformConstants.o: $(includes_GHCCONSTANTS_HASKELL_TYPE)
40 compiler/stage1/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_EXPORTS)
41 compiler/stage2/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_EXPORTS)
42 compiler/stage3/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_EXPORTS)
43 compiler/stage1/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
44 compiler/stage2/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
45 compiler/stage3/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
46 endif
47
48 compiler/stage%/build/Config.hs : mk/config.mk mk/project.mk | $$(dir $$@)/.
49 $(call removeFiles,$@)
50 @echo 'Creating $@ ... '
51 @echo '{-# LANGUAGE CPP #-}' >> $@
52 @echo 'module Config where' >> $@
53 @echo >> $@
54 @echo '#include "ghc_boot_platform.h"' >> $@
55 @echo >> $@
56 @echo 'data IntegerLibrary = IntegerGMP | IntegerSimple' >> $@
57 @echo ' deriving Eq' >> $@
58 @echo >> $@
59 @echo 'cBuildPlatformString :: String' >> $@
60 @echo 'cBuildPlatformString = BuildPlatform_NAME' >> $@
61 @echo 'cHostPlatformString :: String' >> $@
62 @echo 'cHostPlatformString = HostPlatform_NAME' >> $@
63 @echo 'cTargetPlatformString :: String' >> $@
64 @echo 'cTargetPlatformString = TargetPlatform_NAME' >> $@
65 @echo >> $@
66 @echo 'cProjectName :: String' >> $@
67 @echo 'cProjectName = "$(ProjectName)"' >> $@
68 @echo 'cProjectVersion :: String' >> $@
69 @echo 'cProjectVersion = "$(ProjectVersion)"' >> $@
70 @echo 'cProjectVersionInt :: String' >> $@
71 @echo 'cProjectVersionInt = "$(ProjectVersionInt)"' >> $@
72 @echo 'cProjectPatchLevel :: String' >> $@
73 @echo 'cProjectPatchLevel = "$(ProjectPatchLevel)"' >> $@
74 @echo 'cBooterVersion :: String' >> $@
75 @echo 'cBooterVersion = "$(GhcVersion)"' >> $@
76 @echo 'cStage :: String' >> $@
77 @echo 'cStage = show (STAGE :: Int)' >> $@
78 @echo 'cIntegerLibrary :: String' >> $@
79 @echo 'cIntegerLibrary = "$(INTEGER_LIBRARY)"' >> $@
80 @echo 'cIntegerLibraryType :: IntegerLibrary' >> $@
81 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
82 @echo 'cIntegerLibraryType = IntegerGMP' >> $@
83 else ifeq "$(INTEGER_LIBRARY)" "integer-simple"
84 @echo 'cIntegerLibraryType = IntegerSimple' >> $@
85 else ifneq "$(CLEANING)" "YES"
86 $(error Unknown integer library)
87 endif
88 @echo 'cSupportsSplitObjs :: String' >> $@
89 @echo 'cSupportsSplitObjs = "$(SupportsSplitObjs)"' >> $@
90 @echo 'cGhcWithInterpreter :: String' >> $@
91 @echo 'cGhcWithInterpreter = "$(GhcWithInterpreter)"' >> $@
92 @echo 'cGhcWithNativeCodeGen :: String' >> $@
93 @echo 'cGhcWithNativeCodeGen = "$(GhcWithNativeCodeGen)"' >> $@
94 @echo 'cGhcWithSMP :: String' >> $@
95 @echo 'cGhcWithSMP = "$(GhcWithSMP)"' >> $@
96 @echo 'cGhcRTSWays :: String' >> $@
97 @echo 'cGhcRTSWays = "$(GhcRTSWays)"' >> $@
98 @echo 'cGhcEnableTablesNextToCode :: String' >> $@
99 @echo 'cGhcEnableTablesNextToCode = "$(GhcEnableTablesNextToCode)"' >> $@
100 @echo 'cLeadingUnderscore :: String' >> $@
101 @echo 'cLeadingUnderscore = "$(LeadingUnderscore)"' >> $@
102 @echo 'cGHC_UNLIT_PGM :: String' >> $@
103 @echo 'cGHC_UNLIT_PGM = "$(utils/unlit_dist_PROG)"' >> $@
104 @echo 'cGHC_SPLIT_PGM :: String' >> $@
105 @echo 'cGHC_SPLIT_PGM = "$(driver/split_dist_PROG)"' >> $@
106 @echo 'cLibFFI :: Bool' >> $@
107 ifeq "$(UseLibFFIForAdjustors)" "YES"
108 @echo 'cLibFFI = True' >> $@
109 else
110 @echo 'cLibFFI = False' >> $@
111 endif
112 # Note that GhcThreaded just reflects the Makefile variable setting.
113 # In particular, the stage1 compiler is never actually compiled with
114 # -threaded, but it will nevertheless have cGhcThreaded = True.
115 # The "+RTS --info" output will show what RTS GHC is really using.
116 @echo 'cGhcThreaded :: Bool' >> $@
117 ifeq "$(GhcThreaded)" "YES"
118 @echo 'cGhcThreaded = True' >> $@
119 else
120 @echo 'cGhcThreaded = False' >> $@
121 endif
122 @echo 'cGhcDebugged :: Bool' >> $@
123 ifeq "$(GhcDebugged)" "YES"
124 @echo 'cGhcDebugged = True' >> $@
125 else
126 @echo 'cGhcDebugged = False' >> $@
127 endif
128 @echo done.
129
130 # -----------------------------------------------------------------------------
131 # Create platform includes
132
133 # Here we generate a little header file containing CPP symbols that GHC
134 # uses to determine which platform it is building on/for. The platforms
135 # can differ between stage1 and stage2 if we're cross-compiling, so we
136 # need one of these header files per stage.
137
138 PLATFORM_H = ghc_boot_platform.h
139
140 compiler/stage1/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
141 $(call removeFiles,$@)
142 @echo "Creating $@..."
143 @echo "#ifndef __PLATFORM_H__" >> $@
144 @echo "#define __PLATFORM_H__" >> $@
145 @echo >> $@
146 @echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
147 @echo "#define HostPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
148 @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
149 @echo >> $@
150 @echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
151 @echo "#define $(HostPlatform_CPP)_HOST 1" >> $@
152 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
153 @echo >> $@
154 @echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
155 @echo "#define $(HostArch_CPP)_HOST_ARCH 1" >> $@
156 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
157 @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
158 @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
159 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
160 @echo >> $@
161 @echo "#define $(BuildOS_CPP)_BUILD_OS 1" >> $@
162 @echo "#define $(HostOS_CPP)_HOST_OS 1" >> $@
163 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
164 @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
165 @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
166 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
167 ifeq "$(TargetOS_CPP)" "irix"
168 @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS" >> $@
169 @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
170 @echo "#endif" >> $@
171 endif
172 @echo >> $@
173 @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
174 @echo "#define $(HostVendor_CPP)_HOST_VENDOR 1" >> $@
175 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
176 @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
177 @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
178 @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
179 @echo >> $@
180 @echo "#endif /* __PLATFORM_H__ */" >> $@
181 @echo "Done."
182
183 # For stage2 and above, the BUILD platform is the HOST of stage1, and
184 # the HOST platform is the TARGET of stage1. The TARGET remains the same
185 # (stage1 is the cross-compiler, not stage2).
186 compiler/stage2/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
187 $(call removeFiles,$@)
188 @echo "Creating $@..."
189 @echo "#ifndef __PLATFORM_H__" >> $@
190 @echo "#define __PLATFORM_H__" >> $@
191 @echo >> $@
192 @echo "#define BuildPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
193 @echo "#define HostPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
194 @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
195 @echo >> $@
196 @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
197 @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
198 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
199 @echo >> $@
200 @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
201 @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
202 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
203 @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
204 @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
205 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
206 @echo >> $@
207 @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
208 @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
209 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
210 @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
211 @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
212 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
213 ifeq "$(TargetOS_CPP)" "irix"
214 @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS" >> $@
215 @echo "#define $(IRIX_MAJOR)_TARGET_OS 1" >> $@
216 @echo "#endif" >> $@
217 endif
218 @echo >> $@
219 @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
220 @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
221 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
222 @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
223 @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
224 @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
225 @echo >> $@
226 @echo "#endif /* __PLATFORM_H__ */" >> $@
227 @echo "Done."
228
229 compiler/stage3/$(PLATFORM_H) : compiler/stage2/$(PLATFORM_H)
230 "$(CP)" $< $@
231
232 # ----------------------------------------------------------------------------
233 # Generate supporting stuff for prelude/PrimOp.lhs
234 # from prelude/primops.txt
235
236 PRIMOP_BITS_NAMES = primop-data-decl.hs-incl \
237 primop-tag.hs-incl \
238 primop-list.hs-incl \
239 primop-has-side-effects.hs-incl \
240 primop-out-of-line.hs-incl \
241 primop-commutable.hs-incl \
242 primop-code-size.hs-incl \
243 primop-can-fail.hs-incl \
244 primop-strictness.hs-incl \
245 primop-fixity.hs-incl \
246 primop-primop-info.hs-incl \
247 primop-vector-uniques.hs-incl \
248 primop-vector-tys.hs-incl \
249 primop-vector-tys-exports.hs-incl \
250 primop-vector-tycons.hs-incl
251
252 PRIMOP_BITS_STAGE1 = $(addprefix compiler/stage1/build/,$(PRIMOP_BITS_NAMES))
253 PRIMOP_BITS_STAGE2 = $(addprefix compiler/stage2/build/,$(PRIMOP_BITS_NAMES))
254 PRIMOP_BITS_STAGE3 = $(addprefix compiler/stage3/build/,$(PRIMOP_BITS_NAMES))
255
256 compiler_CPP_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
257 compiler_CPP_OPTS += ${GhcCppOpts}
258
259 define preprocessCompilerFiles
260 # $0 = stage
261 compiler/stage$1/build/Parser.y: compiler/parser/Parser.y.pp
262 $$(CPP) $$(RAWCPP_FLAGS) -P $$(compiler_CPP_OPTS) -x c $$< | grep -v '^#pragma GCC' > $$@
263
264 compiler/stage$1/build/primops.txt: compiler/prelude/primops.txt.pp compiler/stage$1/$$(PLATFORM_H)
265 $$(CPP) $$(RAWCPP_FLAGS) -P $$(compiler_CPP_OPTS) -Icompiler/stage$1 -x c $$< | grep -v '^#pragma GCC' > $$@
266
267 compiler/stage$1/build/primop-data-decl.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
268 "$$(genprimopcode_INPLACE)" --data-decl < $$< > $$@
269 compiler/stage$1/build/primop-tag.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
270 "$$(genprimopcode_INPLACE)" --primop-tag < $$< > $$@
271 compiler/stage$1/build/primop-list.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
272 "$$(genprimopcode_INPLACE)" --primop-list < $$< > $$@
273 compiler/stage$1/build/primop-has-side-effects.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
274 "$$(genprimopcode_INPLACE)" --has-side-effects < $$< > $$@
275 compiler/stage$1/build/primop-out-of-line.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
276 "$$(genprimopcode_INPLACE)" --out-of-line < $$< > $$@
277 compiler/stage$1/build/primop-commutable.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
278 "$$(genprimopcode_INPLACE)" --commutable < $$< > $$@
279 compiler/stage$1/build/primop-code-size.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
280 "$$(genprimopcode_INPLACE)" --code-size < $$< > $$@
281 compiler/stage$1/build/primop-can-fail.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
282 "$$(genprimopcode_INPLACE)" --can-fail < $$< > $$@
283 compiler/stage$1/build/primop-strictness.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
284 "$$(genprimopcode_INPLACE)" --strictness < $$< > $$@
285 compiler/stage$1/build/primop-fixity.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
286 "$$(genprimopcode_INPLACE)" --fixity < $$< > $$@
287 compiler/stage$1/build/primop-primop-info.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
288 "$$(genprimopcode_INPLACE)" --primop-primop-info < $$< > $$@
289 compiler/stage$1/build/primop-vector-uniques.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
290 "$$(genprimopcode_INPLACE)" --primop-vector-uniques < $$< > $$@
291 compiler/stage$1/build/primop-vector-tys.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
292 "$$(genprimopcode_INPLACE)" --primop-vector-tys < $$< > $$@
293 compiler/stage$1/build/primop-vector-tys-exports.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
294 "$$(genprimopcode_INPLACE)" --primop-vector-tys-exports < $$< > $$@
295 compiler/stage$1/build/primop-vector-tycons.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
296 "$$(genprimopcode_INPLACE)" --primop-vector-tycons < $$< > $$@
297
298 # Usages aren't used any more; but the generator
299 # can still generate them if we want them back
300 compiler/stage$1/build/primop-usage.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
301 "$$(genprimopcode_INPLACE)" --usage < $$< > $$@
302
303 endef
304
305 $(eval $(call preprocessCompilerFiles,1))
306 $(eval $(call preprocessCompilerFiles,2))
307 $(eval $(call preprocessCompilerFiles,3))
308
309 # -----------------------------------------------------------------------------
310 # Configuration
311
312 compiler_stage1_CONFIGURE_OPTS += --flags=stage1
313 compiler_stage2_CONFIGURE_OPTS += --flags=stage2
314 compiler_stage3_CONFIGURE_OPTS += --flags=stage3
315
316 ifeq "$(GhcThreaded)" "YES"
317 # We pass THREADED_RTS to the stage2 C files so that cbits/genSym.c will bring
318 # the threaded version of atomic_inc() into scope.
319 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-optc-DTHREADED_RTS
320 endif
321
322 ifeq "$(GhcWithNativeCodeGen)" "YES"
323 compiler_stage1_CONFIGURE_OPTS += --flags=ncg
324 compiler_stage2_CONFIGURE_OPTS += --flags=ncg
325 endif
326
327 ifeq "$(GhcWithInterpreter)" "YES"
328 compiler_stage2_CONFIGURE_OPTS += --flags=ghci
329
330 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
331 # Should GHCI be building info tables in the TABLES_NEXT_TO_CODE style
332 # or not?
333 # XXX This should logically be a CPP option, but there doesn't seem to
334 # be a flag for that
335 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DGHCI_TABLES_NEXT_TO_CODE
336 endif
337
338 # Should the debugger commands be enabled?
339 ifeq "$(GhciWithDebugger)" "YES"
340 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DDEBUGGER
341 endif
342
343 endif
344
345 ifeq "$(TargetOS_CPP)" "openbsd"
346 compiler_CONFIGURE_OPTS += --ld-options=-E
347 endif
348
349 ifeq "$(GhcUnregisterised)" "NO"
350 else
351 compiler_CONFIGURE_OPTS += --ghc-option=-DNO_REGS
352 endif
353
354 ifneq "$(GhcWithSMP)" "YES"
355 compiler_CONFIGURE_OPTS += --ghc-option=-DNOSMP
356 compiler_CONFIGURE_OPTS += --ghc-option=-optc-DNOSMP
357 endif
358
359 # Careful optimisation of the parser: we don't want to throw everything
360 # at it, because that takes too long and doesn't buy much, but we do want
361 # to inline certain key external functions, so we instruct GHC not to
362 # throw away inlinings as it would normally do in -O0 mode.
363 compiler/stage1/build/Parser_HC_OPTS += -O0 -fno-ignore-interface-pragmas
364 # If we're bootstrapping the compiler during stage2, or we're being
365 # built by a GHC whose version is > 7.8, we need -fcmm-sink to be
366 # passed to the compiler. This is required on x86 to avoid the
367 # register allocator running out of stack slots when compiling this
368 # module with -fPIC -dynamic.
369 # See #8182 for all the details
370 ifeq "$(CMM_SINK_BOOTSTRAP_IS_NEEDED)" "YES"
371 compiler/stage1/build/Parser_HC_OPTS += -fcmm-sink
372 endif
373 # We also pass -fcmm-sink to every stage != 1
374 compiler/stage2/build/Parser_HC_OPTS += -O0 -fno-ignore-interface-pragmas -fcmm-sink
375 compiler/stage3/build/Parser_HC_OPTS += -O0 -fno-ignore-interface-pragmas -fcmm-sink
376
377
378 ifeq "$(GhcProfiled)" "YES"
379 # If we're profiling GHC then we want SCCs. However, adding -auto-all
380 # everywhere tends to give a hard-to-read profile, and adds lots of
381 # overhead. A better approach is to proceed top-down; identify the
382 # parts of the compiler of interest, and then add further cost centres
383 # as necessary. Turn on -auto-all for individual modules like this:
384
385 # compiler/main/DriverPipeline_HC_OPTS += -auto-all
386 compiler/main/GhcMake_HC_OPTS += -auto-all
387 compiler/main/GHC_HC_OPTS += -auto-all
388
389 # or alternatively add {-# OPTIONS_GHC -auto-all #-} to the top of
390 # modules you're interested in.
391
392 # We seem to still build the vanilla libraries even if we say
393 # --disable-library-vanilla, but installation then fails, as Cabal
394 # doesn't copy the vanilla .hi files, but ghc-pkg complains about
395 # their absence when we register the package. So for now, we just
396 # leave the vanilla libraries enabled.
397 # compiler_stage2_CONFIGURE_OPTS += --disable-library-vanilla
398 compiler_stage2_CONFIGURE_OPTS += --ghc-pkg-option=--force
399 endif
400
401 compiler_stage3_CONFIGURE_OPTS := $(compiler_stage2_CONFIGURE_OPTS)
402
403 compiler_stage1_CONFIGURE_OPTS += --ghc-option=-DSTAGE=1
404 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DSTAGE=2
405 compiler_stage3_CONFIGURE_OPTS += --ghc-option=-DSTAGE=3
406 compiler_stage2_HADDOCK_OPTS += --optghc=-DSTAGE=2
407
408 compiler/stage1/package-data.mk : compiler/ghc.mk
409 compiler/stage2/package-data.mk : compiler/ghc.mk
410 compiler/stage3/package-data.mk : compiler/ghc.mk
411
412 # -----------------------------------------------------------------------------
413 # And build the package
414
415 compiler_PACKAGE = ghc
416
417 # Note [fiddle-stage1-version]
418 # The version of the GHC package changes every day, since the
419 # patchlevel is the current date. We don't want to force
420 # recompilation of the entire compiler when this happens, so for stage
421 # 1 we omit the patchlevel from the version number. For stage 2 we
422 # have to include the patchlevel since this is the package we install,
423 # however.
424 #
425 # Note: we also have to tweak the version number of the package itself
426 # when it gets registered; see Note [munge-stage1-package-config]
427 # below.
428 # The ProjectPatchLevel > 20000000 iff it's a date. If it's e.g. 6.12.1
429 # then we don't want to remove it
430 ifneq "$(CLEANING)" "YES"
431 ifeq "$(shell [ $(ProjectPatchLevel) -gt 20000000 ] && echo YES)" "YES"
432 compiler_stage1_VERSION_MUNGED = YES
433 endif
434 endif
435
436 ifeq "$(compiler_stage1_VERSION_MUNGED)" "YES"
437 compiler_stage1_MUNGED_VERSION = $(subst .$(ProjectPatchLevel),,$(ProjectVersion))
438 define compiler_PACKAGE_MAGIC
439 compiler_stage1_VERSION = $(compiler_stage1_MUNGED_VERSION)
440 endef
441
442 # Don't register the non-munged package
443 compiler_stage1_REGISTER_PACKAGE = NO
444
445 endif
446
447 # Don't do splitting for the GHC package, it takes too long and
448 # there's not much benefit.
449 compiler_stage1_SplitObjs = NO
450 compiler_stage2_SplitObjs = NO
451 compiler_stage3_SplitObjs = NO
452
453 # There are too many symbols in the ghc package for a Windows DLL.
454 # We therefore need to split some of the modules off into a separate
455 # DLL. This clump are the modules reachable from DynFlags:
456 compiler_stage2_dll0_START_MODULE = DynFlags
457 compiler_stage2_dll0_MODULES = \
458 Annotations \
459 Avail \
460 Bag \
461 BasicTypes \
462 BinIface \
463 Binary \
464 Bitmap \
465 BlockId \
466 BooleanFormula \
467 BreakArray \
468 BufWrite \
469 BuildTyCl \
470 ByteCodeAsm \
471 ByteCodeInstr \
472 ByteCodeItbls \
473 CLabel \
474 Class \
475 CmdLineParser \
476 Cmm \
477 CmmCallConv \
478 CmmExpr \
479 CmmInfo \
480 CmmMachOp \
481 CmmNode \
482 CmmType \
483 CmmUtils \
484 CoAxiom \
485 ConLike \
486 CodeGen.Platform \
487 CodeGen.Platform.ARM \
488 CodeGen.Platform.NoRegs \
489 CodeGen.Platform.PPC \
490 CodeGen.Platform.PPC_Darwin \
491 CodeGen.Platform.SPARC \
492 CodeGen.Platform.X86 \
493 CodeGen.Platform.X86_64 \
494 Coercion \
495 Config \
496 Constants \
497 CoreArity \
498 CoreFVs \
499 CoreLint \
500 CoreSubst \
501 CoreSyn \
502 CoreTidy \
503 CoreUnfold \
504 CoreUtils \
505 CostCentre \
506 DataCon \
507 Demand \
508 Digraph \
509 DriverPhases \
510 DsMonad \
511 DynFlags \
512 Encoding \
513 ErrUtils \
514 Exception \
515 ExtsCompat46 \
516 FamInstEnv \
517 FastBool \
518 FastFunctions \
519 FastMutInt \
520 FastString \
521 FastTypes \
522 Finder \
523 Fingerprint \
524 FiniteMap \
525 ForeignCall \
526 Hooks \
527 Hoopl \
528 Hoopl.Dataflow \
529 HsBinds \
530 HsDecls \
531 HsDoc \
532 HsExpr \
533 HsImpExp \
534 HsLit \
535 HsPat \
536 HsSyn \
537 HsTypes \
538 HsUtils \
539 HscTypes \
540 IOEnv \
541 Id \
542 IdInfo \
543 IfaceEnv \
544 IfaceSyn \
545 IfaceType \
546 InstEnv \
547 InteractiveEvalTypes \
548 Kind \
549 ListSetOps \
550 Literal \
551 LoadIface \
552 Maybes \
553 MkCore \
554 MkGraph \
555 MkId \
556 Module \
557 MonadUtils \
558 Name \
559 NameEnv \
560 NameSet \
561 OccName \
562 OccurAnal \
563 OptCoercion \
564 OrdList \
565 Outputable \
566 PackageConfig \
567 Packages \
568 Pair \
569 Panic \
570 PatSyn \
571 PipelineMonad \
572 Platform \
573 PlatformConstants \
574 PprCmm \
575 PprCmmDecl \
576 PprCmmExpr \
577 PprCore \
578 PrelInfo \
579 PrelNames \
580 PrelRules \
581 Pretty \
582 PrimOp \
583 RdrName \
584 Reg \
585 RegClass \
586 Rules \
587 SMRep \
588 Serialized \
589 SrcLoc \
590 StaticFlags \
591 StgCmmArgRep \
592 StgCmmClosure \
593 StgCmmEnv \
594 StgCmmLayout \
595 StgCmmMonad \
596 StgCmmProf \
597 StgCmmTicky \
598 StgCmmUtils \
599 StgSyn \
600 Stream \
601 StringBuffer \
602 TcEvidence \
603 TcIface \
604 TcRnMonad \
605 TcRnTypes \
606 TcType \
607 TcTypeNats \
608 TrieMap \
609 TyCon \
610 Type \
611 TypeRep \
612 TysPrim \
613 TysWiredIn \
614 Unify \
615 UniqFM \
616 UniqSet \
617 UniqSupply \
618 Unique \
619 Util \
620 Var \
621 VarEnv \
622 VarSet
623
624 compiler_stage2_dll0_HS_OBJS = \
625 $(patsubst %,compiler/stage2/build/%.$(dyn_osuf),$(subst .,/,$(compiler_stage2_dll0_MODULES)))
626
627 # if stage is set to something other than "1" or "", disable stage 1
628 ifneq "$(filter-out 1,$(stage))" ""
629 compiler_stage1_NOT_NEEDED = YES
630 endif
631 # if stage is set to something other than "2" or "", disable stage 2
632 ifneq "$(filter-out 2,$(stage))" ""
633 compiler_stage2_NOT_NEEDED = YES
634 endif
635 # stage 3 has to be requested explicitly with stage=3
636 ifneq "$(stage)" "3"
637 compiler_stage3_NOT_NEEDED = YES
638 endif
639 $(eval $(call build-package,compiler,stage1,0))
640 $(eval $(call build-package,compiler,stage2,1))
641 $(eval $(call build-package,compiler,stage3,2))
642
643 # We only want to turn keepCAFs on if we will be loading dynamic
644 # Haskell libraries with GHCi. We therefore filter the object file
645 # out for non-dynamic ways.
646 define keepCAFsForGHCiDynOnly
647 # $1 = stage
648 # $2 = way
649 ifeq "$$(findstring dyn, $1)" ""
650 compiler_stage$1_$2_C_OBJS := $$(filter-out %/keepCAFsForGHCi.o,$$(compiler_stage$1_$2_C_OBJS))
651 endif
652 endef
653 $(foreach w,$(compiler_stage1_WAYS),$(eval $(call keepCAFsForGHCiDynOnly,1,$w)))
654 $(foreach w,$(compiler_stage2_WAYS),$(eval $(call keepCAFsForGHCiDynOnly,2,$w)))
655 $(foreach w,$(compiler_stage3_WAYS),$(eval $(call keepCAFsForGHCiDynOnly,3,$w)))
656
657 # after build-package, because that adds --enable-library-for-ghci
658 # to compiler_stage*_CONFIGURE_OPTS:
659 # We don't build the GHCi library for the ghc package. We can load it
660 # the .a file instead, and as object splitting isn't on for the ghc
661 # package this isn't much slower.However, not building the package saves
662 # a significant chunk of disk space.
663 compiler_stage1_CONFIGURE_OPTS += --disable-library-for-ghci
664 compiler_stage2_CONFIGURE_OPTS += --disable-library-for-ghci
665 compiler_stage3_CONFIGURE_OPTS += --disable-library-for-ghci
666
667 # after build-package, because that sets compiler_stage1_HC_OPTS:
668 compiler_stage1_HC_OPTS += $(GhcHcOpts) $(GhcStage1HcOpts)
669 compiler_stage2_HC_OPTS += $(GhcHcOpts) $(GhcStage2HcOpts)
670 compiler_stage3_HC_OPTS += $(GhcHcOpts) $(GhcStage3HcOpts)
671
672 ifneq "$(BINDIST)" "YES"
673
674 compiler_stage2_TAGS_HC_OPTS = -package ghc
675 $(eval $(call tags-package,compiler,stage2))
676
677 $(compiler_stage1_depfile_haskell) : compiler/stage1/$(PLATFORM_H)
678 $(compiler_stage2_depfile_haskell) : compiler/stage2/$(PLATFORM_H)
679 $(compiler_stage3_depfile_haskell) : compiler/stage3/$(PLATFORM_H)
680
681 COMPILER_INCLUDES_DEPS += $(includes_H_CONFIG)
682 COMPILER_INCLUDES_DEPS += $(includes_H_PLATFORM)
683 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS)
684 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_TYPE)
685 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
686 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_EXPORTS)
687 COMPILER_INCLUDES_DEPS += $(includes_DERIVEDCONSTANTS)
688
689 $(compiler_stage1_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE1)
690 $(compiler_stage2_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE2)
691 $(compiler_stage3_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE3)
692
693 $(foreach way,$(compiler_stage1_WAYS),\
694 compiler/stage1/build/PrimOp.$($(way)_osuf)) : $(PRIMOP_BITS_STAGE1)
695 $(foreach way,$(compiler_stage2_WAYS),\
696 compiler/stage2/build/PrimOp.$($(way)_osuf)) : $(PRIMOP_BITS_STAGE2)
697 $(foreach way,$(compiler_stage3_WAYS),\
698 compiler/stage3/build/PrimOp.$($(way)_osuf)) : $(PRIMOP_BITS_STAGE3)
699
700
701 # GHC itself doesn't know about the above dependencies, so we have to
702 # switch off the recompilation checker for that module:
703 compiler/prelude/PrimOp_HC_OPTS += -fforce-recomp
704
705 ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
706 compiler/utils/Util_HC_OPTS += -DDYNAMIC_GHC_PROGRAMS
707 endif
708
709 # LibFFI.hs #includes ffi.h
710 ifneq "$(UseSystemLibFFI)" "YES"
711 compiler/stage2/build/LibFFI.hs : $(libffi_HEADERS)
712 endif
713
714 # Note [munge-stage1-package-config]
715 # Strip the date/patchlevel from the version of stage1. See Note
716 # [fiddle-stage1-version] above.
717 ifeq "$(compiler_stage1_VERSION_MUNGED)" "YES"
718 compiler/stage1/inplace-pkg-config-munged: compiler/stage1/inplace-pkg-config
719 sed -e 's/^\(version: .*\)\.$(ProjectPatchLevel)$$/\1/' \
720 -e 's/^\(id: .*\)\.$(ProjectPatchLevel)$$/\1/' \
721 -e 's/^\(hs-libraries: HSghc-.*\)\.$(ProjectPatchLevel)$$/\1/' \
722 < $< > $@
723 "$(compiler_stage1_GHC_PKG)" update --force $(compiler_stage1_GHC_PKG_OPTS) $@
724
725 # We need to make sure the munged config is in the database before we
726 # try to configure ghc-bin
727 ghc/stage1/package-data.mk : compiler/stage1/inplace-pkg-config-munged
728 endif
729
730 endif
731