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))
22 ALL_RTS_LIBS = $(foreach way,$(rts_WAYS),rts/dist/build/libHSrts$($(way)_libsuf)) \
23 rts/dist/build/libHSrtsmain.a
24 all_rts : $(ALL_RTS_LIBS)
27 $(eval $(call distdir-opts,rts,dist))
29 # -----------------------------------------------------------------------------
30 # Defining the sources
32 ALL_DIRS = hooks parallel sm eventlog
34 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
40 EXCLUDED_SRCS += rts/Main.c
41 EXCLUDED_SRCS += rts/parallel/SysMan.c
42 EXCLUDED_SRCS += rts/dyn-wrapper.c
43 EXCLUDED_SRCS += $(wildcard rts/Vis*.c)
45 rts_C_SRCS = $(filter-out $(EXCLUDED_SRCS),$(wildcard rts/*.c $(foreach dir,$(ALL_DIRS),rts/$(dir)/*.c)))
46 rts_CMM_SRCS = $(wildcard rts/*.cmm)
48 # Don't compile .S files when bootstrapping a new arch
49 ifeq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
50 ifneq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
51 rts_S_SRCS += rts/AdjustorAsm.S
53 ifneq "$(findstring $(TargetOS_CPP), darwin)" ""
54 rts_S_SRCS += rts/AdjustorAsm.S
59 ifeq "$(GhcUnregisterised)" "YES"
63 rts_AUTO_APPLY_CMM = rts/dist/build/AutoApply.cmm
65 $(rts_AUTO_APPLY_CMM): $(GENAPPLY_INPLACE)
66 "$(GENAPPLY_INPLACE)" >$@
68 rts/dist/build/sm/Evac_thr.c : rts/sm/Evac.c
69 "$(MKDIRHIER)" $(dir $@)
71 rts/dist/build/sm/Scav_thr.c : rts/sm/Scav.c
72 "$(MKDIRHIER)" $(dir $@)
75 rts_H_FILES = $(wildcard includes/*.h) $(wildcard rts/*.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-z]*\)/-l\1/g' > $@
82 #-----------------------------------------------------------------------------
85 define build-rts-way # args: $1 = way
88 ifneq "$$(findstring debug, $1)" ""
90 rts_dist_$1_CC_OPTS = -g -O0
92 rts_dist_$1_HC_OPTS = $$(GhcRtsHcOpts)
93 rts_dist_$1_CC_OPTS = $$(GhcRtsCcOpts)
96 ifneq "$$(findstring thr, $1)" ""
97 rts_$1_EXTRA_C_SRCS = rts/dist/build/sm/Evac_thr.c rts/dist/build/sm/Scav_thr.c
100 $(call distdir-way-opts,rts,dist,$1)
101 $(call c-suffix-rules,rts,dist,$1,YES)
102 $(call cmm-suffix-rules,rts,dist,$1)
104 rts_$1_LIB = rts/dist/build/libHSrts$$($1_libsuf)
106 rts_$1_C_OBJS = $$(patsubst rts/%.c,rts/dist/build/%.$$($1_osuf),$$(rts_C_SRCS)) $$(patsubst %.c,%.$$($1_osuf),$$(rts_$1_EXTRA_C_SRCS))
107 rts_$1_S_OBJS = $$(patsubst rts/%.S,rts/dist/build/%.$$($1_osuf),$$(rts_S_SRCS))
108 rts_$1_CMM_OBJS = $$(patsubst rts/%.cmm,rts/dist/build/%.$$($1_osuf),$$(rts_CMM_SRCS)) $$(patsubst %.cmm,%.$$($1_osuf),$$(rts_AUTO_APPLY_CMM))
110 rts_$1_OBJS = $$(rts_$1_C_OBJS) $$(rts_$1_S_OBJS) $$(rts_$1_CMM_OBJS)
112 rts_dist_$1_CC_OPTS += -DRtsWay=$$(DQ)rts_$1$$(DQ)
114 ifneq "$$(findstring dyn, $1)" ""
115 $$(rts_$1_LIB) : $$(rts_$1_OBJS) rts/libs.depend
116 "$$(RM)" $$(RM_OPTS) $$@
117 "$$(rts_dist_HC)" -shared -dynamic -dynload deploy \
118 -no-auto-link-packages `cat rts/libs.depend` $$(rts_$1_OBJS) -o $$@
120 $$(rts_$1_LIB) : $$(rts_$1_OBJS)
121 "$$(RM)" $$(RM_OPTS) $$@
122 echo $$(rts_$1_OBJS) | $$(XARGS) $$(AR) $$(EXTRA_AR_ARGS) $$@
127 # And expand the above for each way:
128 $(foreach way,$(rts_WAYS),$(eval $(call build-rts-way,$(way))))
130 #-----------------------------------------------------------------------------
131 # Flags for compiling every file
133 # We like plenty of warnings.
134 WARNING_OPTS += -Wall
135 ifeq "$(GccLT34)" "YES"
138 WARNING_OPTS += -Wextra
140 WARNING_OPTS += -Wstrict-prototypes
141 WARNING_OPTS += -Wmissing-prototypes
142 WARNING_OPTS += -Wmissing-declarations
143 WARNING_OPTS += -Winline
144 WARNING_OPTS += -Waggregate-return
145 WARNING_OPTS += -Wpointer-arith
146 WARNING_OPTS += -Wmissing-noreturn
147 WARNING_OPTS += -Wcast-align
148 WARNING_OPTS += -Wnested-externs
149 WARNING_OPTS += -Wredundant-decls
151 # These ones are hard to avoid:
152 #WARNING_OPTS += -Wconversion
153 #WARNING_OPTS += -Wbad-function-cast
154 #WARNING_OPTS += -Wshadow
155 #WARNING_OPTS += -Wcast-qual
157 STANDARD_OPTS += -Iincludes -Irts
158 # COMPILING_RTS is only used when building Win32 DLL support.
159 STANDARD_OPTS += -DCOMPILING_RTS
161 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
162 # only included in .c compilations. HC_OPTS included the WAY_* opts, which
163 # must be included in both types of compilations.
165 rts_CC_OPTS += $(WARNING_OPTS)
166 rts_CC_OPTS += $(STANDARD_OPTS)
168 rts_HC_OPTS += $(STANDARD_OPTS) -package-name rts
170 ifneq "$(GhcWithSMP)" "YES"
171 rts_CC_OPTS += -DNOSMP
172 rts_HC_OPTS += -optc-DNOSMP
175 ifeq "$(UseLibFFIForAdjustors)" "YES"
176 rts_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
179 ifeq "$(Windows)" "YES"
180 # SDM: when compiled with -fasm the RTS currently has bogus references to
181 # __imp_base_ things, so working around for now:
182 rts_HC_OPTS += -fvia-C
185 ifneq "$(DYNAMIC_RTS)" "YES"
186 rts_HC_OPTS += -static
188 $(error ToDo: DYNAMIC_RTS)
191 # Mac OS X: make sure we compile for the right OS version
192 rts_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
193 rts_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
194 rts_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
196 # Otherwise the stack-smash handler gets triggered.
197 ifeq "$(TargetOS_CPP)" "openbsd"
198 rts_HC_OPTS += -optc-fno-stack-protector
201 # We *want* type-checking of hand-written cmm.
202 rts_HC_OPTS += -dcmm-lint
204 # -fno-strict-aliasing is required for the runtime, because we often
205 # use a variety of types to represent closure pointers (StgPtr,
206 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
207 # allowed to assume that these pointers do not alias. eg. without
208 # this flag we get problems in sm/Evac.c:copy() with gcc 3.4.3, the
209 # upd_evacee() assigments get moved before the object copy.
210 rts_CC_OPTS += -fno-strict-aliasing
212 rts_CC_OPTS += -fno-common
214 ifeq "$(BeConservative)" "YES"
215 rts_CC_OPTS += -DBE_CONSERVATIVE
218 #-----------------------------------------------------------------------------
219 # Flags for compiling specific files
221 # XXX DQ is now the same on all platforms, so get rid of it
224 # If RtsMain.c is built with optimisation then the SEH exception stuff on
225 # Windows gets confused.
226 # This has to be in HC rather than CC opts, as otherwise there's a
227 # -optc-O2 that comes after it.
228 RtsMain_HC_OPTS += -optc-O0
230 RtsMessages_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
231 RtsUtils_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
233 RtsUtils_CC_OPTS += -DHostPlatform=$(DQ)$(HOSTPLATFORM)$(DQ)
234 RtsUtils_CC_OPTS += -DHostArch=$(DQ)$(HostArch_CPP)$(DQ)
235 RtsUtils_CC_OPTS += -DHostOS=$(DQ)$(HostOS_CPP)$(DQ)
236 RtsUtils_CC_OPTS += -DHostVendor=$(DQ)$(HostVendor_CPP)$(DQ)
238 RtsUtils_CC_OPTS += -DBuildPlatform=$(DQ)$(BUILDPLATFORM)$(DQ)
239 RtsUtils_CC_OPTS += -DBuildArch=$(DQ)$(BuildArch_CPP)$(DQ)
240 RtsUtils_CC_OPTS += -DBuildOS=$(DQ)$(BuildOS_CPP)$(DQ)
241 RtsUtils_CC_OPTS += -DBuildVendor=$(DQ)$(BuildVendor_CPP)$(DQ)
243 RtsUtils_CC_OPTS += -DTargetPlatform=$(DQ)$(TARGETPLATFORM)$(DQ)
244 RtsUtils_CC_OPTS += -DTargetArch=$(DQ)$(TargetArch_CPP)$(DQ)
245 RtsUtils_CC_OPTS += -DTargetOS=$(DQ)$(TargetOS_CPP)$(DQ)
246 RtsUtils_CC_OPTS += -DTargetVendor=$(DQ)$(TargetVendor_CPP)$(DQ)
248 RtsUtils_CC_OPTS += -DGhcUnregisterised=$(DQ)$(GhcUnregisterised)$(DQ)
249 RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=$(DQ)$(GhcEnableTablesNextToCode)$(DQ)
251 # ffi.h triggers prototype warnings, so disable them here:
252 Interpreter_CC_OPTS += -Wno-strict-prototypes
253 Adjustor_CC_OPTS += -Wno-strict-prototypes
254 sm/Storage_CC_OPTS += -Wno-strict-prototypes
256 # inlining warnings happen in Compact
257 sm/Compact_CC_OPTS += -Wno-inline
259 # emits warnings about call-clobbered registers on x86_64
260 StgCRun_CC_OPTS += -w
262 RetainerProfile_CC_OPTS += -w
263 RetainerSet_CC_OPTS += -Wno-format
265 win32/ConsoleHandler_CC_OPTS += -w
266 win32/ThrIOManager_CC_OPTS += -w
267 win32/Ticker_CC_OPTS += -w
268 # The above warning supression flags are a temporary kludge.
269 # While working on this module you are encouraged to remove it and fix
270 # any warnings in the module. See
271 # http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
274 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
275 sm/Compact_CC_OPTS += -finline-limit=2500
277 # -O3 helps unroll some loops (especially in copy() with a constant argument).
278 sm/Evac_CC_OPTS += -funroll-loops
279 sm/Evac_thr_HC_OPTS += -optc-funroll-loops
281 # These files are just copies of sm/Evac.c and sm/Scav.c respectively,
282 # but compiled with -DPARALLEL_GC.
283 sm/Evac_thr_HC_OPTS += -optc-DPARALLEL_GC -Irts/sm
284 sm/Scav_thr_HC_OPTS += -optc-DPARALLEL_GC -Irts/sm
286 #-----------------------------------------------------------------------------
287 # Add PAPI library if needed
289 ifeq "$(GhcRtsWithPapi)" "YES"
291 rts_CC_OPTS += -DUSE_PAPI
293 rts_PACKAGE_CPP_OPTS += -DUSE_PAPI
294 rts_PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=$(PapiIncludeDir)
295 rts_PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=$(PapiLibDir)
297 ifneq "$(PapiIncludeDir)" ""
298 rts_HC_OPTS += -I$(PapiIncludeDir)
299 rts_CC_OPTS += -I$(PapiIncludeDir)
300 rts_HSC2HS_OPTS += -I$(PapiIncludeDir)
302 ifneq "$(PapiLibDirs)" ""
303 rts_LD_OPTS += -L$(PapiLibDirs)
306 else # GhcRtsWithPapi==YES
308 rts_PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=""
309 rts_PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=""
313 # -----------------------------------------------------------------------------
316 # Hack: we define every way-related option here, so that we get (hopefully)
317 # a superset of the dependencies. To do this properly, we should generate
318 # a different set of dependencies for each way. Further hack: PROFILING and
319 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
320 rts_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
322 rts_WAYS_DASHED = $(subst $(space),,$(patsubst %,-%,$(strip $(rts_WAYS))))
323 rts_dist_depfile = rts/dist/build/.depend$(rts_WAYS_DASHED)
325 rts_dist_C_SRCS = $(rts_C_SRCS)
326 rts_dist_S_SRCS = $(rts_S_SRCS)
327 rts_dist_C_FILES = $(rts_C_SRCS) $(rts_S_SRCS)
329 $(eval $(call build-dependencies,rts,dist))
331 $(rts_dist_depfile) : libffi/ffi.h
333 #-----------------------------------------------------------------------------
336 rts_CC_OPTS += -Ilibffi/build/include
337 rts_HC_OPTS += -Ilibffi/build/include
338 rts_HSC2HS_OPTS += -Ilibffi/build/include
339 rts_LD_OPTS += -Llibffi/build/include
341 # -----------------------------------------------------------------------------
342 # compile generic patchable dyn-wrapper
344 DYNWRAPPER_SRC = rts/dyn-wrapper.c
345 DYNWRAPPER_PROG = rts/dyn-wrapper$(exeext)
346 $(DYNWRAPPER_PROG): $(DYNWRAPPER_SRC)
347 "$(HC)" -cpp -optc-include -optcdyn-wrapper-patchable-behaviour.h $(INPLACE_EXTRA_FLAGS) $< -o $@
349 # -----------------------------------------------------------------------------
350 # build the static lib containing the C main symbol
352 rts/dist/build/libHSrtsmain.a : rts/dist/build/Main.o
353 $(AR) $(EXTRA_AR_ARGS) $@ $<
355 # -----------------------------------------------------------------------------
356 # The RTS package config
358 # If -DDEBUG is in effect, adjust package conf accordingly..
359 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
360 rts_PACKAGE_CPP_OPTS += -DDEBUG
363 ifeq "$(HaveLibMingwEx)" "YES"
364 rts_PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
367 $(eval $(call manual-package-config,rts))
369 ifneq "$(BootingFromHc)" "YES"
370 rts/package.conf.inplace : $(includes_H_CONFIG) $(includes_H_PLATFORM)
373 # -----------------------------------------------------------------------------
376 install : install_rts
380 $(INSTALL_DIR) $(DESTDIR)$(ghclibdir)
381 $(INSTALL_DIR) $(DESTDIR)$(ghclibdir)/include
382 "$(CP)" $(ALL_RTS_LIBS) $(DESTDIR)$(ghclibdir)
384 # -----------------------------------------------------------------------------
387 $(eval $(call clean-target,rts,dist,rts/dist))
389 BINDIST_EXTRAS += rts/package.conf.in
390 BINDIST_EXTRAS += $(ALL_RTS_LIBS)