Add some more fields to +RTS --info
[ghc-hetmet.git] / rts / Makefile
1 #-----------------------------------------------------------------------------
2 #
3 #  This is the Makefile for the runtime-system stuff.
4 #  This stuff is written in C (and cannot be written in Haskell).
5 #
6 #  .c  files are vanilla C,
7 #  .hc files are "Haskellized-C", compiled using the C compiler and
8 #      (possibly) the assembly-mangler.  The GHC driver script
9 #      knows how to compile this stuff.
10
11 #-----------------------------------------------------------------------------
12 # Preamble
13
14 TOP=..
15
16 # Set UseGhcForCc: this causes the fptools build system to use a different
17 # set of suffix rules for compiling C code, using $(HC) rather than $(CC)
18 # and prepending "-optc" to $(CC_OPTS).  NB. must be done before including
19 # boilerplate.mk below.
20 UseGhcForCc = YES
21
22 include $(TOP)/mk/boilerplate.mk
23
24 PACKAGE = rts
25
26 HC=$(GHC_INPLACE)
27
28
29 # Setting _way here is a nasty hack to make sure we get libHSrts*.a etc
30 # rather than just libHSrts.a when we are installing bindists.
31 ifeq "$(DOING_BIN_DIST)" "YES"
32 _way = *
33 endif
34
35 # -----------------------------------------------------------------------------
36 # RTS ways
37
38 WAYS=$(strip $(GhcLibWays) $(GhcRTSWays))
39
40 ifneq "$(findstring debug, $(way))" ""
41 GhcRtsHcOpts=
42 GhcRtsCcOpts=-g -O0
43 endif
44
45 ifeq "$(BeConservative)" "YES"
46 GhcRtsCcOpts += -DBE_CONSERVATIVE
47 endif
48
49 # -----------------------------------------------------------------------------
50
51 # There's nothing for Haddock here...
52 override HADDOCK_DOCS = NO
53
54 # -----------------------------------------------------------------------------
55
56 # Tells the build system not to add various Haskellish options to $(SRC_HC_OPTS)
57 NON_HS_PACKAGE = YES
58
59 # grab sources from these subdirectories
60 ALL_DIRS = hooks parallel sm
61
62 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
63 ALL_DIRS += win32
64 else
65 ALL_DIRS += posix
66 endif
67
68 ifneq "$(findstring dyn, $(way))" ""
69 DYNAMIC_RTS=YES
70 else
71 DYNAMIC_RTS=NO
72 endif
73
74 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
75 EXCLUDED_SRCS += Main.c
76 # It's not included in the DLL, but we need to compile it up separately.
77
78 all :: Main.$(way_)o
79 INSTALL_LIBS += Main.$(way_)o
80 else
81 EXCLUDED_SRCS += RtsDllMain.c
82 endif
83
84 # This file ends up being empty unless we're building for a powerpc
85 # or darwin system, and it is reported that Solaris ld chokes on it when
86 # building HSrts.o.
87 ifeq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
88 ifeq "$(findstring $(TargetOS_CPP), darwin)" ""
89 EXCLUDED_SRCS += AdjustorAsm.S
90 endif
91 endif
92
93 EXCLUDED_SRCS += parallel/SysMan.c
94
95 EXCLUDED_SRCS += dyn-wrapper.c
96
97 # compile generic patchable dyn-wrapper
98
99 DYNWRAPPER_SRC = dyn-wrapper.c
100 DYNWRAPPER_PROG = dyn-wrapper$(exeext)
101 $(DYNWRAPPER_PROG): $(DYNWRAPPER_SRC)
102         $(HC) -cpp -optc-include -optcdyn-wrapper-patchable-behaviour.h $(INPLACE_EXTRA_FLAGS) $< -o $@
103
104 # The build system doesn't give us these
105 CMM_SRCS = $(filter-out AutoApply%.cmm, $(wildcard *.cmm)) $(EXTRA_CMM_SRCS)
106 CMM_OBJS = $(patsubst %.cmm,%.$(way_)o, $(CMM_SRCS))
107
108 CLEAN_FILES += $(CMM_OBJS)
109
110 # Override the default $(LIBOBJS) (defaults to $(HS_OBJS))
111 LIBOBJS = $(C_OBJS) $(CMM_OBJS)
112
113 SplitObjs=NO
114
115 H_FILES = $(wildcard ../includes/*.h) $(wildcard *.h)
116
117 #-----------------------------------------------------------------------------
118 # Flags for compiling RTS .c and .hc files
119
120 # gcc provides lots of useful warnings if you ask it.
121 # This is a pretty good list to start with - use a # to comment out
122 # any you don't like.
123 WARNING_OPTS += -Wall
124 WARNING_OPTS += -W
125 WARNING_OPTS += -Wstrict-prototypes 
126 WARNING_OPTS += -Wmissing-prototypes 
127 WARNING_OPTS += -Wmissing-declarations
128 WARNING_OPTS += -Winline
129 WARNING_OPTS += -Waggregate-return
130 #WARNING_OPTS += -Wpointer-arith
131 #WARNING_OPTS += -Wbad-function-cast
132 #WARNING_OPTS += -Wcast-align
133 #WARNING_OPTS += -Wnested-externs
134 #WARNING_OPTS += -Wshadow
135 #WARNING_OPTS += -Wcast-qual
136 #WARNING_OPTS += -Wno-unused 
137 #WARNING_OPTS += -Wredundant-decls 
138 #WARNING_OPTS += -Wconversion
139
140 STANDARD_OPTS += -I../includes -I. -Iparallel -Ism
141 # COMPILING_RTS is only used when building Win32 DLL support.
142 STANDARD_OPTS += -DCOMPILING_RTS
143
144 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
145 # only included in .c compilations.  HC_OPTS included the WAY_* opts, which
146 # must be included in both types of compilations.
147
148 SRC_CC_OPTS += $(WARNING_OPTS)
149 SRC_CC_OPTS += $(STANDARD_OPTS)
150
151 SRC_CC_OPTS += $(GhcRtsCcOpts)
152 SRC_HC_OPTS += $(GhcRtsHcOpts) $(STANDARD_OPTS) -package-name rts
153
154 ifneq "$(GhcWithSMP)" "YES"
155 SRC_CC_OPTS += -DNOSMP
156 SRC_HC_OPTS += -optc-DNOSMP
157 endif
158
159 ifeq "$(UseLibFFIForAdjustors)" "YES"
160 SRC_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
161 endif
162
163 ifeq "$(Windows)" "YES"
164 # SDM: when compiled with -fasm the RTS currently has bogus references to 
165 # __imp_base_ things, so working around for now:
166 SRC_HC_OPTS = -fvia-C
167 endif
168
169 ifneq "$(DYNAMIC_RTS)" "YES"
170 SRC_HC_OPTS += -static
171 else
172 LIB_LD_OPTS += -ignore-package base -ignore-package rts
173 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
174 LIB_DEPS=buildbase
175 .PHONY: buildbase
176
177 BASE_DIST_LIB=$(TOP)/libraries/base/dist/build
178
179 # The following must be a one liner otherwise its evaluation won't be delayed until base/rts packages are properly registered
180 LIB_LD_OPTS = $(foreach lib,$(shell $(GHC_PKG_INPLACE) field base hs-libraries | sed -e 's/hs-libraries: //'),"-l$(lib)-ghc$(ProjectVersion)$(soext)") $(foreach lib,$(shell $(GHC_PKG_INPLACE) field rts extra-libraries | sed -e s/extra-libraries://),"-l$(lib)") $(foreach libdir,$(shell $(GHC_PKG_INPLACE) field base library-dirs | sed -e 's/library-dirs: //' | sed -e s,\\\\,/,g) $(shell $(GHC_PKG_INPLACE) field rts library-dirs | sed -e s/library-dirs:// | sed -e s/\\\\/\\\\\\\\/g),"-L$(libdir)")
181 endif
182 endif
183
184 # Mac OS X: make sure we compile for the right OS version
185 SRC_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
186 SRC_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
187 LIB_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
188
189 # XXX DQ is now the same on all platforms, so get rid of it
190 DQ = \"
191
192 # If Main.c is built with optimisation then the SEH exception stuff on
193 # Windows gets confused.
194 # This has to be in HC rather than CC opts, as otherwise there's a
195 # -optc-O2 that comes after it.
196 Main_HC_OPTS += -optc-O0
197
198 RtsMessages_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
199 RtsUtils_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
200 RtsUtils_CC_OPTS += -DRtsWay=$(DQ)rts$(_way)$(DQ)
201 #
202 RtsUtils_CC_OPTS += -DHostPlatform=$(DQ)$(HOSTPLATFORM)$(DQ)
203 RtsUtils_CC_OPTS += -DHostArch=$(DQ)$(HostArch_CPP)$(DQ)
204 RtsUtils_CC_OPTS += -DHostOS=$(DQ)$(HostOS_CPP)$(DQ)
205 RtsUtils_CC_OPTS += -DHostVendor=$(DQ)$(HostVendor_CPP)$(DQ)
206 #
207 RtsUtils_CC_OPTS += -DBuildPlatform=$(DQ)$(BUILDPLATFORM)$(DQ)
208 RtsUtils_CC_OPTS += -DBuildArch=$(DQ)$(BuildArch_CPP)$(DQ)
209 RtsUtils_CC_OPTS += -DBuildOS=$(DQ)$(BuildOS_CPP)$(DQ)
210 RtsUtils_CC_OPTS += -DBuildVendor=$(DQ)$(BuildVendor_CPP)$(DQ)
211 #
212 RtsUtils_CC_OPTS += -DTargetPlatform=$(DQ)$(TARGETPLATFORM)$(DQ)
213 RtsUtils_CC_OPTS += -DTargetArch=$(DQ)$(TargetArch_CPP)$(DQ)
214 RtsUtils_CC_OPTS += -DTargetOS=$(DQ)$(TargetOS_CPP)$(DQ)
215 RtsUtils_CC_OPTS += -DTargetVendor=$(DQ)$(TargetVendor_CPP)$(DQ)
216 #
217 RtsUtils_CC_OPTS += -DGhcUnregisterised=$(DQ)$(GhcUnregisterised)$(DQ)
218 RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=$(DQ)$(GhcEnableTablesNextToCode)$(DQ)
219
220 # ffi.h triggers prototype warnings, so disable them here:
221 Interpreter_CC_OPTS += -Wno-strict-prototypes
222 Adjustor_CC_OPTS += -Wno-strict-prototypes
223 sm/Storage_CC_OPTS += -Wno-strict-prototypes
224
225 StgCRun_CC_OPTS += -w
226 Typeable_CC_OPTS += -w
227 RetainerProfile_CC_OPTS += -w
228 sm/Compact_CC_OPTS += -w
229 # On Windows:
230 win32/ConsoleHandler_CC_OPTS += -w
231 win32/ThrIOManager_CC_OPTS += -w
232 win32/Ticker_CC_OPTS += -w
233 # The above warning supression flags are a temporary kludge.
234 # While working on this module you are encouraged to remove it and fix
235 # any warnings in the module. See
236 #     http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
237 # for details
238
239 ifeq "$(way)" "mp"
240 SRC_HC_OPTS += -I$$PVM_ROOT/include
241 endif
242
243 # If -DDEBUG is in effect, adjust package conf accordingly..
244 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
245 PACKAGE_CPP_OPTS += -DDEBUG
246 endif
247
248 ifeq "$(HaveLibMingwEx)" "YES"
249 PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
250 endif
251
252 ifeq "$(GhciWithDebugger)" "YES"
253 STANDARD_OPTS += -DDEBUGGER
254 endif
255
256 ifeq "$(DotnetSupport)" "YES"
257
258
259 # Would like to just use SUBDIRS here, but need to
260 # descend into dotnet/ earlier than that.
261 #
262 all ::
263         $(MAKE) -C dotnet all
264
265 # But use SUBDIRS for other recursive targets.
266 SUBDIRS += dotnet
267
268 LIBOBJS += dotnet/Invoke.o
269 endif
270
271 # Suppress uninitialized variable warnings for GC.c
272 GC_CC_OPTS      += -Wno-uninitialized
273
274 #-----------------------------------------------------------------------------
275 # Include the Front panel code?
276
277 # we need GTK+ for the front panel
278 ifneq "$(GTK_CONFIG)" ""
279 ifeq "$(GhcRtsWithFrontPanel)" "YES"
280 SRC_HC_OPTS             += `$(GTK_CONFIG) --cflags` -optc-DRTS_GTK_FRONTPANEL
281 VisCallbacks_CC_OPTS    += -Wno-unused
282 SRC_MKDEPENDC_OPTS      += `$(GTK_CONFIG) --cflags`
283 else # GhcRtsWithFrontPanel
284 EXCLUDED_SRCS           += $(wildcard Vis*.c)
285 endif
286 else # GTK_CONFIG
287 EXCLUDED_SRCS           += $(wildcard Vis*.c)
288 endif
289
290 #-----------------------------------------------------------------------------
291 # Add PAPI library if needed
292
293 ifeq "$(GhcRtsWithPapi)" "YES"
294
295 SRC_CC_OPTS             += -DUSE_PAPI
296 PACKAGE_CPP_OPTS        += -DUSE_PAPI
297
298 PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=$(PapiIncludeDir)
299 PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=$(PapiLibDir)
300
301 ifneq "$(PapiIncludeDir)" ""
302 SRC_HC_OPTS += -I$(PapiIncludeDir)
303 SRC_CC_OPTS += -I$(PapiIncludeDir)
304 SRC_HSC2HS_OPTS += -I$(PapiIncludeDir)
305 endif
306 ifneq "$(PapiLibDirs)" ""
307 SRC_LD_OPTS += -L$(PapiLibDirs)
308 endif
309
310 else # GhcRtsWithPapi==YES
311
312 PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=""
313
314 endif
315
316 #-----------------------------------------------------------------------------
317 # make depend setup
318
319 SRC_MKDEPENDC_OPTS += -I. -I../includes
320
321 # Hack: we define every way-related option here, so that we get (hopefully)
322 # a superset of the dependencies.  To do this properly, we should generate
323 # a different set of dependencies for each way.  Further hack: PROFILING and
324 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
325 SRC_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
326
327 # -----------------------------------------------------------------------------
328 # The auto-generated apply code
329
330 # We want a slightly different version for the unregisterised way, so we make
331 # AutoApply on a per-way basis (eg. AutoApply_p.cmm).
332
333 ifneq "$(DOING_BIN_DIST)" "YES"
334
335 AUTO_APPLY_CMM = AutoApply$(_way).cmm
336
337 ifneq "$(BootingFromHc)" "YES"
338 $(AUTO_APPLY_CMM): $(GHC_GENAPPLY)
339         @$(RM) $@
340         $(GENAPPLY) $(if $(filter $(way), u debug_u), -u) >$@
341 endif
342
343 EXTRA_CMM_SRCS += $(AUTO_APPLY_CMM)
344
345 CLEAN_FILES += $(AUTO_APPLY_CMM)
346
347 endif
348
349 # -----------------------------------------------------------------------------
350
351 # Need to get the GMP vars in through CPP to package.conf.in, and put
352 # quotes around each element.
353
354 empty =
355 space = $(empty) $(empty)
356 comma = ,
357 PACKAGE_CPP_OPTS += -DGMP_INCLUDE_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_INCLUDE_DIRS))))'
358 PACKAGE_CPP_OPTS += -DGMP_LIB_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_LIB_DIRS))))'
359
360 ifneq "$(GMP_INCLUDE_DIRS)" ""
361 SRC_HC_OPTS += -I$(GMP_INCLUDE_DIRS)
362 SRC_CC_OPTS += -I$(GMP_INCLUDE_DIRS)
363 SRC_HSC2HS_OPTS += -I$(GMP_INCLUDE_DIRS)
364 endif
365 ifneq "$(GMP_LIB_DIRS)" ""
366 SRC_LD_OPTS += -L$(GMP_LIB_DIRS)
367 endif
368
369 SRC_CC_OPTS += -I../gmp/gmpbuild
370 SRC_HC_OPTS += -I../gmp/gmpbuild
371 SRC_HSC2HS_OPTS += -I../gmp/gmpbuild
372 SRC_LD_OPTS += -L../gmp/gmpbuild
373
374 #-----------------------------------------------------------------------------
375 # libffi stuff
376
377 SRC_CC_OPTS     += -I../libffi/build/include
378 SRC_HC_OPTS     += -I../libffi/build/include
379 SRC_HSC2HS_OPTS += -I../libffi/build/include
380 SRC_LD_OPTS     += -L../libffi/build/include
381
382 #-----------------------------------------------------------------------------
383 #
384 # Building the GUM SysMan
385 #
386
387 ifeq "$(way)" "mp"
388 all :: parallel/SysMan
389
390 ifdef solaris2_TARGET_OS
391 __socket_libs = -lsocket -lnsl
392 else
393 __socket_libs =
394 endif
395
396 parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
397         $(RM) $@
398         gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
399
400 CLEAN_FILES  += parallel/SysMan.mp_o parallel/SysMan
401 INSTALL_LIBEXECS += parallel/SysMan
402 endif
403
404 #-----------------------------------------------------------------------------
405 # Compiling the cmm files
406
407 # ToDo: should we really include Rts.h here?  Required for GNU_ATTRIBUTE().
408 SRC_HC_OPTS += -I.
409
410 # Otherwise the stack-smash handler gets triggered.
411 ifeq "$(TargetOS_CPP)" "openbsd"
412 SRC_HC_OPTS += -optc-fno-stack-protector
413 endif
414
415 # -O3 helps unroll some loops (especially in copy() with a constant argument).
416 sm/Evac_HC_OPTS += -optc-funroll-loops
417
418 ifneq "$(findstring thr, $(way))" ""
419 EXTRA_SRCS += sm/Evac_thr.c sm/Scav_thr.c
420 CLEAN_FILES += sm/Evac_thr.c sm/Scav_thr.c
421
422 sm/Evac_thr.c : sm/Evac.c
423         cp $< $@
424 sm/Scav_thr.c : sm/Scav.c
425         cp $< $@
426
427 sm/Evac_thr_HC_OPTS += -optc-DPARALLEL_GC
428 sm/Scav_thr_HC_OPTS += -optc-DPARALLEL_GC
429 else
430 EXCLUDED_SRCS += sm/Evac_thr.c sm/Scav_thr.c
431 endif
432
433 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
434 sm/Compact_HC_OPTS += -optc-finline-limit=2500
435
436 # -fno-strict-aliasing is required for the runtime, because we often
437 # use a variety of types to represent closure pointers (StgPtr,
438 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
439 # allowed to assume that these pointers do not alias.  eg. without
440 # this flag we get problems in sm/Evac.c:copy() with gcc 3.4.3, the
441 # upd_evacee() assigments get moved before the object copy.
442 SRC_CC_OPTS += -fno-strict-aliasing
443
444 # We *want* type-checking of hand-written cmm.
445 SRC_HC_OPTS += -dcmm-lint 
446
447 ifneq "$(BootingFromHc)" "YES"
448 # .cmm files depend on all the .h files, to a first approximation.
449 %.$(way_)o : %.cmm $(H_FILES)
450         $(HC_PRE_OPTS)
451         $(HC) $(HC_OPTS) -c $< -o $@
452         $(HC_POST_OPTS)
453
454 %.$(way_)hc : %.cmm $(H_FILES)
455         $(HC) $(HC_OPTS) -C $< -o $@
456
457 %.$(way_)s : %.cmm $(H_FILES)
458         $(HC) $(HC_OPTS) -S $< -o $@
459 endif
460
461 #-----------------------------------------------------------------------------
462 #
463 # Files to install
464 #
465 # Just libHSrts is installed uniformly across ways
466 #
467
468 include $(TOP)/mk/target.mk
469
470 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
471 # $(LIBRARY).a is not the static library libHSrts.a but
472 # libHSrts.dll.a, the import library for dynamic linking required for
473 # linking the dynamic version of base
474 buildbase: $(LIBRARY).a
475         $(MAKE) way="" -C ../libraries/ make.library.ghc-prim
476         $(MAKE) way="" -C ../libraries/ make.library.integer-gmp
477         $(MAKE) way="" -C ../libraries/ make.library.base
478 endif
479
480 #-----------------------------------------------------------------------------
481 #
482 # binary-dist
483
484 BINDIST_EXTRAS += package.conf.in
485 BINDIST_EXTRAS += $(INSTALL_LIBS)
486 BINDIST_EXTRAS += $(INSTALL_LIBEXECS)
487
488 # Setting _way here is a nasty hack to make sure we get libHSrts*.a etc
489 # rather than just libHSrts.a when we are making bindists.
490 binary-dist: _way=*
491
492 include $(TOP)/mk/bindist.mk
493