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
28 # -----------------------------------------------------------------------------
31 WAYS=$(GhcLibWays) $(GhcRTSWays)
33 ifneq "$(findstring debug, $(way))" ""
38 # -----------------------------------------------------------------------------
40 # Tells the build system not to add various Haskellish options to $(SRC_HC_OPTS)
43 # grab sources from these subdirectories
44 ALL_DIRS = hooks parallel sm
46 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
52 ifneq "$(findstring dyn, $(way))" ""
58 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
59 EXCLUDED_SRCS += Main.c
60 # It's not included in the DLL, but we need to compile it up separately.
63 INSTALL_LIBS += Main.$(way_)o
65 EXCLUDED_SRCS += RtsDllMain.c
68 # This file ends up being empty unless we're building for a powerpc
69 # or darwin system, and it is reported that Solaris ld chokes on it when
71 ifeq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
72 ifeq "$(findstring $(TargetOS_CPP), darwin)" ""
73 EXCLUDED_SRCS += AdjustorAsm.S
77 EXCLUDED_SRCS += parallel/SysMan.c
79 # The build system doesn't give us these
80 CMM_SRCS = $(filter-out AutoApply%.cmm, $(wildcard *.cmm)) $(EXTRA_CMM_SRCS)
81 CMM_OBJS = $(patsubst %.cmm,%.$(way_)o, $(CMM_SRCS))
83 CLEAN_FILES += $(CMM_OBJS)
85 # Override the default $(LIBOBJS) (defaults to $(HS_OBJS))
86 LIBOBJS = $(C_OBJS) $(CMM_OBJS)
90 H_FILES = $(wildcard ../includes/*.h) $(wildcard *.h)
92 #-----------------------------------------------------------------------------
93 # Flags for compiling RTS .c and .hc files
95 # gcc provides lots of useful warnings if you ask it.
96 # This is a pretty good list to start with - use a # to comment out
100 WARNING_OPTS += -Wstrict-prototypes
101 WARNING_OPTS += -Wmissing-prototypes
102 WARNING_OPTS += -Wmissing-declarations
103 WARNING_OPTS += -Winline
104 WARNING_OPTS += -Waggregate-return
105 #WARNING_OPTS += -Wpointer-arith
106 #WARNING_OPTS += -Wbad-function-cast
107 #WARNING_OPTS += -Wcast-align
108 #WARNING_OPTS += -Wnested-externs
109 #WARNING_OPTS += -Wshadow
110 #WARNING_OPTS += -Wcast-qual
111 #WARNING_OPTS += -Wno-unused
112 #WARNING_OPTS += -Wredundant-decls
113 #WARNING_OPTS += -Wconversion
115 STANDARD_OPTS += -I../includes -I. -Iparallel -Ism
116 # COMPILING_RTS is only used when building Win32 DLL support.
117 STANDARD_OPTS += -DCOMPILING_RTS
119 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
120 # only included in .c compilations. HC_OPTS included the WAY_* opts, which
121 # must be included in both types of compilations.
123 SRC_CC_OPTS += $(WARNING_OPTS)
124 SRC_CC_OPTS += $(STANDARD_OPTS)
126 SRC_CC_OPTS += $(GhcRtsCcOpts)
127 SRC_HC_OPTS += $(GhcRtsHcOpts) -package-name rts
129 ifneq "$(GhcWithSMP)" "YES"
130 SRC_CC_OPTS += -DNOSMP
131 SRC_HC_OPTS += -optc-DNOSMP
134 ifneq "$(DYNAMIC_RTS)" "YES"
135 SRC_HC_OPTS += -static
137 LIB_LD_OPTS += -ignore-package base -ignore-package rts
138 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
139 BASE_VERSION=$(strip $(shell grep version: $(TOP)/libraries/base/base.cabal | cut -f2 -d:))
140 BASE_NAME=HSbase-$(BASE_VERSION)-ghc$(ProjectVersion)$(soext)
141 BASE_DIST_LIB=$(TOP)/libraries/base/dist/build
142 BASE_IMPORT_LIBRARY=$(BASE_DIST_LIB)/lib$(BASE_NAME).a
143 LIB_DEPS=$(BASE_IMPORT_LIBRARY)
144 LIB_LD_OPTS += -L$(BASE_DIST_LIB) -l$(BASE_NAME)
145 # We extract a good bit of information out of the rts package.conf by going via ghc-pkg
146 LIB_LD_OPTS += $(foreach lib,$(shell $(GHC_PKG_INPLACE) field rts extra-libraries | sed -e s/extra-libraries://),"-l$(lib)")
147 LIB_LD_OPTS += $(foreach libdir,$(shell $(GHC_PKG_INPLACE) field rts library-dirs | sed -e s/library-dirs://),"-L$(libdir)")
151 RtsMessages_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
152 RtsFlags_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
153 RtsFlags_CC_OPTS += -DRtsWay=\"rts$(_way)\"
154 RtsFlags_CC_OPTS += -DHostPlatform=\"$(HOSTPLATFORM)\"
155 RtsFlags_CC_OPTS += -DBuildPlatform=\"$(BUILDPLATFORM)\"
156 RtsFlags_CC_OPTS += -DTargetPlatform=\"$(TARGETPLATFORM)\"
157 RtsFlags_CC_OPTS += -DGhcUnregisterised=\"$(GhcUnregisterised)\"
158 RtsFlags_CC_OPTS += -DGhcEnableTablesNextToCode=\"$(GhcEnableTablesNextToCode)\"
161 SRC_HC_OPTS += -I$$PVM_ROOT/include
164 # If -DDEBUG is in effect, adjust package conf accordingly..
165 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
166 PACKAGE_CPP_OPTS += -DDEBUG
169 ifeq "$(HaveLibMingwEx)" "YES"
170 PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
173 ifeq "$(GhciWithDebugger)" "YES"
174 STANDARD_OPTS += -DDEBUGGER
177 ifeq "$(DotnetSupport)" "YES"
180 # Would like to just use SUBDIRS here, but need to
181 # descend into dotnet/ earlier than that.
184 $(MAKE) -C dotnet all
186 # But use SUBDIRS for other recursive targets.
189 LIBOBJS += dotnet/Invoke.o
192 # Suppress uninitialized variable warnings for GC.c
193 GC_CC_OPTS += -Wno-uninitialized
195 #-----------------------------------------------------------------------------
196 # Include the Front panel code?
198 # we need GTK+ for the front panel
199 ifneq "$(GTK_CONFIG)" ""
200 ifeq "$(GhcRtsWithFrontPanel)" "YES"
201 SRC_HC_OPTS += `$(GTK_CONFIG) --cflags` -optc-DRTS_GTK_FRONTPANEL
202 VisCallbacks_CC_OPTS += -Wno-unused
203 SRC_MKDEPENDC_OPTS += `$(GTK_CONFIG) --cflags`
204 else # GhcRtsWithFrontPanel
205 EXCLUDED_SRCS += $(wildcard Vis*.c)
208 EXCLUDED_SRCS += $(wildcard Vis*.c)
211 #-----------------------------------------------------------------------------
212 # Add PAPI library if needed
214 ifeq "$(GhcRtsWithPapi)" "YES"
215 SRC_HC_OPTS += -optc-DUSE_PAPI
216 PACKAGE_CPP_OPTS += -DUSE_PAPI
219 #-----------------------------------------------------------------------------
222 SRC_MKDEPENDC_OPTS += -I. -I../includes
224 # Hack: we define every way-related option here, so that we get (hopefully)
225 # a superset of the dependencies. To do this properly, we should generate
226 # a different set of dependencies for each way. Further hack: PROFILING and
227 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
228 SRC_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
230 # -----------------------------------------------------------------------------
231 # The auto-generated apply code
233 # We want a slightly different version for the unregisterised way, so we make
234 # AutoApply on a per-way basis (eg. AutoApply_p.cmm).
236 ifneq "$(DOING_BIN_DIST)" "YES"
238 AUTO_APPLY_CMM = AutoApply$(_way).cmm
240 ifneq "$(BootingFromHc)" "YES"
241 $(AUTO_APPLY_CMM): $(GHC_GENAPPLY)
243 $(GENAPPLY) $(if $(filter $(way), u debug_u), -u) >$@
246 EXTRA_CMM_SRCS += $(AUTO_APPLY_CMM)
248 CLEAN_FILES += $(AUTO_APPLY_CMM)
252 # -----------------------------------------------------------------------------
253 # Compile GMP only if we don't have it already
255 # We use GMP's own configuration stuff, because it's all rather hairy
256 # and not worth re-implementing in our Makefile framework.
258 CLEAN_FILES += gmp/libgmp.a
260 # Need to get the GMP vars in through CPP to package.conf.in, and put
261 # quotes around each element.
264 space = $(empty) $(empty)
266 PACKAGE_CPP_OPTS += -DGMP_INCLUDE_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_INCLUDE_DIRS))))'
267 PACKAGE_CPP_OPTS += -DGMP_LIB_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_LIB_DIRS))))'
269 ifneq "$(GMP_INCLUDE_DIRS)" ""
270 SRC_HC_OPTS += -I$(GMP_INCLUDE_DIRS)
271 SRC_CC_OPTS += -I$(GMP_INCLUDE_DIRS)
272 SRC_HSC2HS_OPTS += -I$(GMP_INCLUDE_DIRS)
274 ifneq "$(GMP_LIB_DIRS)" ""
275 SRC_LD_OPTS += -L$(GMP_LIB_DIRS)
278 SRC_CC_OPTS += -I../gmp/gmpbuild
279 SRC_HC_OPTS += -I../gmp/gmpbuild
280 SRC_HSC2HS_OPTS += -I../gmp/gmpbuild
281 SRC_LD_OPTS += -L../gmp/gmpbuild
283 #-----------------------------------------------------------------------------
285 # Building the GUM SysMan
289 all :: parallel/SysMan
291 ifdef solaris2_TARGET_OS
292 __socket_libs = -lsocket -lnsl
297 parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
299 gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
301 CLEAN_FILES += parallel/SysMan.mp_o parallel/SysMan
302 INSTALL_LIBEXECS += parallel/SysMan
305 #-----------------------------------------------------------------------------
306 # Compiling the cmm files
308 # ToDo: should we really include Rts.h here? Required for GNU_ATTRIBUTE().
309 SRC_HC_OPTS += -I. -\#include HCIncludes.h
311 ifeq "$(Windows)" "YES"
312 PrimOps_HC_OPTS += -\#include '<windows.h>' -\#include win32/AsyncIO.h
314 PrimOps_HC_OPTS += -\#include posix/Itimer.h
317 # Otherwise the stack-smash handler gets triggered.
318 ifeq "$(TargetOS_CPP)" "openbsd"
319 SRC_HC_OPTS += -optc-fno-stack-protector
322 # -O3 helps unroll some loops (especially in copy() with a constant argument).
323 sm/Evac_HC_OPTS += -optc-funroll-loops
325 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
326 sm/Compact_HC_OPTS += -optc-finline-limit=2500
328 # -fno-strict-aliasing is required for the runtime, because we often
329 # use a variety of types to represent closure pointers (StgPtr,
330 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
331 # allowed to assume that these pointers do not alias. eg. without
332 # this flag we get problems in GC.c:copy() with gcc 3.4.3, the
333 # upd_evacee() assigments get moved before the object copy.
334 SRC_CC_OPTS += -fno-strict-aliasing
336 # We *want* type-checking of hand-written cmm.
337 SRC_HC_OPTS += -dcmm-lint
339 ifneq "$(BootingFromHc)" "YES"
340 # .cmm files depend on all the .h files, to a first approximation.
341 %.$(way_)o : %.cmm $(H_FILES)
343 $(HC) $(HC_OPTS) -c $< -o $@
346 %.$(way_)hc : %.cmm $(H_FILES)
347 $(HC) $(HC_OPTS) -C $< -o $@
349 %.$(way_)s : %.cmm $(H_FILES)
350 $(HC) $(HC_OPTS) -S $< -o $@
353 #-----------------------------------------------------------------------------
357 # Just libHSrts is installed uniformly across ways
360 include $(TOP)/mk/target.mk
362 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
363 $(BASE_IMPORT_LIBRARY): $(LIBRARY).a
364 $(MAKE) -C ../libraries/ make.library.base
365 # just for the timestamps
366 touch $(BASE_IMPORT_LIBRARY)
369 #-----------------------------------------------------------------------------
374 $(INSTALL_DIR) $(BIN_DIST_DIR)/rts
375 $(INSTALL_DIR) $(BIN_DIST_DIR)/rts/gmp
376 $(INSTALL_DATA) Makefile $(BIN_DIST_DIR)/rts/
377 $(INSTALL_DATA) package.conf.in $(BIN_DIST_DIR)/rts/
378 ifneq "$(INSTALL_LIBS)" ""
379 $(INSTALL_DATA) $(INSTALL_LIBS) $(BIN_DIST_DIR)/rts/
381 ifneq "$(INSTALL_LIBEXECS)" ""
382 $(INSTALL_PROGRAM) $(INSTALL_LIBEXECS) $(BIN_DIST_DIR)/rts/