1 #-----------------------------------------------------------------------------
3 # This is the Makefile for the runtime-system stuff.
4 # This stuff is written in C (and cannot be written in Haskell).
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.
11 #-----------------------------------------------------------------------------
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.
22 include $(TOP)/mk/boilerplate.mk
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 making and installing
32 ifeq "$(DOING_BIN_DIST)" "YES"
36 # -----------------------------------------------------------------------------
39 WAYS=$(strip $(GhcLibWays) $(GhcRTSWays))
41 ifneq "$(findstring debug, $(way))" ""
46 ifeq "$(BeConservative)" "YES"
47 GhcRtsCcOpts += -DBE_CONSERVATIVE
50 # -----------------------------------------------------------------------------
52 # There's nothing for Haddock here...
53 override HADDOCK_DOCS = NO
55 # -----------------------------------------------------------------------------
57 # Tells the build system not to add various Haskellish options to $(SRC_HC_OPTS)
60 # grab sources from these subdirectories
61 ALL_DIRS = hooks parallel sm
63 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
69 ifneq "$(findstring dyn, $(way))" ""
75 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
76 EXCLUDED_SRCS += Main.c
77 # It's not included in the DLL, but we need to compile it up separately.
80 INSTALL_LIBS += Main.$(way_)o
82 EXCLUDED_SRCS += RtsDllMain.c
85 # This file ends up being empty unless we're building for a powerpc
86 # or darwin system, and it is reported that Solaris ld chokes on it when
88 ifeq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
89 ifeq "$(findstring $(TargetOS_CPP), darwin)" ""
90 EXCLUDED_SRCS += AdjustorAsm.S
94 EXCLUDED_SRCS += parallel/SysMan.c
96 EXCLUDED_SRCS += dyn-wrapper.c
98 # compile generatic patchable dyn-wrapper
100 DYNWRAPPER_SRC = dyn-wrapper.c
101 DYNWRAPPER_PROG = dyn-wrapper$(exeext)
102 $(DYNWRAPPER_PROG): $(DYNWRAPPER_SRC)
103 $(HC) -cpp -optc-include -optcdyn-wrapper-patchable-behaviour.h $(INPLACE_EXTRA_FLAGS) $< -o $@
105 # The build system doesn't give us these
106 CMM_SRCS = $(filter-out AutoApply%.cmm, $(wildcard *.cmm)) $(EXTRA_CMM_SRCS)
107 CMM_OBJS = $(patsubst %.cmm,%.$(way_)o, $(CMM_SRCS))
109 CLEAN_FILES += $(CMM_OBJS)
111 # Override the default $(LIBOBJS) (defaults to $(HS_OBJS))
112 LIBOBJS = $(C_OBJS) $(CMM_OBJS)
116 H_FILES = $(wildcard ../includes/*.h) $(wildcard *.h)
118 #-----------------------------------------------------------------------------
119 # Flags for compiling RTS .c and .hc files
121 # gcc provides lots of useful warnings if you ask it.
122 # This is a pretty good list to start with - use a # to comment out
123 # any you don't like.
124 WARNING_OPTS += -Wall
126 WARNING_OPTS += -Wstrict-prototypes
127 WARNING_OPTS += -Wmissing-prototypes
128 WARNING_OPTS += -Wmissing-declarations
129 WARNING_OPTS += -Winline
130 WARNING_OPTS += -Waggregate-return
131 #WARNING_OPTS += -Wpointer-arith
132 #WARNING_OPTS += -Wbad-function-cast
133 #WARNING_OPTS += -Wcast-align
134 #WARNING_OPTS += -Wnested-externs
135 #WARNING_OPTS += -Wshadow
136 #WARNING_OPTS += -Wcast-qual
137 #WARNING_OPTS += -Wno-unused
138 #WARNING_OPTS += -Wredundant-decls
139 #WARNING_OPTS += -Wconversion
141 STANDARD_OPTS += -I../includes -I. -Iparallel -Ism
142 # COMPILING_RTS is only used when building Win32 DLL support.
143 STANDARD_OPTS += -DCOMPILING_RTS
145 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
146 # only included in .c compilations. HC_OPTS included the WAY_* opts, which
147 # must be included in both types of compilations.
149 SRC_CC_OPTS += $(WARNING_OPTS)
150 SRC_CC_OPTS += $(STANDARD_OPTS)
152 SRC_CC_OPTS += $(GhcRtsCcOpts)
153 SRC_HC_OPTS += $(GhcRtsHcOpts) $(STANDARD_OPTS) -package-name rts
155 ifneq "$(GhcWithSMP)" "YES"
156 SRC_CC_OPTS += -DNOSMP
157 SRC_HC_OPTS += -optc-DNOSMP
160 ifeq "$(UseLibFFIForAdjustors)" "YES"
161 SRC_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
164 ifneq "$(DYNAMIC_RTS)" "YES"
165 SRC_HC_OPTS += -static
167 LIB_LD_OPTS += -ignore-package base -ignore-package rts
168 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
172 BASE_DIST_LIB=$(TOP)/libraries/base/dist/build
174 # The following must be a one liner otherwise its evaluation won't be delayed until base/rts packages are properly registered
175 LIB_LD_OPTS = -L$(shell $(GHC_PKG_INPLACE) field base library-dirs | sed -e 's/library-dirs: //') -l$(shell $(GHC_PKG_INPLACE) field base hs-libraries | sed -e 's/hs-libraries: //')-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 rts library-dirs | sed -e s/library-dirs://),"-L$(libdir)")
179 # Mac OS X: make sure we compile for the right OS version
180 SRC_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
181 SRC_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
182 LIB_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
184 # XXX DQ is now the same on all platforms, so get rid of it
187 # If Main.c is built with optimisation then the SEH exception stuff on
188 # Windows gets confused.
189 # This has to be in HC rather than CC opts, as otherwise there's a
190 # -optc-O2 that comes after it.
191 Main_HC_OPTS += -optc-O0
193 RtsMessages_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
194 RtsUtils_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
195 RtsUtils_CC_OPTS += -DRtsWay=$(DQ)rts$(_way)$(DQ)
196 RtsUtils_CC_OPTS += -DHostPlatform=$(DQ)$(HOSTPLATFORM)$(DQ)
197 RtsUtils_CC_OPTS += -DBuildPlatform=$(DQ)$(BUILDPLATFORM)$(DQ)
198 RtsUtils_CC_OPTS += -DTargetPlatform=$(DQ)$(TARGETPLATFORM)$(DQ)
199 RtsUtils_CC_OPTS += -DGhcUnregisterised=$(DQ)$(GhcUnregisterised)$(DQ)
200 RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=$(DQ)$(GhcEnableTablesNextToCode)$(DQ)
202 # ffi.h triggers prototype warnings, so disable them here:
203 Interpreter_CC_OPTS += -Wno-strict-prototypes
204 Adjustor_CC_OPTS += -Wno-strict-prototypes
206 StgCRun_CC_OPTS += -w
207 Typeable_CC_OPTS += -w
208 RetainerProfile_CC_OPTS += -w
209 sm/Compact_CC_OPTS += -w
211 win32/ConsoleHandler_CC_OPTS += -w
212 win32/ThrIOManager_CC_OPTS += -w
213 win32/Ticker_CC_OPTS += -w
214 Threads_CC_OPTS += -w
215 Capability_CC_OPTS += -w
216 Schedule_CC_OPTS += -w
217 # The above warning supression flags are a temporary kludge.
218 # While working on this module you are encouraged to remove it and fix
219 # any warnings in the module. See
220 # http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
224 SRC_HC_OPTS += -I$$PVM_ROOT/include
227 # If -DDEBUG is in effect, adjust package conf accordingly..
228 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
229 PACKAGE_CPP_OPTS += -DDEBUG
232 ifeq "$(HaveLibMingwEx)" "YES"
233 PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
236 ifeq "$(GhciWithDebugger)" "YES"
237 STANDARD_OPTS += -DDEBUGGER
240 ifeq "$(DotnetSupport)" "YES"
243 # Would like to just use SUBDIRS here, but need to
244 # descend into dotnet/ earlier than that.
247 $(MAKE) -C dotnet all
249 # But use SUBDIRS for other recursive targets.
252 LIBOBJS += dotnet/Invoke.o
255 # Suppress uninitialized variable warnings for GC.c
256 GC_CC_OPTS += -Wno-uninitialized
258 #-----------------------------------------------------------------------------
259 # Include the Front panel code?
261 # we need GTK+ for the front panel
262 ifneq "$(GTK_CONFIG)" ""
263 ifeq "$(GhcRtsWithFrontPanel)" "YES"
264 SRC_HC_OPTS += `$(GTK_CONFIG) --cflags` -optc-DRTS_GTK_FRONTPANEL
265 VisCallbacks_CC_OPTS += -Wno-unused
266 SRC_MKDEPENDC_OPTS += `$(GTK_CONFIG) --cflags`
267 else # GhcRtsWithFrontPanel
268 EXCLUDED_SRCS += $(wildcard Vis*.c)
271 EXCLUDED_SRCS += $(wildcard Vis*.c)
274 #-----------------------------------------------------------------------------
275 # Add PAPI library if needed
277 ifeq "$(GhcRtsWithPapi)" "YES"
279 SRC_CC_OPTS += -DUSE_PAPI
280 PACKAGE_CPP_OPTS += -DUSE_PAPI
282 PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=$(PapiIncludeDir)
283 PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=$(PapiLibDir)
285 ifneq "$(PapiIncludeDir)" ""
286 SRC_HC_OPTS += -I$(PapiIncludeDir)
287 SRC_CC_OPTS += -I$(PapiIncludeDir)
288 SRC_HSC2HS_OPTS += -I$(PapiIncludeDir)
290 ifneq "$(PapiLibDirs)" ""
291 SRC_LD_OPTS += -L$(PapiLibDirs)
294 else # GhcRtsWithPapi==YES
296 PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=""
300 #-----------------------------------------------------------------------------
303 SRC_MKDEPENDC_OPTS += -I. -I../includes
305 # Hack: we define every way-related option here, so that we get (hopefully)
306 # a superset of the dependencies. To do this properly, we should generate
307 # a different set of dependencies for each way. Further hack: PROFILING and
308 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
309 SRC_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
311 # -----------------------------------------------------------------------------
312 # The auto-generated apply code
314 # We want a slightly different version for the unregisterised way, so we make
315 # AutoApply on a per-way basis (eg. AutoApply_p.cmm).
317 ifneq "$(DOING_BIN_DIST)" "YES"
319 AUTO_APPLY_CMM = AutoApply$(_way).cmm
321 ifneq "$(BootingFromHc)" "YES"
322 $(AUTO_APPLY_CMM): $(GHC_GENAPPLY)
324 $(GENAPPLY) $(if $(filter $(way), u debug_u), -u) >$@
327 EXTRA_CMM_SRCS += $(AUTO_APPLY_CMM)
329 CLEAN_FILES += $(AUTO_APPLY_CMM)
333 # -----------------------------------------------------------------------------
335 # Need to get the GMP vars in through CPP to package.conf.in, and put
336 # quotes around each element.
339 space = $(empty) $(empty)
341 PACKAGE_CPP_OPTS += -DGMP_INCLUDE_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_INCLUDE_DIRS))))'
342 PACKAGE_CPP_OPTS += -DGMP_LIB_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_LIB_DIRS))))'
344 ifneq "$(GMP_INCLUDE_DIRS)" ""
345 SRC_HC_OPTS += -I$(GMP_INCLUDE_DIRS)
346 SRC_CC_OPTS += -I$(GMP_INCLUDE_DIRS)
347 SRC_HSC2HS_OPTS += -I$(GMP_INCLUDE_DIRS)
349 ifneq "$(GMP_LIB_DIRS)" ""
350 SRC_LD_OPTS += -L$(GMP_LIB_DIRS)
353 SRC_CC_OPTS += -I../gmp/gmpbuild
354 SRC_HC_OPTS += -I../gmp/gmpbuild
355 SRC_HSC2HS_OPTS += -I../gmp/gmpbuild
356 SRC_LD_OPTS += -L../gmp/gmpbuild
358 #-----------------------------------------------------------------------------
361 SRC_CC_OPTS += -I../libffi/build/include
362 SRC_HC_OPTS += -I../libffi/build/include
363 SRC_HSC2HS_OPTS += -I../libffi/build/include
364 SRC_LD_OPTS += -L../libffi/build/include
366 #-----------------------------------------------------------------------------
368 # Building the GUM SysMan
372 all :: parallel/SysMan
374 ifdef solaris2_TARGET_OS
375 __socket_libs = -lsocket -lnsl
380 parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
382 gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
384 CLEAN_FILES += parallel/SysMan.mp_o parallel/SysMan
385 INSTALL_LIBEXECS += parallel/SysMan
388 #-----------------------------------------------------------------------------
389 # Compiling the cmm files
391 # ToDo: should we really include Rts.h here? Required for GNU_ATTRIBUTE().
394 # Otherwise the stack-smash handler gets triggered.
395 ifeq "$(TargetOS_CPP)" "openbsd"
396 SRC_HC_OPTS += -optc-fno-stack-protector
399 # -O3 helps unroll some loops (especially in copy() with a constant argument).
400 sm/Evac_HC_OPTS += -optc-funroll-loops
402 ifneq "$(findstring thr, $(way))" ""
403 EXTRA_SRCS += sm/Evac_thr.c sm/Scav_thr.c
405 sm/Evac_thr.c : sm/Evac.c
407 sm/Scav_thr.c : sm/Scav.c
410 sm/Evac_thr_HC_OPTS += -optc-DPARALLEL_GC
411 sm/Scav_thr_HC_OPTS += -optc-DPARALLEL_GC
413 EXCLUDED_SRCS += sm/Evac_thr.c sm/Scav_thr.c
416 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
417 sm/Compact_HC_OPTS += -optc-finline-limit=2500
419 # -fno-strict-aliasing is required for the runtime, because we often
420 # use a variety of types to represent closure pointers (StgPtr,
421 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
422 # allowed to assume that these pointers do not alias. eg. without
423 # this flag we get problems in sm/Evac.c:copy() with gcc 3.4.3, the
424 # upd_evacee() assigments get moved before the object copy.
425 SRC_CC_OPTS += -fno-strict-aliasing
427 # We *want* type-checking of hand-written cmm.
428 SRC_HC_OPTS += -dcmm-lint
430 ifneq "$(BootingFromHc)" "YES"
431 # .cmm files depend on all the .h files, to a first approximation.
432 %.$(way_)o : %.cmm $(H_FILES)
434 $(HC) $(HC_OPTS) -c $< -o $@
437 %.$(way_)hc : %.cmm $(H_FILES)
438 $(HC) $(HC_OPTS) -C $< -o $@
440 %.$(way_)s : %.cmm $(H_FILES)
441 $(HC) $(HC_OPTS) -S $< -o $@
444 #-----------------------------------------------------------------------------
448 # Just libHSrts is installed uniformly across ways
451 include $(TOP)/mk/target.mk
453 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
454 # $(LIBRARY).a is not the static library libHSrts.a but
455 # libHSrts.dll.a, the import library for dynamic linking required for
456 # linking the dynamic version of base
457 buildbase: $(LIBRARY).a
458 $(MAKE) way="" -C ../libraries/ make.library.base
461 #-----------------------------------------------------------------------------
466 $(INSTALL_DIR) $(BIN_DIST_DIR)/rts
467 $(INSTALL_DATA) Makefile $(BIN_DIST_DIR)/rts/
468 $(INSTALL_DATA) package.conf.in $(BIN_DIST_DIR)/rts/
469 ifneq "$(INSTALL_LIBS)" ""
470 $(INSTALL_DATA) $(INSTALL_LIBS) $(BIN_DIST_DIR)/rts/
472 ifneq "$(INSTALL_LIBEXECS)" ""
473 $(INSTALL_PROGRAM) $(INSTALL_LIBEXECS) $(BIN_DIST_DIR)/rts/