1 # -----------------------------------------------------------------------------
3 # (c) 2009 The University of Glasgow
5 # This file is part of the GHC build system.
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
11 # -----------------------------------------------------------------------------
13 # -----------------------------------------------------------------------------
16 # We build the RTS with stage 1
17 rts_dist_HC = $(GHC_STAGE1)
19 # merge GhcLibWays and GhcRTSWays but strip out duplicates
20 rts_WAYS = $(GhcLibWays) $(filter-out $(GhcLibWays),$(GhcRTSWays))
21 rts_dist_WAYS = $(rts_WAYS)
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)
27 # -----------------------------------------------------------------------------
28 # Defining the sources
30 ALL_DIRS = hooks parallel sm eventlog
32 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
38 EXCLUDED_SRCS += rts/Main.c
39 EXCLUDED_SRCS += rts/parallel/SysMan.c
40 EXCLUDED_SRCS += $(wildcard rts/Vis*.c)
42 rts_C_SRCS = $(filter-out $(EXCLUDED_SRCS),$(wildcard rts/*.c $(foreach dir,$(ALL_DIRS),rts/$(dir)/*.c)))
43 rts_CMM_SRCS = $(wildcard rts/*.cmm)
45 # Don't compile .S files when bootstrapping a new arch
46 ifneq "$(PORTING_HOST)" "YES"
47 ifneq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
48 rts_S_SRCS += rts/AdjustorAsm.S
50 ifneq "$(findstring $(TargetOS_CPP), darwin)" ""
51 rts_S_SRCS += rts/AdjustorAsm.S
56 ifeq "$(GhcUnregisterised)" "YES"
60 rts_AUTO_APPLY_CMM = rts/dist/build/AutoApply.cmm
62 $(rts_AUTO_APPLY_CMM): $(GENAPPLY_INPLACE)
63 "$(GENAPPLY_INPLACE)" >$@
65 rts/dist/build/sm/Evac_thr.c : rts/sm/Evac.c | $$(dir $$@)/.
67 rts/dist/build/sm/Scav_thr.c : rts/sm/Scav.c | $$(dir $$@)/.
70 rts_H_FILES = $(wildcard includes/*.h) $(wildcard rts/*.h)
72 ifeq "$(HaveDtrace)" "YES"
73 DTRACEPROBES_H = rts/dist/build/RtsProbes.h
74 rts_H_FILES += $(DTRACEPROBES_H)
77 # collect the -l flags that we need to link the rts dyn lib.
78 rts/libs.depend : $(GHC_PKG_INPLACE)
79 "$(GHC_PKG_INPLACE)" field rts extra-libraries \
80 | sed -e 's/^extra-libraries: //' -e 's/\([a-z0-9]*\)[ ]*/-l\1 /g' > $@
83 # ----------------------------------------------------------------------------
84 # On Windows, as the RTS and base libraries have recursive imports,
85 # we have to break the loop with "import libraries".
86 # These are made from rts/win32/libHS*.def which contain lists of
87 # all the symbols in those libraries used by the RTS.
89 ifneq "$$(findstring dyn, $1)" ""
90 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
92 ALL_RTS_DEF_LIBNAMES = base ghc-prim
94 rts/dist/build/win32/libHSbase.dll.a \
95 rts/dist/build/win32/libHSghc-prim.dll.a \
96 rts/dist/build/win32/libHSffi.dll.a
98 # -- import libs for the regular Haskell libraries
99 define make-importlib-def # args $1 = lib name
100 rts/dist/build/win32/libHS$1.def : rts/win32/libHS$1.def
101 cat rts/win32/libHS$1.def \
102 | sed "s/@LibVersion@/$$(libraries/$1_dist-install_VERSION)/" \
103 | sed "s/@ProjectVersion@/$(ProjectVersion)/" \
104 > rts/dist/build/win32/libHS$1.def
106 rts/dist/build/win32/libHS$1.dll.a : rts/dist/build/win32/libHS$1.def
107 "$$(DLLTOOL)" -d rts/dist/build/win32/libHS$1.def \
108 -l rts/dist/build/win32/libHS$1.dll.a
110 $(foreach lib,$(ALL_RTS_DEF_LIBNAMES),$(eval $(call make-importlib-def,$(lib))))
113 # -- import libs for libffi
114 rts/dist/build/win32/libHSffi.def : rts/win32/libHSffi.def
115 cat rts/win32/libHSffi.def \
116 | sed "s/@ProjectVersion@/$(ProjectVersion)/" \
117 > rts/dist/build/win32/libHSffi.def
119 rts/dist/build/win32/libHSffi.dll.a : rts/dist/build/win32/libHSffi.def
120 "$(DLLTOOL)" -d rts/dist/build/win32/libHSffi.def \
121 -l rts/dist/build/win32/libHSffi.dll.a
126 #-----------------------------------------------------------------------------
128 define build-rts-way # args: $1 = way
130 ifneq "$$(BINDIST)" "YES"
132 # The per-way CC_OPTS
133 ifneq "$$(findstring debug, $1)" ""
134 rts_dist_$1_HC_OPTS =
135 rts_dist_$1_CC_OPTS = -g -O0
137 rts_dist_$1_HC_OPTS = $$(GhcRtsHcOpts)
138 rts_dist_$1_CC_OPTS = $$(GhcRtsCcOpts)
141 ifneq "$$(findstring thr, $1)" ""
142 rts_$1_EXTRA_C_SRCS = rts/dist/build/sm/Evac_thr.c rts/dist/build/sm/Scav_thr.c
145 $(call distdir-way-opts,rts,dist,$1)
146 $(call c-suffix-rules,rts,dist,$1,YES)
147 $(call cmm-suffix-rules,rts,dist,$1)
148 $(call hs-suffix-rules-srcdir,rts,dist,$1,$$(dir))
149 # hs-suffix-rules-srcdir is needed when BootingFromHc to get the .hc rules
151 rts_$1_LIB_NAME = libHSrts$$($1_libsuf)
152 rts_$1_LIB = rts/dist/build/$$(rts_$1_LIB_NAME)
154 rts_$1_C_OBJS = $$(patsubst rts/%.c,rts/dist/build/%.$$($1_osuf),$$(rts_C_SRCS)) $$(patsubst %.c,%.$$($1_osuf),$$(rts_$1_EXTRA_C_SRCS))
155 rts_$1_S_OBJS = $$(patsubst rts/%.S,rts/dist/build/%.$$($1_osuf),$$(rts_S_SRCS))
156 rts_$1_CMM_OBJS = $$(patsubst rts/%.cmm,rts/dist/build/%.$$($1_osuf),$$(rts_CMM_SRCS)) $$(patsubst %.cmm,%.$$($1_osuf),$$(rts_AUTO_APPLY_CMM))
158 rts_$1_OBJS = $$(rts_$1_C_OBJS) $$(rts_$1_S_OBJS) $$(rts_$1_CMM_OBJS)
160 rts_dist_$1_CC_OPTS += -DRtsWay=\"rts_$1\"
162 # Making a shared library for the RTS.
163 ifneq "$$(findstring dyn, $1)" ""
164 ifeq "$$(HOSTPLATFORM)" "i386-unknown-mingw32"
165 $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/libs.depend
166 "$$(RM)" $$(RM_OPTS) $$@
167 "$$(rts_dist_HC)" -package-name rts -shared -dynamic -dynload deploy \
168 -no-auto-link-packages `cat rts/libs.depend` $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) -o $$@
170 $$(rts_$1_LIB) : $$(rts_$1_OBJS) rts/libs.depend
171 "$$(RM)" $$(RM_OPTS) $$@
172 "$$(rts_dist_HC)" -package-name rts -shared -dynamic -dynload deploy \
173 -no-auto-link-packages `cat rts/libs.depend` $$(rts_$1_OBJS) -o $$@
174 ifeq "$$(darwin_HOST_OS)" "1"
175 # Ensure library's install name is correct before anyone links with it.
176 install_name_tool -id $(ghclibdir)/$$(rts_$1_LIB_NAME) $$@
180 $$(rts_$1_LIB) : $$(rts_$1_OBJS)
181 "$$(RM)" $$(RM_OPTS) $$@
182 echo $$(rts_$1_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR)" $$(AR_OPTS) $$(EXTRA_AR_ARGS) $$@
189 # And expand the above for each way:
190 $(foreach way,$(rts_WAYS),$(eval $(call build-rts-way,$(way))))
192 #-----------------------------------------------------------------------------
193 # Flags for compiling every file
195 # We like plenty of warnings.
196 WARNING_OPTS += -Wall
197 ifeq "$(GccLT34)" "YES"
200 WARNING_OPTS += -Wextra
202 WARNING_OPTS += -Wstrict-prototypes
203 WARNING_OPTS += -Wmissing-prototypes
204 WARNING_OPTS += -Wmissing-declarations
205 WARNING_OPTS += -Winline
206 WARNING_OPTS += -Waggregate-return
207 WARNING_OPTS += -Wpointer-arith
208 WARNING_OPTS += -Wmissing-noreturn
209 WARNING_OPTS += -Wnested-externs
210 WARNING_OPTS += -Wredundant-decls
212 # These ones are hard to avoid:
213 #WARNING_OPTS += -Wconversion
214 #WARNING_OPTS += -Wbad-function-cast
215 #WARNING_OPTS += -Wshadow
216 #WARNING_OPTS += -Wcast-qual
218 # This one seems buggy on GCC 4.1.2, which is the only GCC version we
219 # have that can bootstrap the SPARC build. We end up with lots of supurious
220 # warnings of the form "cast increases required alignment of target type".
221 # Some legitimate warnings can be fixed by adding an intermediate cast to
222 # (void*), but we get others in rts/sm/GCUtils.c concerning the gct var
223 # that look innocuous to me. We could enable this again once we deprecate
224 # support for registerised builds on this arch. -- BL 2010/02/03
225 # WARNING_OPTS += -Wcast-align
227 STANDARD_OPTS += -Iincludes -Irts
228 # COMPILING_RTS is only used when building Win32 DLL support.
229 STANDARD_OPTS += -DCOMPILING_RTS
231 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
232 # only included in .c compilations. HC_OPTS included the WAY_* opts, which
233 # must be included in both types of compilations.
235 rts_CC_OPTS += $(WARNING_OPTS)
236 rts_CC_OPTS += $(STANDARD_OPTS)
238 rts_HC_OPTS += $(STANDARD_OPTS) -package-name rts
240 ifneq "$(GhcWithSMP)" "YES"
241 rts_CC_OPTS += -DNOSMP
242 rts_HC_OPTS += -optc-DNOSMP
245 ifeq "$(UseLibFFIForAdjustors)" "YES"
246 rts_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
249 # Mac OS X: make sure we compile for the right OS version
250 rts_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
251 rts_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
252 rts_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
254 # We *want* type-checking of hand-written cmm.
255 rts_HC_OPTS += -dcmm-lint
257 # -fno-strict-aliasing is required for the runtime, because we often
258 # use a variety of types to represent closure pointers (StgPtr,
259 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
260 # allowed to assume that these pointers do not alias. eg. without
261 # this flag we get problems in sm/Evac.c:copy() with gcc 3.4.3, the
262 # upd_evacee() assigments get moved before the object copy.
263 rts_CC_OPTS += -fno-strict-aliasing
265 rts_CC_OPTS += -fno-common
267 ifeq "$(BeConservative)" "YES"
268 rts_CC_OPTS += -DBE_CONSERVATIVE
271 #-----------------------------------------------------------------------------
272 # Flags for compiling specific files
274 # If RtsMain.c is built with optimisation then the SEH exception stuff on
275 # Windows gets confused.
276 # This has to be in HC rather than CC opts, as otherwise there's a
277 # -optc-O2 that comes after it.
278 rts/RtsMain_HC_OPTS += -optc-O0
280 rts/RtsMessages_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
281 rts/RtsUtils_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
283 rts/RtsUtils_CC_OPTS += -DHostPlatform=\"$(HOSTPLATFORM)\"
284 rts/RtsUtils_CC_OPTS += -DHostArch=\"$(HostArch_CPP)\"
285 rts/RtsUtils_CC_OPTS += -DHostOS=\"$(HostOS_CPP)\"
286 rts/RtsUtils_CC_OPTS += -DHostVendor=\"$(HostVendor_CPP)\"
288 rts/RtsUtils_CC_OPTS += -DBuildPlatform=\"$(BUILDPLATFORM)\"
289 rts/RtsUtils_CC_OPTS += -DBuildArch=\"$(BuildArch_CPP)\"
290 rts/RtsUtils_CC_OPTS += -DBuildOS=\"$(BuildOS_CPP)\"
291 rts/RtsUtils_CC_OPTS += -DBuildVendor=\"$(BuildVendor_CPP)\"
293 rts/RtsUtils_CC_OPTS += -DTargetPlatform=\"$(TARGETPLATFORM)\"
294 rts/RtsUtils_CC_OPTS += -DTargetArch=\"$(TargetArch_CPP)\"
295 rts/RtsUtils_CC_OPTS += -DTargetOS=\"$(TargetOS_CPP)\"
296 rts/RtsUtils_CC_OPTS += -DTargetVendor=\"$(TargetVendor_CPP)\"
298 rts/RtsUtils_CC_OPTS += -DGhcUnregisterised=\"$(GhcUnregisterised)\"
299 rts/RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=\"$(GhcEnableTablesNextToCode)\"
301 # Compile various performance-critical pieces *without* -fPIC -dynamic
302 # even when building a shared library. If we don't do this, then the
303 # GC runs about 50% slower on x86 due to the overheads of PIC. The
304 # cost of doing this is a little runtime linking and less sharing, but
307 # On x86_64 this doesn't work, because all objects in a shared library
308 # must be compiled with -fPIC (since the 32-bit relocations generated
309 # by the default small memory can't be resolved at runtime). So we
310 # only do this on i386.
312 # This apparently doesn't work on OS X (Darwin) where we get errors of
315 # 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
317 # and lots of these warnings:
319 # ld: warning codegen in _stg_ap_pppv_fast (offset 0x0000005E) prevents image from loading in dyld shared cache
321 ifeq "$(TargetArch_CPP)" "i386"
322 ifneq "$(TargetOS_CPP)" "darwin"
323 rts/sm/Evac_HC_OPTS += -fno-PIC
324 rts/sm/Evac_thr_HC_OPTS += -fno-PIC
325 rts/sm/Scav_HC_OPTS += -fno-PIC
326 rts/sm/Scav_thr_HC_OPTS += -fno-PIC
327 rts/sm/Compact_HC_OPTS += -fno-PIC
328 rts/sm/GC_HC_OPTS += -fno-PIC
330 # -static is also necessary for these bits, otherwise the NCG
331 # -generates dynamic references:
332 rts/Updates_HC_OPTS += -fno-PIC -static
333 rts/StgMiscClosures_HC_OPTS += -fno-PIC -static
334 rts/PrimOps_HC_OPTS += -fno-PIC -static
335 rts/Apply_HC_OPTS += -fno-PIC -static
336 rts/dist/build/AutoApply_HC_OPTS += -fno-PIC -static
340 # ffi.h triggers prototype warnings, so disable them here:
341 rts/Interpreter_CC_OPTS += -Wno-strict-prototypes
342 rts/Adjustor_CC_OPTS += -Wno-strict-prototypes
343 rts/sm/Storage_CC_OPTS += -Wno-strict-prototypes
345 # inlining warnings happen in Compact
346 rts/sm/Compact_CC_OPTS += -Wno-inline
348 # emits warnings about call-clobbered registers on x86_64
349 rts/StgCRun_CC_OPTS += -w
351 rts/RetainerProfile_CC_OPTS += -w
352 rts/RetainerSet_CC_OPTS += -Wno-format
354 rts/win32/ConsoleHandler_CC_OPTS += -w
355 rts/win32/ThrIOManager_CC_OPTS += -w
356 # The above warning supression flags are a temporary kludge.
357 # While working on this module you are encouraged to remove it and fix
358 # any warnings in the module. See
359 # http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
362 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
363 rts/sm/Compact_CC_OPTS += -finline-limit=2500
365 # -O3 helps unroll some loops (especially in copy() with a constant argument).
366 rts/sm/Evac_CC_OPTS += -funroll-loops
367 rts/dist/build/sm/Evac_thr_HC_OPTS += -optc-funroll-loops
369 # These files are just copies of sm/Evac.c and sm/Scav.c respectively,
370 # but compiled with -DPARALLEL_GC.
371 rts/dist/build/sm/Evac_thr_CC_OPTS += -DPARALLEL_GC -Irts/sm
372 rts/dist/build/sm/Scav_thr_CC_OPTS += -DPARALLEL_GC -Irts/sm
374 #-----------------------------------------------------------------------------
375 # Add PAPI library if needed
377 ifeq "$(GhcRtsWithPapi)" "YES"
379 rts_CC_OPTS += -DUSE_PAPI
381 rts_PACKAGE_CPP_OPTS += -DUSE_PAPI
382 rts_PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=$(PapiIncludeDir)
383 rts_PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=$(PapiLibDir)
385 ifneq "$(PapiIncludeDir)" ""
386 rts_HC_OPTS += -I$(PapiIncludeDir)
387 rts_CC_OPTS += -I$(PapiIncludeDir)
388 rts_HSC2HS_OPTS += -I$(PapiIncludeDir)
390 ifneq "$(PapiLibDirs)" ""
391 rts_LD_OPTS += -L$(PapiLibDirs)
394 else # GhcRtsWithPapi==YES
396 rts_PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=""
397 rts_PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=""
401 # -----------------------------------------------------------------------------
404 rts_WAYS_DASHED = $(subst $(space),,$(patsubst %,-%,$(strip $(rts_WAYS))))
405 rts_dist_depfile_base = rts/dist/build/.depend$(rts_WAYS_DASHED)
407 rts_dist_C_SRCS = $(rts_C_SRCS) $(rts_thr_EXTRA_C_SRCS)
408 rts_dist_S_SRCS = $(rts_S_SRCS)
409 rts_dist_C_FILES = $(rts_C_SRCS) $(rts_thr_EXTRA_C_SRCS) $(rts_S_SRCS)
411 # Hack: we define every way-related option here, so that we get (hopefully)
412 # a superset of the dependencies. To do this properly, we should generate
413 # a different set of dependencies for each way. Further hack: PROFILING an
415 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
416 rts_dist_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
418 ifeq "$(HaveDtrace)" "YES"
420 rts_dist_MKDEPENDC_OPTS += -Irts/dist/build
424 $(eval $(call build-dependencies,rts,dist,1))
426 $(rts_dist_depfile_c_asm) : libffi/dist-install/build/ffi.h $(DTRACEPROBES_H)
428 #-----------------------------------------------------------------------------
431 rts_CC_OPTS += -Ilibffi/build/include
432 rts_HC_OPTS += -Ilibffi/build/include
433 rts_HSC2HS_OPTS += -Ilibffi/build/include
434 rts_LD_OPTS += -Llibffi/build/include
436 # -----------------------------------------------------------------------------
437 # compile dtrace probes if dtrace is supported
439 ifeq "$(HaveDtrace)" "YES"
441 rts_CC_OPTS += -DDTRACE
442 rts_HC_OPTS += -DDTRACE
444 DTRACEPROBES_SRC = rts/RtsProbes.d
445 $(DTRACEPROBES_H): $(DTRACEPROBES_SRC) includes/ghcplatform.h | $(dir $@)/.
446 "$(DTRACE)" $(filter -I%,$(rts_CC_OPTS)) -C -h -o $@ -s $<
450 # -----------------------------------------------------------------------------
451 # build the static lib containing the C main symbol
453 ifneq "$(BINDIST)" "YES"
454 rts/dist/build/libHSrtsmain.a : rts/dist/build/Main.o
455 "$(RM)" $(RM_OPTS) $@
456 "$(AR)" $(AR_OPTS) $(EXTRA_AR_ARGS) $@ $<
459 # -----------------------------------------------------------------------------
460 # The RTS package config
462 # If -DDEBUG is in effect, adjust package conf accordingly..
463 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
464 rts_PACKAGE_CPP_OPTS += -DDEBUG
467 ifeq "$(HaveLibMingwEx)" "YES"
468 rts_PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
471 $(eval $(call manual-package-config,rts))
473 ifneq "$(BootingFromHc)" "YES"
474 rts/package.conf.inplace : $(includes_H_CONFIG) $(includes_H_PLATFORM)
477 # -----------------------------------------------------------------------------
480 INSTALL_LIBS += $(ALL_RTS_LIBS)
482 # -----------------------------------------------------------------------------
485 $(eval $(call clean-target,rts,dist,rts/dist))
487 BINDIST_EXTRAS += rts/package.conf.in
488 BINDIST_EXTRAS += $(ALL_RTS_LIBS)