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