hadrian: eliminate most of the remaining big rule enumerations
[ghc.git] / rts / ghc.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009 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 # Building the RTS
15
16 # We build the RTS with stage 1
17 rts_dist_HC = $(GHC_STAGE1)
18
19 rts_INSTALL_INFO = rts
20 rts_VERSION = 1.0
21
22 # Minimum supported Windows version.
23 # These numbers can be found at:
24 # https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx
25 # If we're compiling on windows, enforce that we only support Vista SP1+
26 # Adding this here means it doesn't have to be done in individual .c files
27 # and also centralizes the versioning.
28 rts_WINVER = 0x06000100
29
30 # merge GhcLibWays and GhcRTSWays but strip out duplicates
31 rts_WAYS = $(GhcLibWays) $(filter-out $(GhcLibWays),$(GhcRTSWays))
32 rts_dist_WAYS = $(rts_WAYS)
33
34 ALL_RTS_LIBS = $(foreach way,$(rts_WAYS),rts/dist/build/libHSrts$($(way)_libsuf))
35 $(eval $(call all-target,rts,$(ALL_RTS_LIBS)))
36
37 # -----------------------------------------------------------------------------
38 # Defining the sources
39
40 ALL_DIRS = hooks sm eventlog linker
41
42 ifeq "$(TargetOS_CPP)" "mingw32"
43 ALL_DIRS += win32
44 else
45 ALL_DIRS += posix
46 endif
47
48 rts_C_SRCS := $(wildcard rts/*.c $(foreach dir,$(ALL_DIRS),rts/$(dir)/*.c))
49 rts_C_HOOK_SRCS := $(wildcard rts/hooks/*.c)
50 rts_CMM_SRCS := $(wildcard rts/*.cmm)
51
52 # Don't compile .S files when bootstrapping a new arch
53 ifneq "$(PORTING_HOST)" "YES"
54 ifneq "$(findstring $(TargetArch_CPP), i386 powerpc powerpc64)" ""
55 rts_S_SRCS += rts/AdjustorAsm.S
56 endif
57 # this matches substrings of powerpc64le, including "powerpc" and "powerpc64"
58 ifneq "$(findstring $(TargetArch_CPP), powerpc64le)" ""
59 # unregisterised builds use the mini interpreter
60 ifneq "$(GhcUnregisterised)" "YES"
61 rts_S_SRCS += rts/StgCRunAsm.S
62 endif
63 endif
64 endif
65
66 ifeq "$(GhcUnregisterised)" "YES"
67 GENAPPLY_OPTS = -u
68 endif
69
70 rts_AUTO_APPLY_CMM = rts/dist/build/AutoApply.cmm
71
72 $(rts_AUTO_APPLY_CMM): $$(genapply_INPLACE)
73 "$(genapply_INPLACE)" >$@
74
75
76 rts_H_FILES := $(wildcard rts/*.h rts/*/*.h)
77
78 ifeq "$(USE_DTRACE)" "YES"
79 DTRACEPROBES_H = rts/dist/build/RtsProbes.h
80 rts_H_FILES += $(DTRACEPROBES_H)
81 endif
82
83 # collect the -l and -L flags that we need to link the rts dyn lib.
84 # Note that, as sed on OS X doesn't handle \+, we use [^ ][^ ]* rather
85 # than [^ ]\+
86 rts/dist/libs.depend : $$(ghc-pkg_INPLACE) | $$(dir $$@)/.
87 "$(ghc-pkg_INPLACE)" --simple-output field rts extra-libraries \
88 | sed -e 's/\([^ ][^ ]*\)/-l\1/g' > $@
89 "$(ghc-pkg_INPLACE)" --simple-output field rts library-dirs \
90 | sed -e 's/\([^ ][^ ]*\)/-L\1/g' >> $@
91
92
93 # ----------------------------------------------------------------------------
94 # On Windows, as the RTS and base libraries have recursive imports,
95 # we have to break the loop with "import libraries".
96 # These are made from rts/win32/libHS*.def which contain lists of
97 # all the symbols in those libraries used by the RTS.
98 #
99 ifeq "$(TargetOS_CPP)" "mingw32"
100
101 ALL_RTS_DEF_LIBNAMES = base ghc-prim
102 ALL_RTS_DEF_LIBS = \
103 rts/dist/build/win32/libHSbase.dll.a \
104 rts/dist/build/win32/libHSghc-prim.dll.a
105
106 # -- import libs for the regular Haskell libraries
107 define make-importlib-def # args $1 = lib name
108 rts/dist/build/win32/libHS$1.def : rts/win32/libHS$1.def
109 cat rts/win32/libHS$1.def \
110 | sed "s/@LibVersion@/$$(libraries/$1_dist-install_VERSION)/" \
111 | sed "s/@ProjectVersion@/$$(ProjectVersion)/" \
112 > rts/dist/build/win32/libHS$1.def
113
114 rts/dist/build/win32/libHS$1.dll.a : rts/dist/build/win32/libHS$1.def
115 "$$(DLLTOOL)" -d rts/dist/build/win32/libHS$1.def \
116 -l rts/dist/build/win32/libHS$1.dll.a
117 endef
118 $(foreach lib,$(ALL_RTS_DEF_LIBNAMES),$(eval $(call make-importlib-def,$(lib))))
119 endif
120
121 ifneq "$(BINDIST)" "YES"
122 ifneq "$(UseSystemLibFFI)" "YES"
123 ifeq "$(TargetOS_CPP)" "mingw32"
124 rts/dist/build/$(LIBFFI_DLL): libffi/build/inst/bin/$(LIBFFI_DLL)
125 cp $< $@
126 else
127 # This is a little hacky. We don't know the SO version, so we only
128 # depend on libffi.so, but copy libffi.so*
129 rts/dist/build/lib$(LIBFFI_NAME)$(soext): libffi/build/inst/lib/lib$(LIBFFI_NAME)$(soext)
130 cp libffi/build/inst/lib/lib$(LIBFFI_NAME)$(soext)* rts/dist/build
131 ifeq "$(TargetOS_CPP)" "darwin"
132 install_name_tool -id @rpath/lib$(LIBFFI_NAME)$(soext) rts/dist/build/lib$(LIBFFI_NAME)$(soext)
133 endif
134 endif
135 endif
136 endif
137
138
139 ifeq "$(USE_DTRACE)" "YES"
140 ifneq "$(findstring $(TargetOS_CPP), linux solaris2 freebsd)" ""
141 NEED_DTRACE_PROBES_OBJ = YES
142 endif
143 endif
144
145 #-----------------------------------------------------------------------------
146 # Building one way
147 define build-rts-way # args: $1 = way
148
149 ifneq "$$(BINDIST)" "YES"
150
151 rts_dist_$1_HC_OPTS := $$(GhcRtsHcOpts)
152 rts_dist_$1_CC_OPTS := $$(GhcRtsCcOpts)
153
154 # The per-way CC_OPTS
155 ifneq "$$(findstring debug, $1)" ""
156 rts_dist_$1_HC_OPTS += -O0
157 rts_dist_$1_CC_OPTS += -fno-omit-frame-pointer -O0 -g3
158 # Useful to ensure that inline functions can be called within GDB but not
159 # supported by clang
160 #rts_dist_$1_CC_OPTS += -fkeep-inline-functions
161 endif
162
163 ifneq "$$(findstring dyn, $1)" ""
164 ifeq "$$(TargetOS_CPP)" "mingw32"
165 rts_dist_$1_CC_OPTS += -DCOMPILING_WINDOWS_DLL
166 endif
167 rts_dist_$1_CC_OPTS += -DDYNAMIC
168 endif
169
170
171 $(call distdir-way-opts,rts,dist,$1,1) # 1 because the rts is built with stage1
172 $(call c-suffix-rules,rts,dist,$1,YES)
173 $(call cmm-suffix-rules,rts,dist,$1)
174
175 rts_$1_LIB_FILE = libHSrts$$($1_libsuf)
176 rts_$1_LIB = rts/dist/build/$$(rts_$1_LIB_FILE)
177
178 rts_$1_C_OBJS = $$(patsubst rts/%.c,rts/dist/build/%.$$($1_osuf),$$(rts_C_SRCS)) $$(patsubst %.c,%.$$($1_osuf),$$(rts_$1_EXTRA_C_SRCS))
179 rts_$1_C_HOOK_OBJS = $$(patsubst rts/hooks/%.c,rts/dist/build/hooks/%.$$($1_osuf),$$(rts_C_HOOK_SRCS))
180 rts_$1_S_OBJS = $$(patsubst rts/%.S,rts/dist/build/%.$$($1_osuf),$$(rts_S_SRCS))
181 rts_$1_CMM_OBJS = $$(patsubst rts/%.cmm,rts/dist/build/%.$$($1_osuf),$$(rts_CMM_SRCS)) $$(patsubst %.cmm,%.$$($1_osuf),$$(rts_AUTO_APPLY_CMM))
182
183 rts_$1_OBJS = $$(rts_$1_C_OBJS) $$(rts_$1_S_OBJS) $$(rts_$1_CMM_OBJS)
184
185 ifeq "$(USE_DTRACE)" "YES"
186 ifeq "$(NEED_DTRACE_PROBES_OBJ)" "YES"
187 # On Darwin we don't need to generate binary containing probes defined
188 # in DTrace script, but DTrace on Solaris expects generation of binary
189 # from the DTrace probes definitions
190 rts_$1_DTRACE_OBJS = rts/dist/build/RtsProbes.$$($1_osuf)
191
192 $$(rts_$1_DTRACE_OBJS) : $$(rts_$1_OBJS)
193 $(DTRACE) -G -C $$(addprefix -I,$$(GHC_INCLUDE_DIRS)) -DDTRACE -s rts/RtsProbes.d -o \
194 $$@ $$(rts_$1_OBJS)
195 endif
196 endif
197
198 rts_dist_$1_CC_OPTS += -DRtsWay=\"rts_$1\"
199
200 # If we're compiling on windows, enforce that we only support XP+
201 # Adding this here means it doesn't have to be done in individual .c files
202 # and also centralizes the versioning.
203 ifeq "$$(TargetOS_CPP)" "mingw32"
204 rts_dist_$1_CC_OPTS += -DWINVER=$(rts_WINVER)
205 endif
206
207 ifneq "$$(UseSystemLibFFI)" "YES"
208 rts_dist_FFI_SO = rts/dist/build/lib$$(LIBFFI_NAME)$$(soext)
209 else
210 rts_dist_FFI_SO =
211 endif
212
213 # Making a shared library for the RTS.
214 ifneq "$$(findstring dyn, $1)" ""
215 ifeq "$$(TargetOS_CPP)" "mingw32"
216 $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/dist/libs.depend rts/dist/build/$$(LIBFFI_DLL)
217 "$$(RM)" $$(RM_OPTS) $$@
218 # Call out to the shell script to decide how to build the dll.
219 # Making a shared library for the RTS.
220 # $$1 = dir
221 # $$2 = distdir
222 # $$3 = way
223 # $$4 = extra flags
224 # $$5 = extra libraries to link
225 # $$6 = object files to link
226 # $$7 = output filename
227 # $$8 = link command
228 # $$9 = create delay load import lib
229 # $$10 = SxS Name
230 # $$11 = SxS Version
231 $$(gen-dll_INPLACE) link "rts/dist/build" "rts/dist/build" "" "" "$$(ALL_RTS_DEF_LIBS)" "$$(rts_$1_OBJS)" "$$@" "$$(rts_dist_HC) -this-unit-id rts -no-hs-main -shared -dynamic -dynload deploy \
232 -no-auto-link-packages -Lrts/dist/build -l$$(LIBFFI_NAME) \
233 `cat rts/dist/libs.depend | tr '\n' ' '` \
234 $$(rts_dist_$1_GHC_LD_OPTS)" "NO" \
235 "$(rts_INSTALL_INFO)-$(subst dyn,,$(subst _dyn,,$(subst v,,$1)))" "$(ProjectVersion)"
236
237 else
238 ifneq "$$(UseSystemLibFFI)" "YES"
239 LIBFFI_LIBS = -Lrts/dist/build -l$$(LIBFFI_NAME)
240 ifeq "$$(TargetElf)" "YES"
241 LIBFFI_LIBS += -optl-Wl,-rpath -optl-Wl,'$$$$ORIGIN' -optl-Wl,-zorigin
242 endif
243 ifeq "$(TargetOS_CPP)" "darwin"
244 LIBFFI_LIBS += -optl-Wl,-rpath -optl-Wl,@loader_path
245 endif
246
247 else
248 # flags will be taken care of in rts/dist/libs.depend
249 LIBFFI_LIBS =
250 endif
251 $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/dist/libs.depend $$(rts_dist_FFI_SO)
252 "$$(RM)" $$(RM_OPTS) $$@
253 "$$(rts_dist_HC)" -this-unit-id rts -shared -dynamic -dynload deploy \
254 -no-auto-link-packages $$(LIBFFI_LIBS) `cat rts/dist/libs.depend` $$(rts_$1_OBJS) \
255 $$(rts_dist_$1_GHC_LD_OPTS) \
256 $$(rts_$1_DTRACE_OBJS) -o $$@
257 endif
258 else
259
260 ifeq "$(USE_DTRACE)" "YES"
261 ifeq "$(NEED_DTRACE_PROBES_OBJ)" "YES"
262 # A list of objects that do not get included in the RTS object that is created
263 # during the linking step. To prevent future linking errors, especially when
264 # using the compiler as a bootstrap compiler, we need to exclude the hook
265 # objects from being re-linked into the single LINKED_OBJS object file. When the
266 # hooks are being linked into the RTS object this will result in duplicated
267 # symbols causing the linker to fail (e.g. `StackOverflowHook` in RTS.o and
268 # hschooks.o). The excluded objects do not get relinked into the RTS object but
269 # get included separately so prevent linker errors.
270 # (see issue #15040)
271 rts_$1_EXCLUDED_OBJS = $$(rts_$1_C_HOOK_OBJS)
272 # The RTS object that gets generated to package up all of the runtime system
273 # with the dtrace probe code.
274 rts_$1_LINKED_OBJS = rts/dist/build/RTS.$$($1_osuf)
275
276 $$(rts_$1_LINKED_OBJS) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) $$(rts_$1_C_HOOK_OBJS)
277 "$$(RM)" $$(RM_OPTS) $$@
278
279 # When linking an archive the linker will only include the object files that
280 # are actually needed during linking. It therefore does not include the dtrace
281 # specific code for initializing the probes. By creating a single object that
282 # also includes the probe object code we force the linker to include the
283 # probes when linking the static runtime.
284 #
285 # The reason why we are re-linking all the objects into a single object file
286 # is stated in this thread:
287 # https://thr3ads.net/dtrace-discuss/2005/08/384778-Problem-with-probes-defined-in-static-libraries
288 $(LD) -r -o $$(rts_$1_LINKED_OBJS) $$(rts_$1_DTRACE_OBJS) $$(filter-out $$(rts_$1_EXCLUDED_OBJS), $$(rts_$1_OBJS))
289 else
290 rts_$1_EXCLUDED_OBJS =
291 rts_$1_LINKED_OBJS = $$(rts_$1_OBJS)
292 endif
293 else
294 rts_$1_EXCLUDED_OBJS =
295 rts_$1_LINKED_OBJS = $$(rts_$1_OBJS)
296 endif
297
298
299 $$(rts_$1_LIB) : $$(rts_$1_LINKED_OBJS)
300 "$$(RM)" $$(RM_OPTS) $$@
301
302 echo $$(rts_$1_LINKED_OBJS) $$(rts_$1_EXCLUDED_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR_STAGE1)" \
303 $$(AR_OPTS_STAGE1) $$(EXTRA_AR_ARGS_STAGE1) $$@
304
305 ifneq "$$(UseSystemLibFFI)" "YES"
306 $$(rts_$1_LIB) : rts/dist/build/libC$$(LIBFFI_NAME)$$($1_libsuf)
307 rts/dist/build/libC$$(LIBFFI_NAME)$$($1_libsuf): libffi/build/inst/lib/libffi.a
308 cp $$< $$@
309 endif
310
311 endif
312
313 endif
314
315 endef
316
317 # And expand the above for each way:
318 $(foreach way,$(rts_WAYS),$(eval $(call build-rts-way,$(way))))
319
320 $(eval $(call distdir-opts,rts,dist,1))
321
322 #-----------------------------------------------------------------------------
323 # Flags for compiling every file
324
325 # We like plenty of warnings.
326 WARNING_OPTS += -Wall
327 WARNING_OPTS += -Wextra
328 WARNING_OPTS += -Wstrict-prototypes
329 WARNING_OPTS += -Wmissing-prototypes
330 WARNING_OPTS += -Wmissing-declarations
331 WARNING_OPTS += -Winline
332 WARNING_OPTS += -Wpointer-arith
333 WARNING_OPTS += -Wmissing-noreturn
334 WARNING_OPTS += -Wnested-externs
335 WARNING_OPTS += -Wredundant-decls
336 ifeq "$(GccLT46)" "NO"
337 WARNING_OPTS += -Wundef
338 endif
339
340 # These ones are hard to avoid:
341 #WARNING_OPTS += -Wconversion
342 #WARNING_OPTS += -Wbad-function-cast
343 #WARNING_OPTS += -Wshadow
344 #WARNING_OPTS += -Wcast-qual
345
346 # This one seems buggy on GCC 4.1.2, which is the only GCC version we
347 # have that can bootstrap the SPARC build. We end up with lots of supurious
348 # warnings of the form "cast increases required alignment of target type".
349 # Some legitimate warnings can be fixed by adding an intermediate cast to
350 # (void*), but we get others in rts/sm/GCUtils.c concerning the gct var
351 # that look innocuous to me. We could enable this again once we deprecate
352 # support for registerised builds on this arch. -- BL 2010/02/03
353 # WARNING_OPTS += -Wcast-align
354
355 STANDARD_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS)) -Irts -Irts/dist/build
356 # COMPILING_RTS is only used when building Win32 DLL support.
357 STANDARD_OPTS += -DCOMPILING_RTS -DFS_NAMESPACE=rts
358
359 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
360 # only included in .c compilations. HC_OPTS included the WAY_* opts, which
361 # must be included in both types of compilations.
362
363 rts_CC_OPTS += $(WARNING_OPTS)
364 rts_CC_OPTS += $(STANDARD_OPTS)
365
366 rts_HC_OPTS += $(STANDARD_OPTS) -this-unit-id rts
367
368 ifneq "$(GhcWithSMP)" "YES"
369 rts_CC_OPTS += -DNOSMP
370 rts_HC_OPTS += -optc-DNOSMP
371 endif
372
373 ifeq "$(UseLibFFIForAdjustors)" "YES"
374 rts_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
375 endif
376
377 # We *want* type-checking of hand-written cmm.
378 rts_HC_OPTS += -dcmm-lint
379
380 # -fno-strict-aliasing is required for the runtime, because we often
381 # use a variety of types to represent closure pointers (StgPtr,
382 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
383 # allowed to assume that these pointers do not alias. eg. without
384 # this flag we get problems in sm/Evac.c:copy() with gcc 3.4.3, the
385 # upd_evacuee() assignments get moved before the object copy.
386 rts_CC_OPTS += -fno-strict-aliasing
387
388 rts_CC_OPTS += -fno-common
389
390 ifeq "$(BeConservative)" "YES"
391 rts_CC_OPTS += -DBE_CONSERVATIVE
392 endif
393
394 # Set Windows version
395 ifeq "$$(TargetOS_CPP)" "mingw32"
396 rts_CC_OPTS += -DWINVER=$(rts_WINVER)
397 endif
398
399 #-----------------------------------------------------------------------------
400 # Flags for compiling specific files
401 rts/RtsMessages_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
402 rts/RtsUtils_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
403 rts/Trace_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
404 #
405 rts/RtsUtils_CC_OPTS += -DHostPlatform=\"$(HOSTPLATFORM)\"
406 rts/RtsUtils_CC_OPTS += -DHostArch=\"$(HostArch_CPP)\"
407 rts/RtsUtils_CC_OPTS += -DHostOS=\"$(HostOS_CPP)\"
408 rts/RtsUtils_CC_OPTS += -DHostVendor=\"$(HostVendor_CPP)\"
409 #
410 rts/RtsUtils_CC_OPTS += -DBuildPlatform=\"$(BUILDPLATFORM)\"
411 rts/RtsUtils_CC_OPTS += -DBuildArch=\"$(BuildArch_CPP)\"
412 rts/RtsUtils_CC_OPTS += -DBuildOS=\"$(BuildOS_CPP)\"
413 rts/RtsUtils_CC_OPTS += -DBuildVendor=\"$(BuildVendor_CPP)\"
414 #
415 rts/RtsUtils_CC_OPTS += -DTargetPlatform=\"$(TARGETPLATFORM)\"
416 rts/RtsUtils_CC_OPTS += -DTargetArch=\"$(TargetArch_CPP)\"
417 rts/RtsUtils_CC_OPTS += -DTargetOS=\"$(TargetOS_CPP)\"
418 rts/RtsUtils_CC_OPTS += -DTargetVendor=\"$(TargetVendor_CPP)\"
419 #
420 rts/RtsUtils_CC_OPTS += -DGhcUnregisterised=\"$(GhcUnregisterised)\"
421 rts/RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=\"$(GhcEnableTablesNextToCode)\"
422 #
423 rts/xxhash_CC_OPTS += -O3 -ffast-math -ftree-vectorize
424
425 # Compile various performance-critical pieces *without* -fPIC -dynamic
426 # even when building a shared library. If we don't do this, then the
427 # GC runs about 50% slower on x86 due to the overheads of PIC. The
428 # cost of doing this is a little runtime linking and less sharing, but
429 # not much.
430 #
431 # On x86_64 this doesn't work, because all objects in a shared library
432 # must be compiled with -fPIC (since the 32-bit relocations generated
433 # by the default small memory can't be resolved at runtime). So we
434 # only do this on i386.
435 #
436 # This apparently doesn't work on OS X (Darwin) nor on Solaris.
437 # On Darwin we get errors of the form
438 #
439 # ld: absolute addressing (perhaps -mdynamic-no-pic) used in _stg_ap_0_fast from rts/dist/build/Apply.dyn_o not allowed in slidable image
440 #
441 # and lots of these warnings:
442 #
443 # ld: warning codegen in _stg_ap_pppv_fast (offset 0x0000005E) prevents image from loading in dyld shared cache
444 #
445 # On Solaris we get errors like:
446 #
447 # Text relocation remains referenced
448 # against symbol offset in file
449 # .rodata (section) 0x11 rts/dist/build/Apply.dyn_o
450 # ...
451 # ld: fatal: relocations remain against allocatable but non-writable sections
452 # collect2: ld returned 1 exit status
453
454 ifeq "$(TargetArch_CPP)" "i386"
455 i386_SPEED_HACK := "YES"
456 ifeq "$(TargetOS_CPP)" "darwin"
457 i386_SPEED_HACK := "NO"
458 endif
459 ifeq "$(TargetOS_CPP)" "solaris2"
460 i386_SPEED_HACK := "NO"
461 endif
462 endif
463
464 ifeq "$(TargetArch_CPP)" "i386"
465 ifeq "$(i386_SPEED_HACK)" "YES"
466 rts/sm/Evac_HC_OPTS += -fno-PIC
467 rts/sm/Evac_thr_HC_OPTS += -fno-PIC
468 rts/sm/Scav_HC_OPTS += -fno-PIC
469 rts/sm/Scav_thr_HC_OPTS += -fno-PIC
470 rts/sm/Compact_HC_OPTS += -fno-PIC
471 rts/sm/GC_HC_OPTS += -fno-PIC
472
473 # -static is also necessary for these bits, otherwise the NCG
474 # -generates dynamic references:
475 rts/Updates_HC_OPTS += -fno-PIC -static
476 rts/StgMiscClosures_HC_OPTS += -fno-PIC -static
477 rts/PrimOps_HC_OPTS += -fno-PIC -static
478 rts/Apply_HC_OPTS += -fno-PIC -static
479 rts/dist/build/AutoApply_HC_OPTS += -fno-PIC -static
480 endif
481 endif
482
483 # add CFLAGS for libffi
484 ifeq "$(UseSystemLibFFI)" "YES"
485 LIBFFI_CFLAGS = $(addprefix -I,$(FFIIncludeDir))
486 else
487 LIBFFI_CFLAGS =
488 endif
489 # ffi.h triggers prototype warnings, so disable them here:
490 rts/Interpreter_CC_OPTS += -Wno-strict-prototypes $(LIBFFI_CFLAGS)
491 rts/Adjustor_CC_OPTS += -Wno-strict-prototypes $(LIBFFI_CFLAGS)
492 rts/sm/Storage_CC_OPTS += -Wno-strict-prototypes $(LIBFFI_CFLAGS)
493 # ffi.h triggers undefined macro warnings on PowerPC, disable those:
494 # this matches substrings of powerpc64le, including "powerpc" and "powerpc64"
495 ifneq "$(findstring $(TargetArch_CPP), powerpc64le)" ""
496 rts/Interpreter_CC_OPTS += -Wno-undef
497 rts/Adjustor_CC_OPTS += -Wno-undef
498 rts/sm/Storage_CC_OPTS += -Wno-undef
499 endif
500
501 # inlining warnings happen in Compact
502 rts/sm/Compact_CC_OPTS += -Wno-inline
503
504 # emits warnings about call-clobbered registers on x86_64
505 rts/StgCRun_CC_OPTS += -w
506
507 rts/RetainerProfile_CC_OPTS += -w
508 # On Windows:
509 rts/win32/ConsoleHandler_CC_OPTS += -w
510 rts/win32/ThrIOManager_CC_OPTS += -w
511 # The above warning suppression flags are a temporary kludge.
512 # While working on this module you are encouraged to remove it and fix
513 # any warnings in the module. See
514 # http://ghc.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
515 # for details
516
517 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
518 ifneq "$(CC_CLANG_BACKEND)" "1"
519 rts/sm/Compact_CC_OPTS += -finline-limit=2500
520 endif
521
522 # -O3 helps unroll some loops (especially in copy() with a constant argument).
523 rts/sm/Evac_CC_OPTS += -funroll-loops
524 rts/sm/Evac_thr_HC_OPTS += -optc-funroll-loops
525
526
527 #-----------------------------------------------------------------------------
528 # Use system provided libffi
529
530 ifeq "$(UseSystemLibFFI)" "YES"
531
532 rts_PACKAGE_CPP_OPTS += -DFFI_INCLUDE_DIR=$(FFIIncludeDir)
533 rts_PACKAGE_CPP_OPTS += -DFFI_LIB_DIR=$(FFILibDir)
534 rts_PACKAGE_CPP_OPTS += '-DFFI_LIB='
535
536 else # UseSystemLibFFI==YES
537
538 rts_PACKAGE_CPP_OPTS += -DFFI_INCLUDE_DIR=
539 rts_PACKAGE_CPP_OPTS += -DFFI_LIB_DIR=
540 rts_PACKAGE_CPP_OPTS += '-DFFI_LIB="C$(LIBFFI_NAME)"'
541
542 endif
543
544 # -----------------------------------------------------------------------------
545 # dependencies
546
547 rts_WAYS_DASHED = $(subst $(space),,$(patsubst %,-%,$(strip $(rts_WAYS))))
548 rts_dist_depfile_base = rts/dist/build/.depend$(rts_WAYS_DASHED)
549
550 rts_dist_C_SRCS = $(rts_C_SRCS) $(rts_thr_EXTRA_C_SRCS)
551 rts_dist_S_SRCS = $(rts_S_SRCS)
552 rts_dist_CMM_SRCS = $(rts_CMM_SRCS)
553 rts_dist_C_FILES = $(rts_dist_C_SRCS)
554 rts_dist_S_FILES = $(rts_dist_S_SRCS)
555 rts_dist_CMM_FILES = $(rts_dist_CMM_SRCS)
556
557 # Hack: we define every way-related option here, so that we get (hopefully)
558 # a superset of the dependencies. To do this properly, we should generate
559 # a different set of dependencies for each way. Further hack: PROFILING an
560
561 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
562 rts_dist_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
563
564 ifeq "$(USE_DTRACE)" "YES"
565
566 rts_dist_MKDEPENDC_OPTS += -Irts/dist/build
567
568 endif
569
570 $(eval $(call dependencies,rts,dist,1))
571
572 $(rts_dist_depfile_c_asm) : $(DTRACEPROBES_H)
573 ifneq "$(UseSystemLibFFI)" "YES"
574 $(rts_dist_depfile_c_asm) : $(libffi_HEADERS)
575 endif
576
577 # -----------------------------------------------------------------------------
578 # compile dtrace probes if dtrace is supported
579
580 ifeq "$(USE_DTRACE)" "YES"
581
582 rts_CC_OPTS += -DDTRACE
583 rts_HC_OPTS += -DDTRACE
584
585 # Apple's dtrace (the only one supported by ghc at the moment) uses
586 # gcc as its preprocessor. If gcc isn't at /usr/bin/gcc, or we need
587 # to force it to use a different gcc, we need to give the path in
588 # the option cpppath.
589
590 ifeq "$(TargetOS_CPP)" "darwin"
591 # Darwin has a flag to tell dtrace which cpp to use.
592 # Unfortunately, this isn't supported on Solaris (See Solaris Dynamic Tracing
593 # Guide, Chapter 16, for the configuration variables available on Solaris)
594 DTRACE_FLAGS = -x cpppath=$(CC)
595 endif
596
597 DTRACEPROBES_SRC = rts/RtsProbes.d
598 $(DTRACEPROBES_H): $(DTRACEPROBES_SRC) includes/ghcplatform.h | $$(dir $$@)/.
599 "$(DTRACE)" $(filter -I%,$(rts_CC_OPTS)) -C $(DTRACE_FLAGS) -h -o $@ -s $<
600 endif
601
602 # -----------------------------------------------------------------------------
603 # The RTS package config
604
605 # If -DDEBUG is in effect, adjust package conf accordingly..
606 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
607 rts_PACKAGE_CPP_OPTS += -DDEBUG
608 endif
609
610 ifeq "$(HaveLibMingwEx)" "YES"
611 rts_PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
612 endif
613
614 $(eval $(call manual-package-config,rts))
615
616 rts/package.conf.inplace : $(includes_H_CONFIG) $(includes_H_PLATFORM)
617
618 # -----------------------------------------------------------------------------
619 # installing
620
621 RTS_INSTALL_LIBS += $(ALL_RTS_LIBS)
622 ifneq "$(UseSystemLibFFI)" "YES"
623 RTS_INSTALL_LIBS += $(wildcard rts/dist/build/lib$(LIBFFI_NAME)*$(soext)*)
624 RTS_INSTALL_LIBS += $(foreach w,$(filter-out %dyn,$(rts_WAYS)),rts/dist/build/libC$(LIBFFI_NAME)$($w_libsuf))
625 endif
626
627 ifneq "$(UseSystemLibFFI)" "YES"
628 install: install_libffi_headers
629 endif
630
631 .PHONY: install_libffi_headers
632 install_libffi_headers :
633 $(INSTALL_DIR) "$(DESTDIR)$(ghcheaderdir)"
634 $(INSTALL_HEADER) $(INSTALL_OPTS) $(libffi_HEADERS) "$(DESTDIR)$(ghcheaderdir)/"
635
636 # -----------------------------------------------------------------------------
637 # cleaning
638
639 $(eval $(call clean-target,rts,dist,rts/dist))
640
641 BINDIST_EXTRAS += rts/package.conf.in
642