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