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)
26 # -----------------------------------------------------------------------------
27 # Defining the sources
29 ALL_DIRS = hooks parallel sm eventlog
31 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
37 EXCLUDED_SRCS += rts/Main.c
38 EXCLUDED_SRCS += rts/parallel/SysMan.c
39 EXCLUDED_SRCS += rts/dyn-wrapper.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 ifeq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
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 # collect the -l flags that we need to link the rts dyn lib.
73 rts/libs.depend : $(GHC_PKG_INPLACE)
74 "$(GHC_PKG_INPLACE)" field rts extra-libraries \
75 | sed -e 's/^extra-libraries: //' -e 's/\([a-z0-9]*\)[ ]*/-l\1 /g' > $@
77 #-----------------------------------------------------------------------------
80 define build-rts-way # args: $1 = way
83 ifneq "$$(findstring debug, $1)" ""
85 rts_dist_$1_CC_OPTS = -g -O0
87 rts_dist_$1_HC_OPTS = $$(GhcRtsHcOpts)
88 rts_dist_$1_CC_OPTS = $$(GhcRtsCcOpts)
91 ifneq "$$(findstring thr, $1)" ""
92 rts_$1_EXTRA_C_SRCS = rts/dist/build/sm/Evac_thr.c rts/dist/build/sm/Scav_thr.c
95 $(call distdir-way-opts,rts,dist,$1)
96 $(call c-suffix-rules,rts,dist,$1,YES)
97 $(call cmm-suffix-rules,rts,dist,$1)
98 $(call hs-suffix-rules-srcdir,rts,dist,$1,$$(dir))
99 # hs-suffix-rules-srcdir is needed when BootingFromHc to get the .hc rules
101 rts_$1_LIB = rts/dist/build/libHSrts$$($1_libsuf)
103 rts_$1_C_OBJS = $$(patsubst rts/%.c,rts/dist/build/%.$$($1_osuf),$$(rts_C_SRCS)) $$(patsubst %.c,%.$$($1_osuf),$$(rts_$1_EXTRA_C_SRCS))
104 rts_$1_S_OBJS = $$(patsubst rts/%.S,rts/dist/build/%.$$($1_osuf),$$(rts_S_SRCS))
105 rts_$1_CMM_OBJS = $$(patsubst rts/%.cmm,rts/dist/build/%.$$($1_osuf),$$(rts_CMM_SRCS)) $$(patsubst %.cmm,%.$$($1_osuf),$$(rts_AUTO_APPLY_CMM))
107 rts_$1_OBJS = $$(rts_$1_C_OBJS) $$(rts_$1_S_OBJS) $$(rts_$1_CMM_OBJS)
109 rts_dist_$1_CC_OPTS += -DRtsWay=$$(DQ)rts_$1$$(DQ)
112 # Making a shared library for the RTS.
113 # On Windows, as the RTS and base library has recursive imports
114 # we have to break the loop with a import library (libHSbase.so.a)
115 # This is made from rts/win32/libHSbase.def which contains a list of
116 # all the symbols in the base library used by the RTS.
117 ifneq "$$(findstring dyn, $1)" ""
118 $$(rts_$1_LIB) : $$(rts_$1_OBJS) rts/libs.depend
119 "$$(RM)" $$(RM_OPTS) $$@
120 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
121 "$$(DLLTOOL)" -d rts/win32/libHSbase.def -l rts/dist/build/win32/libHSbase.so.a
122 "$$(rts_dist_HC)" -shared -dynamic -dynload deploy \
123 -no-auto-link-packages `cat rts/libs.depend` $$(rts_$1_OBJS) rts/dist/build/win32/libHSbase.so.a -o $$@
125 "$$(rts_dist_HC)" -shared -dynamic -dynload deploy \
126 -no-auto-link-packages `cat rts/libs.depend` $$(rts_$1_OBJS) -o $$@
129 $$(rts_$1_LIB) : $$(rts_$1_OBJS)
130 "$$(RM)" $$(RM_OPTS) $$@
131 echo $$(rts_$1_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR)" $$(AR_OPTS) $$(EXTRA_AR_ARGS) $$@
136 # And expand the above for each way:
137 $(foreach way,$(rts_WAYS),$(eval $(call build-rts-way,$(way))))
139 #-----------------------------------------------------------------------------
140 # Flags for compiling every file
142 # We like plenty of warnings.
143 WARNING_OPTS += -Wall
144 ifeq "$(GccLT34)" "YES"
147 WARNING_OPTS += -Wextra
149 WARNING_OPTS += -Wstrict-prototypes
150 WARNING_OPTS += -Wmissing-prototypes
151 WARNING_OPTS += -Wmissing-declarations
152 WARNING_OPTS += -Winline
153 WARNING_OPTS += -Waggregate-return
154 WARNING_OPTS += -Wpointer-arith
155 WARNING_OPTS += -Wmissing-noreturn
156 WARNING_OPTS += -Wcast-align
157 WARNING_OPTS += -Wnested-externs
158 WARNING_OPTS += -Wredundant-decls
160 # These ones are hard to avoid:
161 #WARNING_OPTS += -Wconversion
162 #WARNING_OPTS += -Wbad-function-cast
163 #WARNING_OPTS += -Wshadow
164 #WARNING_OPTS += -Wcast-qual
166 STANDARD_OPTS += -Iincludes -Irts
167 # COMPILING_RTS is only used when building Win32 DLL support.
168 STANDARD_OPTS += -DCOMPILING_RTS
170 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
171 # only included in .c compilations. HC_OPTS included the WAY_* opts, which
172 # must be included in both types of compilations.
174 rts_CC_OPTS += $(WARNING_OPTS)
175 rts_CC_OPTS += $(STANDARD_OPTS)
177 rts_HC_OPTS += $(STANDARD_OPTS) -package-name rts
179 ifneq "$(GhcWithSMP)" "YES"
180 rts_CC_OPTS += -DNOSMP
181 rts_HC_OPTS += -optc-DNOSMP
184 ifeq "$(UseLibFFIForAdjustors)" "YES"
185 rts_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
188 # Mac OS X: make sure we compile for the right OS version
189 rts_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
190 rts_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
191 rts_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
193 # Otherwise the stack-smash handler gets triggered.
194 ifneq "$(findstring $(TargetOS_CPP), darwin openbsd)" ""
195 rts_HC_OPTS += -optc-fno-stack-protector
198 # We *want* type-checking of hand-written cmm.
199 rts_HC_OPTS += -dcmm-lint
201 # -fno-strict-aliasing is required for the runtime, because we often
202 # use a variety of types to represent closure pointers (StgPtr,
203 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
204 # allowed to assume that these pointers do not alias. eg. without
205 # this flag we get problems in sm/Evac.c:copy() with gcc 3.4.3, the
206 # upd_evacee() assigments get moved before the object copy.
207 rts_CC_OPTS += -fno-strict-aliasing
209 rts_CC_OPTS += -fno-common
211 ifeq "$(BeConservative)" "YES"
212 rts_CC_OPTS += -DBE_CONSERVATIVE
215 #-----------------------------------------------------------------------------
216 # Flags for compiling specific files
218 # XXX DQ is now the same on all platforms, so get rid of it
221 # If RtsMain.c is built with optimisation then the SEH exception stuff on
222 # Windows gets confused.
223 # This has to be in HC rather than CC opts, as otherwise there's a
224 # -optc-O2 that comes after it.
225 rts/RtsMain_HC_OPTS += -optc-O0
227 rts/RtsMessages_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
228 rts/RtsUtils_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
230 rts/RtsUtils_CC_OPTS += -DHostPlatform=$(DQ)$(HOSTPLATFORM)$(DQ)
231 rts/RtsUtils_CC_OPTS += -DHostArch=$(DQ)$(HostArch_CPP)$(DQ)
232 rts/RtsUtils_CC_OPTS += -DHostOS=$(DQ)$(HostOS_CPP)$(DQ)
233 rts/RtsUtils_CC_OPTS += -DHostVendor=$(DQ)$(HostVendor_CPP)$(DQ)
235 rts/RtsUtils_CC_OPTS += -DBuildPlatform=$(DQ)$(BUILDPLATFORM)$(DQ)
236 rts/RtsUtils_CC_OPTS += -DBuildArch=$(DQ)$(BuildArch_CPP)$(DQ)
237 rts/RtsUtils_CC_OPTS += -DBuildOS=$(DQ)$(BuildOS_CPP)$(DQ)
238 rts/RtsUtils_CC_OPTS += -DBuildVendor=$(DQ)$(BuildVendor_CPP)$(DQ)
240 rts/RtsUtils_CC_OPTS += -DTargetPlatform=$(DQ)$(TARGETPLATFORM)$(DQ)
241 rts/RtsUtils_CC_OPTS += -DTargetArch=$(DQ)$(TargetArch_CPP)$(DQ)
242 rts/RtsUtils_CC_OPTS += -DTargetOS=$(DQ)$(TargetOS_CPP)$(DQ)
243 rts/RtsUtils_CC_OPTS += -DTargetVendor=$(DQ)$(TargetVendor_CPP)$(DQ)
245 rts/RtsUtils_CC_OPTS += -DGhcUnregisterised=$(DQ)$(GhcUnregisterised)$(DQ)
246 rts/RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=$(DQ)$(GhcEnableTablesNextToCode)$(DQ)
248 # ffi.h triggers prototype warnings, so disable them here:
249 rts/Interpreter_CC_OPTS += -Wno-strict-prototypes
250 rts/Adjustor_CC_OPTS += -Wno-strict-prototypes
251 rts/sm/Storage_CC_OPTS += -Wno-strict-prototypes
253 # inlining warnings happen in Compact
254 rts/sm/Compact_CC_OPTS += -Wno-inline
256 # emits warnings about call-clobbered registers on x86_64
257 rts/StgCRun_CC_OPTS += -w
259 rts/RetainerProfile_CC_OPTS += -w
260 rts/RetainerSet_CC_OPTS += -Wno-format
262 rts/win32/ConsoleHandler_CC_OPTS += -w
263 rts/win32/ThrIOManager_CC_OPTS += -w
264 rts/win32/Ticker_CC_OPTS += -w
265 # The above warning supression flags are a temporary kludge.
266 # While working on this module you are encouraged to remove it and fix
267 # any warnings in the module. See
268 # http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
271 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
272 rts/sm/Compact_CC_OPTS += -finline-limit=2500
274 # -O3 helps unroll some loops (especially in copy() with a constant argument).
275 rts/sm/Evac_CC_OPTS += -funroll-loops
276 rts/dist/build/sm/Evac_thr_HC_OPTS += -optc-funroll-loops
278 # These files are just copies of sm/Evac.c and sm/Scav.c respectively,
279 # but compiled with -DPARALLEL_GC.
280 rts/dist/build/sm/Evac_thr_HC_OPTS += -optc-DPARALLEL_GC -Irts/sm
281 rts/dist/build/sm/Scav_thr_HC_OPTS += -optc-DPARALLEL_GC -Irts/sm
283 #-----------------------------------------------------------------------------
284 # Add PAPI library if needed
286 ifeq "$(GhcRtsWithPapi)" "YES"
288 rts_CC_OPTS += -DUSE_PAPI
290 rts_PACKAGE_CPP_OPTS += -DUSE_PAPI
291 rts_PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=$(PapiIncludeDir)
292 rts_PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=$(PapiLibDir)
294 ifneq "$(PapiIncludeDir)" ""
295 rts_HC_OPTS += -I$(PapiIncludeDir)
296 rts_CC_OPTS += -I$(PapiIncludeDir)
297 rts_HSC2HS_OPTS += -I$(PapiIncludeDir)
299 ifneq "$(PapiLibDirs)" ""
300 rts_LD_OPTS += -L$(PapiLibDirs)
303 else # GhcRtsWithPapi==YES
305 rts_PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=""
306 rts_PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=""
310 # -----------------------------------------------------------------------------
313 # Hack: we define every way-related option here, so that we get (hopefully)
314 # a superset of the dependencies. To do this properly, we should generate
315 # a different set of dependencies for each way. Further hack: PROFILING and
316 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
317 rts_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
318 rts_MKDEPENDC_OPTS += -Irts/sm
320 rts_WAYS_DASHED = $(subst $(space),,$(patsubst %,-%,$(strip $(rts_WAYS))))
321 rts_dist_depfile = rts/dist/build/.depend$(rts_WAYS_DASHED)
323 rts_dist_C_SRCS = $(rts_C_SRCS) $(rts_thr_EXTRA_C_SRCS)
324 rts_dist_S_SRCS = $(rts_S_SRCS)
325 rts_dist_C_FILES = $(rts_C_SRCS) $(rts_thr_EXTRA_C_SRCS) $(rts_S_SRCS)
327 $(eval $(call build-dependencies,rts,dist))
329 $(rts_dist_depfile) : libffi/dist-install/build/ffi.h
331 #-----------------------------------------------------------------------------
334 rts_CC_OPTS += -Ilibffi/build/include
335 rts_HC_OPTS += -Ilibffi/build/include
336 rts_HSC2HS_OPTS += -Ilibffi/build/include
337 rts_LD_OPTS += -Llibffi/build/include
339 # -----------------------------------------------------------------------------
340 # compile generic patchable dyn-wrapper
342 DYNWRAPPER_SRC = rts/dyn-wrapper.c
343 DYNWRAPPER_PROG = rts/dyn-wrapper$(exeext)
344 $(DYNWRAPPER_PROG): $(DYNWRAPPER_SRC)
345 "$(HC)" -cpp -optc-include -optcdyn-wrapper-patchable-behaviour.h $(INPLACE_EXTRA_FLAGS) $< -o $@
347 # -----------------------------------------------------------------------------
348 # build the static lib containing the C main symbol
350 rts/dist/build/libHSrtsmain.a : rts/dist/build/Main.o
351 "$(AR)" $(AR_OPTS) $(EXTRA_AR_ARGS) $@ $<
353 # -----------------------------------------------------------------------------
354 # The RTS package config
356 # If -DDEBUG is in effect, adjust package conf accordingly..
357 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
358 rts_PACKAGE_CPP_OPTS += -DDEBUG
361 ifeq "$(HaveLibMingwEx)" "YES"
362 rts_PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
365 $(eval $(call manual-package-config,rts))
367 ifneq "$(BootingFromHc)" "YES"
368 rts/package.conf.inplace : $(includes_H_CONFIG) $(includes_H_PLATFORM)
371 # -----------------------------------------------------------------------------
374 install : install_rts
378 $(INSTALL_DIR) "$(DESTDIR)$(ghclibdir)"
379 $(INSTALL_DIR) "$(DESTDIR)$(ghclibdir)/include"
380 "$(CP)" $(ALL_RTS_LIBS) "$(DESTDIR)$(ghclibdir)"
382 # -----------------------------------------------------------------------------
385 $(eval $(call clean-target,rts,dist,rts/dist))
387 BINDIST_EXTRAS += rts/package.conf.in
388 BINDIST_EXTRAS += $(ALL_RTS_LIBS)