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