Expose all EventLog events as DTrace probes
[ghc-hetmet.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://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
9 #      http://hackage.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 # merge GhcLibWays and GhcRTSWays but strip out duplicates
20 rts_WAYS = $(GhcLibWays) $(filter-out $(GhcLibWays),$(GhcRTSWays))
21 rts_dist_WAYS = $(rts_WAYS)
22
23 ALL_RTS_LIBS = rts/dist/build/libHSrtsmain.a \
24                $(foreach way,$(rts_WAYS),rts/dist/build/libHSrts$($(way)_libsuf))
25 all_rts : $(ALL_RTS_LIBS)
26
27 # -----------------------------------------------------------------------------
28 # Defining the sources
29
30 ALL_DIRS = hooks parallel sm eventlog
31
32 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
33 ALL_DIRS += win32
34 else
35 ALL_DIRS += posix
36 endif
37
38 EXCLUDED_SRCS += rts/Main.c
39 EXCLUDED_SRCS += rts/parallel/SysMan.c
40 EXCLUDED_SRCS += rts/dyn-wrapper.c
41 EXCLUDED_SRCS += $(wildcard rts/Vis*.c)
42
43 rts_C_SRCS = $(filter-out $(EXCLUDED_SRCS),$(wildcard rts/*.c $(foreach dir,$(ALL_DIRS),rts/$(dir)/*.c)))
44 rts_CMM_SRCS = $(wildcard rts/*.cmm)
45
46 # Don't compile .S files when bootstrapping a new arch
47 ifeq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
48 ifneq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
49 rts_S_SRCS += rts/AdjustorAsm.S
50 else
51 ifneq "$(findstring $(TargetOS_CPP), darwin)" ""
52 rts_S_SRCS += rts/AdjustorAsm.S
53 endif
54 endif
55 endif
56
57 ifeq "$(GhcUnregisterised)" "YES"
58 GENAPPLY_OPTS = -u
59 endif
60
61 rts_AUTO_APPLY_CMM = rts/dist/build/AutoApply.cmm
62
63 $(rts_AUTO_APPLY_CMM): $(GENAPPLY_INPLACE)
64         "$(GENAPPLY_INPLACE)" >$@
65
66 rts/dist/build/sm/Evac_thr.c : rts/sm/Evac.c | $$(dir $$@)/.
67         cp $< $@
68 rts/dist/build/sm/Scav_thr.c : rts/sm/Scav.c | $$(dir $$@)/.
69         cp $< $@
70
71 rts_H_FILES = $(wildcard includes/*.h) $(wildcard rts/*.h)
72
73 ifeq "$(HaveDtrace)" "YES"
74 DTRACEPROBES_H = rts/dist/build/RtsProbes.h
75 rts_H_FILES += $(DTRACEPROBES_H)
76 endif
77
78 # collect the -l flags that we need to link the rts dyn lib.
79 rts/libs.depend : $(GHC_PKG_INPLACE)
80         "$(GHC_PKG_INPLACE)" field rts extra-libraries \
81           | sed -e 's/^extra-libraries: //' -e 's/\([a-z0-9]*\)[ ]*/-l\1 /g' > $@
82
83
84 # ----------------------------------------------------------------------------
85 # On Windows, as the RTS and base libraries have recursive imports,
86 #       we have to break the loop with "import libraries".
87 #       These are made from rts/win32/libHS*.def which contain lists of
88 #       all the symbols in those libraries used by the RTS.
89 #
90 ifneq "$$(findstring dyn, $1)" ""
91 ifeq  "$(HOSTPLATFORM)" "i386-unknown-mingw32" 
92
93 ALL_RTS_DEF_LIBNAMES    = base ghc-prim
94 ALL_RTS_DEF_LIBS        = \
95         rts/dist/build/win32/libHSbase.dll.a \
96         rts/dist/build/win32/libHSghc-prim.dll.a \
97         rts/dist/build/win32/libHSffi.dll.a 
98
99 # -- import libs for the regular Haskell libraries
100 define make-importlib-def # args $1 = lib name
101 rts/dist/build/win32/libHS$1.def : rts/win32/libHS$1.def
102         cat rts/win32/libHS$1.def \
103                 | sed "s/@LibVersion@/$$(libraries/$1_dist-install_VERSION)/" \
104                 | sed "s/@ProjectVersion@/$(ProjectVersion)/" \
105                 > rts/dist/build/win32/libHS$1.def
106                 
107 rts/dist/build/win32/libHS$1.dll.a : rts/dist/build/win32/libHS$1.def
108         "$$(DLLTOOL)"   -d rts/dist/build/win32/libHS$1.def \
109                         -l rts/dist/build/win32/libHS$1.dll.a
110 endef
111 $(foreach lib,$(ALL_RTS_DEF_LIBNAMES),$(eval $(call make-importlib-def,$(lib))))
112
113
114 # -- import libs for libffi
115 rts/dist/build/win32/libHSffi.def : rts/win32/libHSffi.def
116         cat rts/win32/libHSffi.def \
117                 | sed "s/@ProjectVersion@/$(ProjectVersion)/" \
118                 > rts/dist/build/win32/libHSffi.def
119                 
120 rts/dist/build/win32/libHSffi.dll.a : rts/dist/build/win32/libHSffi.def
121         "$(DLLTOOL)"    -d rts/dist/build/win32/libHSffi.def \
122                         -l rts/dist/build/win32/libHSffi.dll.a
123 endif
124 endif
125
126
127 #-----------------------------------------------------------------------------
128 # Building one way
129 define build-rts-way # args: $1 = way
130
131 # The per-way CC_OPTS
132 ifneq "$$(findstring debug, $1)" ""
133 rts_dist_$1_HC_OPTS =
134 rts_dist_$1_CC_OPTS = -g -O0
135 else
136 rts_dist_$1_HC_OPTS = $$(GhcRtsHcOpts)
137 rts_dist_$1_CC_OPTS = $$(GhcRtsCcOpts)
138 endif
139
140 ifneq "$$(findstring thr, $1)" ""
141 rts_$1_EXTRA_C_SRCS  =  rts/dist/build/sm/Evac_thr.c rts/dist/build/sm/Scav_thr.c
142 endif
143
144 $(call distdir-way-opts,rts,dist,$1)
145 $(call c-suffix-rules,rts,dist,$1,YES)
146 $(call cmm-suffix-rules,rts,dist,$1)
147 $(call hs-suffix-rules-srcdir,rts,dist,$1,$$(dir))
148 # hs-suffix-rules-srcdir is needed when BootingFromHc to get the .hc rules
149
150 rts_$1_LIB_NAME = libHSrts$$($1_libsuf)
151 rts_$1_LIB = rts/dist/build/$$(rts_$1_LIB_NAME)
152
153 rts_$1_C_OBJS   = $$(patsubst rts/%.c,rts/dist/build/%.$$($1_osuf),$$(rts_C_SRCS)) $$(patsubst %.c,%.$$($1_osuf),$$(rts_$1_EXTRA_C_SRCS))
154 rts_$1_S_OBJS   = $$(patsubst rts/%.S,rts/dist/build/%.$$($1_osuf),$$(rts_S_SRCS))
155 rts_$1_CMM_OBJS = $$(patsubst rts/%.cmm,rts/dist/build/%.$$($1_osuf),$$(rts_CMM_SRCS)) $$(patsubst %.cmm,%.$$($1_osuf),$$(rts_AUTO_APPLY_CMM))
156
157 rts_$1_OBJS = $$(rts_$1_C_OBJS) $$(rts_$1_S_OBJS) $$(rts_$1_CMM_OBJS)
158
159 rts_dist_$1_CC_OPTS += -DRtsWay=$$(DQ)rts_$1$$(DQ)
160
161 # Making a shared library for the RTS.
162 ifneq "$$(findstring dyn, $1)" ""
163 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
164 $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/libs.depend
165         "$$(RM)" $$(RM_OPTS) $$@
166         "$$(rts_dist_HC)" -shared -dynamic -dynload deploy \
167           -no-auto-link-packages `cat rts/libs.depend` $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) -o $$@
168 ifeq "$(darwin_TARGET_OS)" "1"
169         # Ensure library's install name is correct before anyone links with it.
170         install_name_tool -id $(ghclibdir)/$$(rts_$1_LIB_NAME) $$@
171 endif
172 else
173 $$(rts_$1_LIB) : $$(rts_$1_OBJS) rts/libs.depend
174         "$$(RM)" $$(RM_OPTS) $$@
175         "$$(rts_dist_HC)" -shared -dynamic -dynload deploy \
176           -no-auto-link-packages `cat rts/libs.depend` $$(rts_$1_OBJS) -o $$@
177 endif
178 else
179 $$(rts_$1_LIB) : $$(rts_$1_OBJS)
180         "$$(RM)" $$(RM_OPTS) $$@
181         echo $$(rts_$1_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR)" $$(AR_OPTS) $$(EXTRA_AR_ARGS) $$@
182 endif
183
184 endef
185
186 # And expand the above for each way:
187 $(foreach way,$(rts_WAYS),$(eval $(call build-rts-way,$(way))))
188
189 #-----------------------------------------------------------------------------
190 # Flags for compiling every file
191
192 # We like plenty of warnings.
193 WARNING_OPTS += -Wall
194 ifeq "$(GccLT34)" "YES"
195 WARNING_OPTS += -W
196 else
197 WARNING_OPTS += -Wextra
198 endif
199 WARNING_OPTS += -Wstrict-prototypes 
200 WARNING_OPTS += -Wmissing-prototypes 
201 WARNING_OPTS += -Wmissing-declarations
202 WARNING_OPTS += -Winline
203 WARNING_OPTS += -Waggregate-return
204 WARNING_OPTS += -Wpointer-arith
205 WARNING_OPTS += -Wmissing-noreturn
206 WARNING_OPTS += -Wcast-align
207 WARNING_OPTS += -Wnested-externs
208 WARNING_OPTS += -Wredundant-decls 
209
210 # These ones are hard to avoid:
211 #WARNING_OPTS += -Wconversion
212 #WARNING_OPTS += -Wbad-function-cast
213 #WARNING_OPTS += -Wshadow
214 #WARNING_OPTS += -Wcast-qual
215
216 STANDARD_OPTS += -Iincludes -Irts
217 # COMPILING_RTS is only used when building Win32 DLL support.
218 STANDARD_OPTS += -DCOMPILING_RTS
219
220 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
221 # only included in .c compilations.  HC_OPTS included the WAY_* opts, which
222 # must be included in both types of compilations.
223
224 rts_CC_OPTS += $(WARNING_OPTS)
225 rts_CC_OPTS += $(STANDARD_OPTS)
226
227 rts_HC_OPTS += $(STANDARD_OPTS) -package-name rts
228
229 ifneq "$(GhcWithSMP)" "YES"
230 rts_CC_OPTS += -DNOSMP
231 rts_HC_OPTS += -optc-DNOSMP
232 endif
233
234 ifeq "$(UseLibFFIForAdjustors)" "YES"
235 rts_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
236 endif
237
238 # Mac OS X: make sure we compile for the right OS version
239 rts_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
240 rts_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
241 rts_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
242
243 # Otherwise the stack-smash handler gets triggered.
244 ifneq "$(findstring $(TargetOS_CPP), darwin openbsd)" ""
245 rts_HC_OPTS += -optc-fno-stack-protector
246 endif
247
248 # We *want* type-checking of hand-written cmm.
249 rts_HC_OPTS += -dcmm-lint 
250
251 # -fno-strict-aliasing is required for the runtime, because we often
252 # use a variety of types to represent closure pointers (StgPtr,
253 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
254 # allowed to assume that these pointers do not alias.  eg. without
255 # this flag we get problems in sm/Evac.c:copy() with gcc 3.4.3, the
256 # upd_evacee() assigments get moved before the object copy.
257 rts_CC_OPTS += -fno-strict-aliasing
258
259 rts_CC_OPTS += -fno-common
260
261 ifeq "$(BeConservative)" "YES"
262 rts_CC_OPTS += -DBE_CONSERVATIVE
263 endif
264
265 #-----------------------------------------------------------------------------
266 # Flags for compiling specific files
267
268 # XXX DQ is now the same on all platforms, so get rid of it
269 DQ = \"
270
271 # If RtsMain.c is built with optimisation then the SEH exception stuff on
272 # Windows gets confused.
273 # This has to be in HC rather than CC opts, as otherwise there's a
274 # -optc-O2 that comes after it.
275 rts/RtsMain_HC_OPTS += -optc-O0
276
277 rts/RtsMessages_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
278 rts/RtsUtils_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
279 #
280 rts/RtsUtils_CC_OPTS += -DHostPlatform=$(DQ)$(HOSTPLATFORM)$(DQ)
281 rts/RtsUtils_CC_OPTS += -DHostArch=$(DQ)$(HostArch_CPP)$(DQ)
282 rts/RtsUtils_CC_OPTS += -DHostOS=$(DQ)$(HostOS_CPP)$(DQ)
283 rts/RtsUtils_CC_OPTS += -DHostVendor=$(DQ)$(HostVendor_CPP)$(DQ)
284 #
285 rts/RtsUtils_CC_OPTS += -DBuildPlatform=$(DQ)$(BUILDPLATFORM)$(DQ)
286 rts/RtsUtils_CC_OPTS += -DBuildArch=$(DQ)$(BuildArch_CPP)$(DQ)
287 rts/RtsUtils_CC_OPTS += -DBuildOS=$(DQ)$(BuildOS_CPP)$(DQ)
288 rts/RtsUtils_CC_OPTS += -DBuildVendor=$(DQ)$(BuildVendor_CPP)$(DQ)
289 #
290 rts/RtsUtils_CC_OPTS += -DTargetPlatform=$(DQ)$(TARGETPLATFORM)$(DQ)
291 rts/RtsUtils_CC_OPTS += -DTargetArch=$(DQ)$(TargetArch_CPP)$(DQ)
292 rts/RtsUtils_CC_OPTS += -DTargetOS=$(DQ)$(TargetOS_CPP)$(DQ)
293 rts/RtsUtils_CC_OPTS += -DTargetVendor=$(DQ)$(TargetVendor_CPP)$(DQ)
294 #
295 rts/RtsUtils_CC_OPTS += -DGhcUnregisterised=$(DQ)$(GhcUnregisterised)$(DQ)
296 rts/RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=$(DQ)$(GhcEnableTablesNextToCode)$(DQ)
297
298 # ffi.h triggers prototype warnings, so disable them here:
299 rts/Interpreter_CC_OPTS += -Wno-strict-prototypes
300 rts/Adjustor_CC_OPTS    += -Wno-strict-prototypes
301 rts/sm/Storage_CC_OPTS  += -Wno-strict-prototypes
302
303 # inlining warnings happen in Compact
304 rts/sm/Compact_CC_OPTS += -Wno-inline
305
306 # emits warnings about call-clobbered registers on x86_64
307 rts/StgCRun_CC_OPTS += -w
308
309 rts/RetainerProfile_CC_OPTS += -w
310 rts/RetainerSet_CC_OPTS += -Wno-format
311 # On Windows:
312 rts/win32/ConsoleHandler_CC_OPTS += -w
313 rts/win32/ThrIOManager_CC_OPTS += -w
314 rts/win32/Ticker_CC_OPTS += -w
315 # The above warning supression flags are a temporary kludge.
316 # While working on this module you are encouraged to remove it and fix
317 # any warnings in the module. See
318 #     http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
319 # for details
320
321 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
322 rts/sm/Compact_CC_OPTS += -finline-limit=2500
323
324 # -O3 helps unroll some loops (especially in copy() with a constant argument).
325 rts/sm/Evac_CC_OPTS += -funroll-loops
326 rts/dist/build/sm/Evac_thr_HC_OPTS += -optc-funroll-loops
327
328 # These files are just copies of sm/Evac.c and sm/Scav.c respectively,
329 # but compiled with -DPARALLEL_GC.
330 rts/dist/build/sm/Evac_thr_CC_OPTS += -DPARALLEL_GC -Irts/sm
331 rts/dist/build/sm/Scav_thr_CC_OPTS += -DPARALLEL_GC -Irts/sm
332
333 #-----------------------------------------------------------------------------
334 # Add PAPI library if needed
335
336 ifeq "$(GhcRtsWithPapi)" "YES"
337
338 rts_CC_OPTS             += -DUSE_PAPI
339
340 rts_PACKAGE_CPP_OPTS    += -DUSE_PAPI
341 rts_PACKAGE_CPP_OPTS    += -DPAPI_INCLUDE_DIR=$(PapiIncludeDir)
342 rts_PACKAGE_CPP_OPTS    += -DPAPI_LIB_DIR=$(PapiLibDir)
343
344 ifneq "$(PapiIncludeDir)" ""
345 rts_HC_OPTS     += -I$(PapiIncludeDir)
346 rts_CC_OPTS     += -I$(PapiIncludeDir)
347 rts_HSC2HS_OPTS += -I$(PapiIncludeDir)
348 endif
349 ifneq "$(PapiLibDirs)" ""
350 rts_LD_OPTS     += -L$(PapiLibDirs)
351 endif
352
353 else # GhcRtsWithPapi==YES
354
355 rts_PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=""
356 rts_PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=""
357
358 endif
359
360 # -----------------------------------------------------------------------------
361 # dependencies
362
363 rts_WAYS_DASHED = $(subst $(space),,$(patsubst %,-%,$(strip $(rts_WAYS))))
364 rts_dist_depfile_base = rts/dist/build/.depend$(rts_WAYS_DASHED)
365
366 rts_dist_C_SRCS  = $(rts_C_SRCS) $(rts_thr_EXTRA_C_SRCS)
367 rts_dist_S_SRCS =  $(rts_S_SRCS)
368 rts_dist_C_FILES = $(rts_C_SRCS) $(rts_thr_EXTRA_C_SRCS) $(rts_S_SRCS)
369
370 ifeq "$(HaveDtrace)" "YES"
371
372 rts_dist_MKDEPENDC_OPTS += -Irts/dist/build
373
374 endif
375
376 $(eval $(call build-dependencies,rts,dist))
377
378 $(rts_dist_depfile_c_asm) : libffi/dist-install/build/ffi.h $(DTRACEPROBES_H)
379
380 #-----------------------------------------------------------------------------
381 # libffi stuff
382
383 rts_CC_OPTS     += -Ilibffi/build/include
384 rts_HC_OPTS     += -Ilibffi/build/include
385 rts_HSC2HS_OPTS += -Ilibffi/build/include
386 rts_LD_OPTS     += -Llibffi/build/include
387
388 # -----------------------------------------------------------------------------
389 # compile generic patchable dyn-wrapper
390
391 DYNWRAPPER_SRC = rts/dyn-wrapper.c
392 DYNWRAPPER_PROG = rts/dyn-wrapper$(exeext)
393 $(DYNWRAPPER_PROG): $(DYNWRAPPER_SRC)
394         "$(HC)" -cpp -optc-include -optcdyn-wrapper-patchable-behaviour.h $(INPLACE_EXTRA_FLAGS) $< -o $@
395
396 # -----------------------------------------------------------------------------
397 # compile dtrace probes if dtrace is supported
398
399 ifeq "$(HaveDtrace)" "YES"
400
401 rts_CC_OPTS             += -DDTRACE
402 rts_HC_OPTS             += -DDTRACE
403
404 DTRACEPROBES_SRC = rts/RtsProbes.d
405 $(DTRACEPROBES_H): $(DTRACEPROBES_SRC) | $(dir $@)/.
406         "$(DTRACE)" $(filter -I%,$(rts_CC_OPTS)) -C -h -o $@ -s $<
407
408 endif
409
410 # -----------------------------------------------------------------------------
411 # build the static lib containing the C main symbol
412
413 rts/dist/build/libHSrtsmain.a : rts/dist/build/Main.o
414         "$(AR)" $(AR_OPTS) $(EXTRA_AR_ARGS) $@ $<
415
416 # -----------------------------------------------------------------------------
417 # The RTS package config
418
419 # If -DDEBUG is in effect, adjust package conf accordingly..
420 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
421 rts_PACKAGE_CPP_OPTS += -DDEBUG
422 endif
423
424 ifeq "$(HaveLibMingwEx)" "YES"
425 rts_PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
426 endif
427
428 $(eval $(call manual-package-config,rts))
429
430 ifneq "$(BootingFromHc)" "YES"
431 rts/package.conf.inplace : $(includes_H_CONFIG) $(includes_H_PLATFORM)
432 endif
433
434 # -----------------------------------------------------------------------------
435 # installing
436
437 install : install_rts
438
439 .PHONY: install_rts
440 install_rts:
441         $(INSTALL_DIR) "$(DESTDIR)$(ghclibdir)"
442         $(INSTALL_DIR) "$(DESTDIR)$(ghclibdir)/include"
443         "$(CP)" $(ALL_RTS_LIBS) "$(DESTDIR)$(ghclibdir)"
444
445 # -----------------------------------------------------------------------------
446 # cleaning
447
448 $(eval $(call clean-target,rts,dist,rts/dist))
449
450 BINDIST_EXTRAS += rts/package.conf.in
451 BINDIST_EXTRAS += $(ALL_RTS_LIBS)
452