Fix lld detection if both gold and lld are found
[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 ' | IntegerSimple' >> $@
58 @echo ' deriving Eq' >> $@
59 @echo >> $@
60 @echo 'cBuildPlatformString :: String' >> $@
61 @echo 'cBuildPlatformString = BuildPlatform_NAME' >> $@
62 @echo 'cHostPlatformString :: String' >> $@
63 @echo 'cHostPlatformString = HostPlatform_NAME' >> $@
64 @echo 'cTargetPlatformString :: String' >> $@
65 @echo 'cTargetPlatformString = TargetPlatform_NAME' >> $@
66 @echo >> $@
67 @echo 'cProjectName :: String' >> $@
68 @echo 'cProjectName = "$(ProjectName)"' >> $@
69 @echo 'cProjectGitCommitId :: String' >> $@
70 @echo 'cProjectGitCommitId = "$(ProjectGitCommitId)"' >> $@
71 @echo 'cProjectVersion :: String' >> $@
72 @echo 'cProjectVersion = "$(ProjectVersion)"' >> $@
73 @echo 'cProjectVersionInt :: String' >> $@
74 @echo 'cProjectVersionInt = "$(ProjectVersionInt)"' >> $@
75 @echo 'cProjectPatchLevel :: String' >> $@
76 @echo 'cProjectPatchLevel = "$(ProjectPatchLevel)"' >> $@
77 @echo 'cProjectPatchLevel1 :: String' >> $@
78 @echo 'cProjectPatchLevel1 = "$(ProjectPatchLevel1)"' >> $@
79 @echo 'cProjectPatchLevel2 :: String' >> $@
80 @echo 'cProjectPatchLevel2 = "$(ProjectPatchLevel2)"' >> $@
81 @echo 'cBooterVersion :: String' >> $@
82 @echo 'cBooterVersion = "$(GhcVersion)"' >> $@
83 @echo 'cStage :: String' >> $@
84 @echo 'cStage = show (STAGE :: Int)' >> $@
85 @echo 'cIntegerLibrary :: String' >> $@
86 @echo 'cIntegerLibrary = "$(INTEGER_LIBRARY)"' >> $@
87 @echo 'cIntegerLibraryType :: IntegerLibrary' >> $@
88 ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
89 @echo 'cIntegerLibraryType = IntegerGMP' >> $@
90 else ifeq "$(INTEGER_LIBRARY)" "integer-simple"
91 @echo 'cIntegerLibraryType = IntegerSimple' >> $@
92 else ifneq "$(CLEANING)" "YES"
93 $(error Unknown integer library)
94 endif
95 @echo 'cSupportsSplitObjs :: String' >> $@
96 @echo 'cSupportsSplitObjs = "$(SupportsSplitObjs)"' >> $@
97 @echo 'cGhcWithInterpreter :: String' >> $@
98 @echo 'cGhcWithInterpreter = "$(GhcWithInterpreter)"' >> $@
99 @echo 'cGhcWithNativeCodeGen :: String' >> $@
100 @echo 'cGhcWithNativeCodeGen = "$(GhcWithNativeCodeGen)"' >> $@
101 @echo 'cGhcWithSMP :: String' >> $@
102 @echo 'cGhcWithSMP = "$(GhcWithSMP)"' >> $@
103 @echo 'cGhcRTSWays :: String' >> $@
104 @echo 'cGhcRTSWays = "$(GhcRTSWays)"' >> $@
105 @echo 'cGhcRtsWithLibdw :: Bool' >> $@
106 ifeq "$(GhcRtsWithLibdw)" "YES"
107 @echo 'cGhcRtsWithLibdw = True' >> $@
108 else
109 @echo 'cGhcRtsWithLibdw = False' >> $@
110 endif
111 @echo 'cGhcEnableTablesNextToCode :: String' >> $@
112 @echo 'cGhcEnableTablesNextToCode = "$(GhcEnableTablesNextToCode)"' >> $@
113 @echo 'cLeadingUnderscore :: String' >> $@
114 @echo 'cLeadingUnderscore = "$(LeadingUnderscore)"' >> $@
115 @echo 'cGHC_UNLIT_PGM :: String' >> $@
116 @echo 'cGHC_UNLIT_PGM = "$(utils/unlit_dist_PROG)"' >> $@
117 @echo 'cGHC_SPLIT_PGM :: String' >> $@
118 @echo 'cGHC_SPLIT_PGM = "$(driver/split_dist_PROG)"' >> $@
119 @echo 'cLibFFI :: Bool' >> $@
120 ifeq "$(UseLibFFIForAdjustors)" "YES"
121 @echo 'cLibFFI = True' >> $@
122 else
123 @echo 'cLibFFI = False' >> $@
124 endif
125 # Note that GhcThreaded just reflects the Makefile variable setting.
126 # In particular, the stage1 compiler is never actually compiled with
127 # -threaded, but it will nevertheless have cGhcThreaded = True.
128 # The "+RTS --info" output will show what RTS GHC is really using.
129 @echo 'cGhcThreaded :: Bool' >> $@
130 ifeq "$(GhcThreaded)" "YES"
131 @echo 'cGhcThreaded = True' >> $@
132 else
133 @echo 'cGhcThreaded = False' >> $@
134 endif
135 @echo 'cGhcDebugged :: Bool' >> $@
136 ifeq "$(GhcDebugged)" "YES"
137 @echo 'cGhcDebugged = True' >> $@
138 else
139 @echo 'cGhcDebugged = False' >> $@
140 endif
141 @echo done.
142
143 # -----------------------------------------------------------------------------
144 # Create platform includes
145
146 # Here we generate a little header file containing CPP symbols that GHC
147 # uses to determine which platform it is building on/for. The platforms
148 # can differ between stage1 and stage2 if we're cross-compiling, so we
149 # need one of these header files per stage.
150
151 PLATFORM_H = ghc_boot_platform.h
152
153 compiler/stage1/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
154 $(call removeFiles,$@)
155 @echo "Creating $@..."
156 @echo "#ifndef __PLATFORM_H__" >> $@
157 @echo "#define __PLATFORM_H__" >> $@
158 @echo >> $@
159 @echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
160 @echo "#define HostPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
161 @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
162 @echo >> $@
163 @echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
164 @echo "#define $(HostPlatform_CPP)_HOST 1" >> $@
165 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
166 @echo >> $@
167 @echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
168 @echo "#define $(HostArch_CPP)_HOST_ARCH 1" >> $@
169 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
170 @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
171 @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
172 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
173 @echo "#define LLVM_TARGET \"$(LLVMTarget_CPP)\"" >> $@
174 @echo >> $@
175 @echo "#define $(BuildOS_CPP)_BUILD_OS 1" >> $@
176 @echo "#define $(HostOS_CPP)_HOST_OS 1" >> $@
177 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
178 @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
179 @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
180 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
181 @echo >> $@
182 @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
183 @echo "#define $(HostVendor_CPP)_HOST_VENDOR 1" >> $@
184 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
185 @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
186 @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
187 @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
188 @echo >> $@
189 @echo "#endif /* __PLATFORM_H__ */" >> $@
190 @echo "Done."
191
192 # For stage2 and above, the BUILD platform is the HOST of stage1, and
193 # the HOST platform is the TARGET of stage1. The TARGET remains the same
194 # (stage1 is the cross-compiler, not stage2).
195 compiler/stage2/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
196 $(call removeFiles,$@)
197 @echo "Creating $@..."
198 @echo "#ifndef __PLATFORM_H__" >> $@
199 @echo "#define __PLATFORM_H__" >> $@
200 @echo >> $@
201 @echo "#define BuildPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
202 @echo "#define HostPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
203 @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
204 @echo >> $@
205 @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
206 @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
207 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
208 @echo >> $@
209 @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
210 @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
211 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
212 @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
213 @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
214 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
215 @echo "#define LLVM_TARGET \"$(LLVMTarget_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 @echo >> $@
224 @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
225 @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
226 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
227 @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
228 @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
229 @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
230 @echo >> $@
231 @echo "#endif /* __PLATFORM_H__ */" >> $@
232 @echo "Done."
233
234 compiler/stage3/$(PLATFORM_H) : compiler/stage2/$(PLATFORM_H)
235 "$(CP)" $< $@
236
237 # ----------------------------------------------------------------------------
238 # Generate supporting stuff for prelude/PrimOp.hs
239 # from prelude/primops.txt
240
241 PRIMOP_BITS_NAMES = primop-data-decl.hs-incl \
242 primop-tag.hs-incl \
243 primop-list.hs-incl \
244 primop-has-side-effects.hs-incl \
245 primop-out-of-line.hs-incl \
246 primop-commutable.hs-incl \
247 primop-code-size.hs-incl \
248 primop-can-fail.hs-incl \
249 primop-strictness.hs-incl \
250 primop-fixity.hs-incl \
251 primop-primop-info.hs-incl \
252 primop-vector-uniques.hs-incl \
253 primop-vector-tys.hs-incl \
254 primop-vector-tys-exports.hs-incl \
255 primop-vector-tycons.hs-incl
256
257 PRIMOP_BITS_STAGE1 = $(addprefix compiler/stage1/build/,$(PRIMOP_BITS_NAMES))
258 PRIMOP_BITS_STAGE2 = $(addprefix compiler/stage2/build/,$(PRIMOP_BITS_NAMES))
259 PRIMOP_BITS_STAGE3 = $(addprefix compiler/stage3/build/,$(PRIMOP_BITS_NAMES))
260
261 compiler_CPP_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
262 compiler_CPP_OPTS += ${GhcCppOpts}
263
264 # We add these paths to the Haskell compiler's #include search path list since
265 # we must avoid #including files by paths relative to the source file as Hadrian
266 # moves the build artifacts out of the source tree. See #8040.
267 compiler_HC_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
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 ifeq "$(WITH_TERMINFO)" "NO"
367 compiler_stage2_CONFIGURE_OPTS += --flags=-terminfo
368 endif
369
370 # Careful optimisation of the parser: we don't want to throw everything
371 # at it, because that takes too long and doesn't buy much, but we do want
372 # to inline certain key external functions, so we instruct GHC not to
373 # throw away inlinings as it would normally do in -O0 mode.
374 # Since GHC version 7.8, we need -fcmm-sink to be
375 # passed to the compiler. This is required on x86 to avoid the
376 # register allocator running out of stack slots when compiling this
377 # module with -fPIC -dynamic.
378 # See #8182 for all the details
379 compiler/stage1/build/Parser_HC_OPTS += -O0 -fno-ignore-interface-pragmas -fcmm-sink
380 compiler/stage2/build/Parser_HC_OPTS += -O0 -fno-ignore-interface-pragmas -fcmm-sink
381 compiler/stage3/build/Parser_HC_OPTS += -O0 -fno-ignore-interface-pragmas -fcmm-sink
382
383 ifeq "$(GhcProfiled)" "YES"
384 # If we're profiling GHC then we want SCCs. However, adding -auto-all
385 # everywhere tends to give a hard-to-read profile, and adds lots of
386 # overhead. A better approach is to proceed top-down; identify the
387 # parts of the compiler of interest, and then add further cost centres
388 # as necessary. Turn on -fprof-auto for individual modules like this:
389
390 # compiler/main/DriverPipeline_HC_OPTS += -fprof-auto
391 compiler/main/GhcMake_HC_OPTS += -fprof-auto
392 compiler/main/GHC_HC_OPTS += -fprof-auto
393
394 # or alternatively add {-# OPTIONS_GHC -fprof-auto #-} to the top of
395 # modules you're interested in.
396
397 # We seem to still build the vanilla libraries even if we say
398 # --disable-library-vanilla, but installation then fails, as Cabal
399 # doesn't copy the vanilla .hi files, but ghc-pkg complains about
400 # their absence when we register the package. So for now, we just
401 # leave the vanilla libraries enabled.
402 # compiler_stage2_CONFIGURE_OPTS += --disable-library-vanilla
403 compiler_stage2_CONFIGURE_OPTS += --ghc-pkg-option=--force
404 endif
405
406 compiler_stage3_CONFIGURE_OPTS := $(compiler_stage2_CONFIGURE_OPTS)
407
408 compiler_stage1_CONFIGURE_OPTS += --ghc-option=-DSTAGE=1
409 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DSTAGE=2
410 compiler_stage3_CONFIGURE_OPTS += --ghc-option=-DSTAGE=3
411 compiler_stage2_HADDOCK_OPTS += --optghc=-DSTAGE=2
412
413 compiler/stage1/package-data.mk : compiler/ghc.mk
414 compiler/stage2/package-data.mk : compiler/ghc.mk
415 compiler/stage3/package-data.mk : compiler/ghc.mk
416
417 # -----------------------------------------------------------------------------
418 # And build the package
419
420 compiler_PACKAGE = ghc
421
422 # Don't do splitting for the GHC package, it takes too long and
423 # there's not much benefit.
424 compiler_stage1_SplitObjs = NO
425 compiler_stage2_SplitObjs = NO
426 compiler_stage3_SplitObjs = NO
427 compiler_stage1_SplitSections = NO
428 compiler_stage2_SplitSections = NO
429 compiler_stage3_SplitSections = NO
430
431 # There are too many symbols in the ghc package for a Windows DLL
432 # (due to a limitation of bfd ld, see Trac #5987). We therefore need to split
433 # some of the modules off into a separate DLL. This clump are the modules
434 # reachable from DynFlags:
435 compiler_stage2_dll0_START_MODULE = DynFlags
436 compiler_stage2_dll0_MODULES = \
437 Annotations \
438 ApiAnnotation \
439 Avail \
440 Bag \
441 BasicTypes \
442 Binary \
443 BinFingerprint \
444 BooleanFormula \
445 BufWrite \
446 ByteCodeTypes \
447 Class \
448 CmdLineParser \
449 CmmType \
450 CoAxiom \
451 ConLike \
452 Coercion \
453 Config \
454 Constants \
455 CoreArity \
456 CoreFVs \
457 CoreSubst \
458 CoreOpt \
459 CoreSyn \
460 CoreTidy \
461 CoreUnfold \
462 CoreUtils \
463 CoreSeq \
464 CoreStats \
465 CostCentre \
466 DataCon \
467 Demand \
468 Digraph \
469 DriverPhases \
470 DynFlags \
471 Encoding \
472 EnumSet \
473 ErrUtils \
474 Exception \
475 FamInstEnv \
476 FastFunctions \
477 FastMutInt \
478 FastString \
479 FastStringEnv \
480 FieldLabel \
481 FileCleanup \
482 Fingerprint \
483 FiniteMap \
484 ForeignCall \
485 FV \
486 Hooks \
487 HsBinds \
488 HsDecls \
489 HsDoc \
490 HsExpr \
491 HsImpExp \
492 HsLit \
493 PlaceHolder \
494 HsExtension \
495 PmExpr \
496 HsPat \
497 HsSyn \
498 HsTypes \
499 HsUtils \
500 HscTypes \
501 IOEnv \
502 NameCache \
503 Id \
504 IdInfo \
505 IfaceSyn \
506 IfaceType \
507 InteractiveEvalTypes \
508 Json \
509 ToIface \
510 InstEnv \
511 Kind \
512 KnownUniques \
513 Lexeme \
514 ListSetOps \
515 Literal \
516 Maybes \
517 MkCore \
518 MkId \
519 Module \
520 MonadUtils \
521 Name \
522 NameEnv \
523 NameSet \
524 OccName \
525 OccurAnal \
526 OptCoercion \
527 OrdList \
528 Outputable \
529 PackageConfig \
530 Packages \
531 Pair \
532 Panic \
533 PatSyn \
534 PipelineMonad \
535 Platform \
536 PlatformConstants \
537 PprColour \
538 PprCore \
539 PrelNames \
540 PrelRules \
541 Pretty \
542 PrimOp \
543 RepType \
544 RdrName \
545 Rules \
546 SrcLoc \
547 StringBuffer \
548 SysTools.Terminal \
549 TcEvidence \
550 TcRnTypes \
551 TcType \
552 TrieMap \
553 TyCon \
554 Type \
555 TyCoRep \
556 TysPrim \
557 TysWiredIn \
558 Unify \
559 UniqDFM \
560 UniqDSet \
561 UniqFM \
562 UniqSet \
563 UniqSupply \
564 Unique \
565 Util \
566 Var \
567 VarEnv \
568 VarSet
569
570 ifeq "$(GhcWithInterpreter)" "YES"
571 # These files are reacheable from DynFlags
572 # only by GHCi-enabled code (see #9552)
573 compiler_stage2_dll0_MODULES += # none
574 endif
575
576 compiler_stage2_dll0_HS_OBJS = \
577 $(patsubst %,compiler/stage2/build/%.$(dyn_osuf),$(subst .,/,$(compiler_stage2_dll0_MODULES)))
578
579 # if stage is set to something other than "1" or "", disable stage 1
580 # See Note [Stage1Only vs stage=1] in mk/config.mk.in.
581 ifneq "$(filter-out 1,$(stage))" ""
582 compiler_stage1_NOT_NEEDED = YES
583 endif
584 # if stage is set to something other than "2" or "", disable stage 2
585 ifneq "$(filter-out 2,$(stage))" ""
586 compiler_stage2_NOT_NEEDED = YES
587 endif
588 # stage 3 has to be requested explicitly with stage=3
589 ifneq "$(stage)" "3"
590 compiler_stage3_NOT_NEEDED = YES
591 endif
592 $(eval $(call build-package,compiler,stage1,0))
593 $(eval $(call build-package,compiler,stage2,1))
594 $(eval $(call build-package,compiler,stage3,2))
595
596 # We only want to turn keepCAFs on if we will be loading dynamic
597 # Haskell libraries with GHCi. We therefore filter the object file
598 # out for non-dynamic ways.
599 define keepCAFsForGHCiDynOnly
600 # $1 = stage
601 # $2 = way
602 ifeq "$$(findstring dyn, $2)" ""
603 compiler_stage$1_$2_C_OBJS := $$(filter-out %/keepCAFsForGHCi.$$($2_osuf),$$(compiler_stage$1_$2_C_OBJS))
604 endif
605 endef
606 $(foreach w,$(compiler_stage1_WAYS),$(eval $(call keepCAFsForGHCiDynOnly,1,$w)))
607 $(foreach w,$(compiler_stage2_WAYS),$(eval $(call keepCAFsForGHCiDynOnly,2,$w)))
608 $(foreach w,$(compiler_stage3_WAYS),$(eval $(call keepCAFsForGHCiDynOnly,3,$w)))
609
610 # after build-package, because that adds --enable-library-for-ghci
611 # to compiler_stage*_CONFIGURE_OPTS:
612 # We don't build the GHCi library for the ghc package. We can load it
613 # the .a file instead, and as object splitting isn't on for the ghc
614 # package this isn't much slower.However, not building the package saves
615 # a significant chunk of disk space.
616 compiler_stage1_CONFIGURE_OPTS += --disable-library-for-ghci
617 compiler_stage2_CONFIGURE_OPTS += --disable-library-for-ghci
618 compiler_stage3_CONFIGURE_OPTS += --disable-library-for-ghci
619
620 # after build-package, because that sets compiler_stage1_HC_OPTS:
621 ifeq "$(V)" "0"
622 compiler_stage1_HC_OPTS += $(filter-out -Rghc-timing,$(GhcHcOpts)) $(GhcStage1HcOpts)
623 compiler_stage2_HC_OPTS += $(filter-out -Rghc-timing,$(GhcHcOpts)) $(GhcStage2HcOpts)
624 compiler_stage3_HC_OPTS += $(filter-out -Rghc-timing,$(GhcHcOpts)) $(GhcStage3HcOpts)
625 else
626 compiler_stage1_HC_OPTS += $(GhcHcOpts) $(GhcStage1HcOpts)
627 compiler_stage2_HC_OPTS += $(GhcHcOpts) $(GhcStage2HcOpts)
628 compiler_stage3_HC_OPTS += $(GhcHcOpts) $(GhcStage3HcOpts)
629 endif
630
631 ifneq "$(BINDIST)" "YES"
632
633 compiler_stage2_TAGS_HC_OPTS = -package ghc
634 $(eval $(call tags-package,compiler,stage2))
635
636 $(compiler_stage1_depfile_haskell) : compiler/stage1/$(PLATFORM_H)
637 $(compiler_stage2_depfile_haskell) : compiler/stage2/$(PLATFORM_H)
638 $(compiler_stage3_depfile_haskell) : compiler/stage3/$(PLATFORM_H)
639
640 COMPILER_INCLUDES_DEPS += $(includes_H_CONFIG)
641 COMPILER_INCLUDES_DEPS += $(includes_H_PLATFORM)
642 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS)
643 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_TYPE)
644 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
645 COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_EXPORTS)
646 COMPILER_INCLUDES_DEPS += $(includes_DERIVEDCONSTANTS)
647
648 $(compiler_stage1_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE1)
649 $(compiler_stage2_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE2)
650 $(compiler_stage3_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE3)
651
652 $(foreach way,$(compiler_stage1_WAYS),\
653 compiler/stage1/build/PrimOp.$($(way)_osuf)) : $(PRIMOP_BITS_STAGE1)
654 $(foreach way,$(compiler_stage2_WAYS),\
655 compiler/stage2/build/PrimOp.$($(way)_osuf)) : $(PRIMOP_BITS_STAGE2)
656 $(foreach way,$(compiler_stage3_WAYS),\
657 compiler/stage3/build/PrimOp.$($(way)_osuf)) : $(PRIMOP_BITS_STAGE3)
658
659
660 # GHC itself doesn't know about the above dependencies, so we have to
661 # switch off the recompilation checker for that module:
662 compiler/prelude/PrimOp_HC_OPTS += -fforce-recomp
663
664 ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
665 compiler/utils/Util_HC_OPTS += -DDYNAMIC_GHC_PROGRAMS
666 endif
667
668 endif