Revert "rts: Drop redundant flags for libffi"
[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 # https://gitlab.haskell.org/ghc/ghc/wikis/building/architecture
9 # https://gitlab.haskell.org/ghc/ghc/wikis/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 s390x)" ""
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 \
194 $$(addprefix -I,$$(GHC_INCLUDE_DIRS)) \
195 -I$$(BUILD_1_INCLUDE_DIR) \
196 -DDTRACE -s rts/RtsProbes.d \
197 -o $$@ \
198 $$(rts_$1_OBJS)
199 endif
200 endif
201
202 rts_dist_$1_CC_OPTS += -DRtsWay=\"rts_$1\"
203
204 # If we're compiling on windows, enforce that we only support XP+
205 # Adding this here means it doesn't have to be done in individual .c files
206 # and also centralizes the versioning.
207 ifeq "$$(TargetOS_CPP)" "mingw32"
208 rts_dist_$1_CC_OPTS += -DWINVER=$(rts_WINVER)
209 endif
210
211 ifneq "$$(UseSystemLibFFI)" "YES"
212 rts_dist_FFI_SO = rts/dist/build/lib$$(LIBFFI_NAME)$$(soext)
213 else
214 rts_dist_FFI_SO =
215 endif
216
217 # Making a shared library for the RTS.
218 ifneq "$$(findstring dyn, $1)" ""
219 ifeq "$$(TargetOS_CPP)" "mingw32"
220 $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/dist/libs.depend rts/dist/build/$$(LIBFFI_DLL)
221 "$$(RM)" $$(RM_OPTS) $$@
222 # Call out to the shell script to decide how to build the dll.
223 # Making a shared library for the RTS.
224 # $$1 = dir
225 # $$2 = distdir
226 # $$3 = way
227 # $$4 = extra flags
228 # $$5 = extra libraries to link
229 # $$6 = object files to link
230 # $$7 = output filename
231 # $$8 = link command
232 # $$9 = create delay load import lib
233 # $$10 = SxS Name
234 # $$11 = SxS Version
235 $$(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 \
236 -no-auto-link-packages -Lrts/dist/build -l$$(LIBFFI_NAME) \
237 `cat rts/dist/libs.depend | tr '\n' ' '` \
238 $$(rts_dist_$1_GHC_LD_OPTS)" "NO" \
239 "$(rts_INSTALL_INFO)-$(subst dyn,,$(subst _dyn,,$(subst v,,$1)))" "$(ProjectVersion)"
240
241 else
242 ifneq "$$(UseSystemLibFFI)" "YES"
243 LIBFFI_LIBS = -Lrts/dist/build -l$$(LIBFFI_NAME)
244 ifeq "$$(TargetElf)" "YES"
245 LIBFFI_LIBS += -optl-Wl,-rpath -optl-Wl,'$$$$ORIGIN' -optl-Wl,-zorigin
246 endif
247 ifeq "$(TargetOS_CPP)" "darwin"
248 LIBFFI_LIBS += -optl-Wl,-rpath -optl-Wl,@loader_path
249 endif
250
251 else
252 # flags will be taken care of in rts/dist/libs.depend
253 LIBFFI_LIBS =
254 endif
255 $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/dist/libs.depend $$(rts_dist_FFI_SO)
256 "$$(RM)" $$(RM_OPTS) $$@
257 "$$(rts_dist_HC)" -this-unit-id rts -shared -dynamic -dynload deploy \
258 -no-auto-link-packages $$(LIBFFI_LIBS) `cat rts/dist/libs.depend` $$(rts_$1_OBJS) \
259 $$(rts_dist_$1_GHC_LD_OPTS) \
260 $$(rts_$1_DTRACE_OBJS) -o $$@
261 endif
262 else
263
264 ifeq "$(USE_DTRACE)" "YES"
265 ifeq "$(NEED_DTRACE_PROBES_OBJ)" "YES"
266 # A list of objects that do not get included in the RTS object that is created
267 # during the linking step. To prevent future linking errors, especially when
268 # using the compiler as a bootstrap compiler, we need to exclude the hook
269 # objects from being re-linked into the single LINKED_OBJS object file. When the
270 # hooks are being linked into the RTS object this will result in duplicated
271 # symbols causing the linker to fail (e.g. `StackOverflowHook` in RTS.o and
272 # hschooks.o). The excluded objects do not get relinked into the RTS object but
273 # get included separately so prevent linker errors.
274 # (see issue #15040)
275 rts_$1_EXCLUDED_OBJS = $$(rts_$1_C_HOOK_OBJS)
276 # The RTS object that gets generated to package up all of the runtime system
277 # with the dtrace probe code.
278 rts_$1_LINKED_OBJS = rts/dist/build/RTS.$$($1_osuf)
279
280 $$(rts_$1_LINKED_OBJS) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) $$(rts_$1_C_HOOK_OBJS)
281 "$$(RM)" $$(RM_OPTS) $$@
282
283 # When linking an archive the linker will only include the object files that
284 # are actually needed during linking. It therefore does not include the dtrace
285 # specific code for initializing the probes. By creating a single object that
286 # also includes the probe object code we force the linker to include the
287 # probes when linking the static runtime.
288 #
289 # The reason why we are re-linking all the objects into a single object file
290 # is stated in this thread:
291 # https://thr3ads.net/dtrace-discuss/2005/08/384778-Problem-with-probes-defined-in-static-libraries
292 $(LD) -r -o $$(rts_$1_LINKED_OBJS) $$(rts_$1_DTRACE_OBJS) $$(filter-out $$(rts_$1_EXCLUDED_OBJS), $$(rts_$1_OBJS))
293 else
294 rts_$1_EXCLUDED_OBJS =
295 rts_$1_LINKED_OBJS = $$(rts_$1_OBJS)
296 endif
297 else
298 rts_$1_EXCLUDED_OBJS =
299 rts_$1_LINKED_OBJS = $$(rts_$1_OBJS)
300 endif
301
302
303 $$(rts_$1_LIB) : $$(rts_$1_LINKED_OBJS)
304 "$$(RM)" $$(RM_OPTS) $$@
305
306 echo $$(rts_$1_LINKED_OBJS) $$(rts_$1_EXCLUDED_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR_STAGE1)" \
307 $$(AR_OPTS_STAGE1) $$(EXTRA_AR_ARGS_STAGE1) $$@
308
309 ifneq "$$(UseSystemLibFFI)" "YES"
310 $$(rts_$1_LIB) : rts/dist/build/libC$$(LIBFFI_NAME)$$($1_libsuf)
311 rts/dist/build/libC$$(LIBFFI_NAME)$$($1_libsuf): libffi/build/inst/lib/libffi.a
312 cp $$< $$@
313 endif
314
315 endif
316
317 endif
318
319 endef
320
321 # And expand the above for each way:
322 $(foreach way,$(rts_WAYS),$(eval $(call build-rts-way,$(way))))
323
324 $(eval $(call distdir-opts,rts,dist,1))
325
326 #-----------------------------------------------------------------------------
327 # Flags for compiling every file
328
329 # We like plenty of warnings.
330 WARNING_OPTS += -Wall
331 WARNING_OPTS += -Wextra
332 WARNING_OPTS += -Wstrict-prototypes
333 WARNING_OPTS += -Wmissing-prototypes
334 WARNING_OPTS += -Wmissing-declarations
335 WARNING_OPTS += -Winline
336 WARNING_OPTS += -Wpointer-arith
337 WARNING_OPTS += -Wmissing-noreturn
338 WARNING_OPTS += -Wnested-externs
339 WARNING_OPTS += -Wredundant-decls
340 # Some gccs annoyingly enable this archaic specimen by default
341 WARNING_OPTS += -Wno-aggregate-return
342
343 # These ones are hard to avoid:
344 #WARNING_OPTS += -Wconversion
345 #WARNING_OPTS += -Wbad-function-cast
346 #WARNING_OPTS += -Wshadow
347 #WARNING_OPTS += -Wcast-qual
348
349 # This one seems buggy on GCC 4.1.2, which is the only GCC version we
350 # have that can bootstrap the SPARC build. We end up with lots of supurious
351 # warnings of the form "cast increases required alignment of target type".
352 # Some legitimate warnings can be fixed by adding an intermediate cast to
353 # (void*), but we get others in rts/sm/GCUtils.c concerning the gct var
354 # that look innocuous to me. We could enable this again once we deprecate
355 # support for registerised builds on this arch. -- BL 2010/02/03
356 # WARNING_OPTS += -Wcast-align
357
358 STANDARD_OPTS += \
359 $(addprefix -I,$(GHC_INCLUDE_DIRS)) \
360 -I$(BUILD_1_INCLUDE_DIR) \
361 -Irts \
362 -Irts/dist/build
363
364 # COMPILING_RTS is only used when building Win32 DLL support.
365 STANDARD_OPTS += -DCOMPILING_RTS -DFS_NAMESPACE=rts
366
367 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
368 # only included in .c compilations. HC_OPTS included the WAY_* opts, which
369 # must be included in both types of compilations.
370
371 rts_CC_OPTS += $(WARNING_OPTS)
372 rts_CC_OPTS += $(STANDARD_OPTS)
373
374 rts_HC_OPTS += $(STANDARD_OPTS) -this-unit-id rts
375
376 ifneq "$(GhcWithSMP)" "YES"
377 rts_CC_OPTS += -DNOSMP
378 rts_HC_OPTS += -optc-DNOSMP
379 endif
380
381 ifeq "$(UseLibFFIForAdjustors)" "YES"
382 rts_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
383 endif
384
385 # We *want* type-checking of hand-written cmm.
386 rts_HC_OPTS += -dcmm-lint
387
388 # -fno-strict-aliasing is required for the runtime, because we often
389 # use a variety of types to represent closure pointers (StgPtr,
390 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
391 # allowed to assume that these pointers do not alias. eg. without
392 # this flag we get problems in sm/Evac.c:copy() with gcc 3.4.3, the
393 # upd_evacuee() assignments get moved before the object copy.
394 rts_CC_OPTS += -fno-strict-aliasing
395
396 rts_CC_OPTS += -fno-common
397
398 ifeq "$(BeConservative)" "YES"
399 rts_CC_OPTS += -DBE_CONSERVATIVE
400 endif
401
402 # Set Windows version
403 ifeq "$$(TargetOS_CPP)" "mingw32"
404 rts_CC_OPTS += -DWINVER=$(rts_WINVER)
405 endif
406
407 #-----------------------------------------------------------------------------
408 # Flags for compiling specific files
409 rts/RtsMessages_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
410 rts/RtsUtils_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
411 rts/Trace_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
412 #
413 rts/RtsUtils_CC_OPTS += -DHostPlatform=\"$(HOSTPLATFORM)\"
414 rts/RtsUtils_CC_OPTS += -DHostArch=\"$(HostArch_CPP)\"
415 rts/RtsUtils_CC_OPTS += -DHostOS=\"$(HostOS_CPP)\"
416 rts/RtsUtils_CC_OPTS += -DHostVendor=\"$(HostVendor_CPP)\"
417 #
418 rts/RtsUtils_CC_OPTS += -DBuildPlatform=\"$(BUILDPLATFORM)\"
419 rts/RtsUtils_CC_OPTS += -DBuildArch=\"$(BuildArch_CPP)\"
420 rts/RtsUtils_CC_OPTS += -DBuildOS=\"$(BuildOS_CPP)\"
421 rts/RtsUtils_CC_OPTS += -DBuildVendor=\"$(BuildVendor_CPP)\"
422 #
423 rts/RtsUtils_CC_OPTS += -DTargetPlatform=\"$(TARGETPLATFORM)\"
424 rts/RtsUtils_CC_OPTS += -DTargetArch=\"$(TargetArch_CPP)\"
425 rts/RtsUtils_CC_OPTS += -DTargetOS=\"$(TargetOS_CPP)\"
426 rts/RtsUtils_CC_OPTS += -DTargetVendor=\"$(TargetVendor_CPP)\"
427 #
428 rts/RtsUtils_CC_OPTS += -DGhcUnregisterised=\"$(GhcUnregisterised)\"
429 rts/RtsUtils_CC_OPTS += -DTablesNextToCode=\"$(TablesNextToCode)\"
430 #
431 rts/xxhash_CC_OPTS += -O3 -ffast-math -ftree-vectorize
432
433 # Compile various performance-critical pieces *without* -fPIC -dynamic
434 # even when building a shared library. If we don't do this, then the
435 # GC runs about 50% slower on x86 due to the overheads of PIC. The
436 # cost of doing this is a little runtime linking and less sharing, but
437 # not much.
438 #
439 # On x86_64 this doesn't work, because all objects in a shared library
440 # must be compiled with -fPIC (since the 32-bit relocations generated
441 # by the default small memory can't be resolved at runtime). So we
442 # only do this on i386.
443 #
444 # This apparently doesn't work on OS X (Darwin) nor on Solaris.
445 # On Darwin we get errors of the form
446 #
447 # 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
448 #
449 # and lots of these warnings:
450 #
451 # ld: warning codegen in _stg_ap_pppv_fast (offset 0x0000005E) prevents image from loading in dyld shared cache
452 #
453 # On Solaris we get errors like:
454 #
455 # Text relocation remains referenced
456 # against symbol offset in file
457 # .rodata (section) 0x11 rts/dist/build/Apply.dyn_o
458 # ...
459 # ld: fatal: relocations remain against allocatable but non-writable sections
460 # collect2: ld returned 1 exit status
461
462 ifeq "$(TargetArch_CPP)" "i386"
463 i386_SPEED_HACK := "YES"
464 ifeq "$(TargetOS_CPP)" "darwin"
465 i386_SPEED_HACK := "NO"
466 endif
467 ifeq "$(TargetOS_CPP)" "solaris2"
468 i386_SPEED_HACK := "NO"
469 endif
470 endif
471
472 ifeq "$(TargetArch_CPP)" "i386"
473 ifeq "$(i386_SPEED_HACK)" "YES"
474 rts/sm/Evac_HC_OPTS += -fno-PIC
475 rts/sm/Evac_thr_HC_OPTS += -fno-PIC
476 rts/sm/Scav_HC_OPTS += -fno-PIC
477 rts/sm/Scav_thr_HC_OPTS += -fno-PIC
478 rts/sm/Compact_HC_OPTS += -fno-PIC
479 rts/sm/GC_HC_OPTS += -fno-PIC
480
481 # -static is also necessary for these bits, otherwise the NCG
482 # -generates dynamic references:
483 rts/Updates_HC_OPTS += -fno-PIC -static
484 rts/StgMiscClosures_HC_OPTS += -fno-PIC -static
485 rts/PrimOps_HC_OPTS += -fno-PIC -static
486 rts/Apply_HC_OPTS += -fno-PIC -static
487 rts/dist/build/AutoApply_HC_OPTS += -fno-PIC -static
488 endif
489 endif
490
491 # add CFLAGS for libffi
492 ifeq "$(UseSystemLibFFI)" "YES"
493 LIBFFI_CFLAGS = $(addprefix -I,$(FFIIncludeDir))
494 else
495 LIBFFI_CFLAGS =
496 endif
497 # ffi.h triggers prototype warnings, so disable them here:
498 rts/Interpreter_CC_OPTS += -Wno-strict-prototypes $(LIBFFI_CFLAGS)
499 rts/Adjustor_CC_OPTS += -Wno-strict-prototypes $(LIBFFI_CFLAGS)
500 rts/sm/Storage_CC_OPTS += -Wno-strict-prototypes $(LIBFFI_CFLAGS)
501 # ffi.h triggers undefined macro warnings on PowerPC, disable those:
502 # this matches substrings of powerpc64le, including "powerpc" and "powerpc64"
503 ifneq "$(findstring $(TargetArch_CPP), powerpc64le)" ""
504 rts/Interpreter_CC_OPTS += -Wno-undef
505 rts/Adjustor_CC_OPTS += -Wno-undef
506 rts/sm/Storage_CC_OPTS += -Wno-undef
507 endif
508
509 # inlining warnings happen in Compact
510 rts/sm/Compact_CC_OPTS += -Wno-inline
511
512 # emits warnings about call-clobbered registers on x86_64
513 rts/StgCRun_CC_OPTS += -w
514
515 # On Windows:
516 rts/win32/ConsoleHandler_CC_OPTS += -w
517 rts/win32/ThrIOManager_CC_OPTS += -w
518 # The above warning suppression flags are a temporary kludge.
519 # While working on this module you are encouraged to remove it and fix
520 # any warnings in the module. See
521 # https://gitlab.haskell.org/ghc/ghc/wikis/working-conventions#Warnings
522 # for details
523
524 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
525 ifneq "$(CcLlvmBackend)" "YES"
526 rts/sm/Compact_CC_OPTS += -finline-limit=2500
527 endif
528
529 # -O3 helps unroll some loops (especially in copy() with a constant argument).
530 rts/sm/Evac_CC_OPTS += -funroll-loops
531 rts/sm/Evac_thr_HC_OPTS += -optc-funroll-loops
532
533
534 #-----------------------------------------------------------------------------
535 # Use system provided libffi
536
537 ifeq "$(UseSystemLibFFI)" "YES"
538
539 rts_PACKAGE_CPP_OPTS += -DFFI_INCLUDE_DIR=$(FFIIncludeDir)
540 rts_PACKAGE_CPP_OPTS += -DFFI_LIB_DIR=$(FFILibDir)
541 rts_PACKAGE_CPP_OPTS += '-DFFI_LIB='
542
543 else # UseSystemLibFFI==YES
544
545 rts_PACKAGE_CPP_OPTS += -DFFI_INCLUDE_DIR=
546 rts_PACKAGE_CPP_OPTS += -DFFI_LIB_DIR=
547 rts_PACKAGE_CPP_OPTS += '-DFFI_LIB="C$(LIBFFI_NAME)"'
548
549 endif
550
551 ifeq "$(UseLibdw)" "YES"
552 rts_PACKAGE_CPP_OPTS += -DLIBDW_INCLUDE_DIR=$(LibdwIncludeDir)
553 rts_PACKAGE_CPP_OPTS += -DLIBDW_LIB_DIR=$(LibdwLibDir)
554 else
555 rts_PACKAGE_CPP_OPTS += -DLIBDW_INCLUDE_DIR=
556 rts_PACKAGE_CPP_OPTS += -DLIBDW_LIB_DIR=
557 endif
558
559 # -----------------------------------------------------------------------------
560 # dependencies
561
562 rts_WAYS_DASHED = $(subst $(space),,$(patsubst %,-%,$(strip $(rts_WAYS))))
563 rts_dist_depfile_base = rts/dist/build/.depend$(rts_WAYS_DASHED)
564
565 rts_dist_C_SRCS = $(rts_C_SRCS) $(rts_thr_EXTRA_C_SRCS)
566 rts_dist_S_SRCS = $(rts_S_SRCS)
567 rts_dist_CMM_SRCS = $(rts_CMM_SRCS)
568 rts_dist_C_FILES = $(rts_dist_C_SRCS)
569 rts_dist_S_FILES = $(rts_dist_S_SRCS)
570 rts_dist_CMM_FILES = $(rts_dist_CMM_SRCS)
571
572 # Hack: we define every way-related option here, so that we get (hopefully)
573 # a superset of the dependencies. To do this properly, we should generate
574 # a different set of dependencies for each way. Further hack: PROFILING an
575
576 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
577 rts_dist_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
578
579 ifeq "$(USE_DTRACE)" "YES"
580
581 rts_dist_MKDEPENDC_OPTS += -Irts/dist/build
582
583 endif
584
585 $(eval $(call dependencies,rts,dist,1))
586
587 $(rts_dist_depfile_c_asm) : $(includes_dist_H_CONFIG)
588 $(rts_dist_depfile_c_asm) : $(includes_dist_H_PLATFORM)
589 $(rts_dist_depfile_c_asm) : $(includes_dist_H_VERSION)
590
591 $(rts_dist_depfile_c_asm) : $(DTRACEPROBES_H)
592 ifneq "$(UseSystemLibFFI)" "YES"
593 $(rts_dist_depfile_c_asm) : $(libffi_HEADERS)
594 endif
595
596 # -----------------------------------------------------------------------------
597 # compile dtrace probes if dtrace is supported
598
599 ifeq "$(USE_DTRACE)" "YES"
600
601 rts_CC_OPTS += -DDTRACE
602 rts_HC_OPTS += -DDTRACE
603
604 # Apple's dtrace (the only one supported by ghc at the moment) uses
605 # gcc as its preprocessor. If gcc isn't at /usr/bin/gcc, or we need
606 # to force it to use a different gcc, we need to give the path in
607 # the option cpppath.
608
609 ifeq "$(TargetOS_CPP)" "darwin"
610 # Darwin has a flag to tell dtrace which cpp to use.
611 # Unfortunately, this isn't supported on Solaris (See Solaris Dynamic Tracing
612 # Guide, Chapter 16, for the configuration variables available on Solaris)
613 DTRACE_FLAGS = -x cpppath=$(CC)
614 endif
615
616 DTRACEPROBES_SRC = rts/RtsProbes.d
617 $(DTRACEPROBES_H): $(DTRACEPROBES_SRC) $(includes_1_H_PLATFORM) | $$(dir $$@)/.
618 "$(DTRACE)" $(filter -I%,$(rts_CC_OPTS)) -C $(DTRACE_FLAGS) -h -o $@ -s $<
619 endif
620
621 # -----------------------------------------------------------------------------
622 # The RTS package config
623
624 # If -DDEBUG is in effect, adjust package conf accordingly..
625 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
626 rts_PACKAGE_CPP_OPTS += -DDEBUG
627 endif
628
629 ifeq "$(HaveLibMingwEx)" "YES"
630 rts_PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
631 endif
632
633 $(eval $(call manual-package-config,rts,1))
634
635 rts/dist/package.conf.inplace : $(includes_1_H_CONFIG) $(includes_1_H_PLATFORM) $(includes_1_H_VERSION)
636
637 # -----------------------------------------------------------------------------
638 # installing
639
640 RTS_INSTALL_LIBS += $(ALL_RTS_LIBS)
641 ifneq "$(UseSystemLibFFI)" "YES"
642 RTS_INSTALL_LIBS += $(wildcard rts/dist/build/lib$(LIBFFI_NAME)*$(soext)*)
643 RTS_INSTALL_LIBS += $(foreach w,$(filter-out %dyn,$(rts_WAYS)),rts/dist/build/libC$(LIBFFI_NAME)$($w_libsuf))
644 endif
645
646 ifneq "$(UseSystemLibFFI)" "YES"
647 install: install_libffi_headers
648 endif
649
650 .PHONY: install_libffi_headers
651 install_libffi_headers :
652 $(INSTALL_DIR) "$(DESTDIR)$(ghcheaderdir)"
653 $(INSTALL_HEADER) $(INSTALL_OPTS) $(libffi_HEADERS) "$(DESTDIR)$(ghcheaderdir)/"
654
655 # -----------------------------------------------------------------------------
656 # cleaning
657
658 $(eval $(call clean-target,rts,dist,rts/dist))
659
660 BINDIST_EXTRAS += rts/package.conf.in
661