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 "$(DLLized)" "YES"
53 EXCLUDED_SRCS += RtsDllMain.c
55 EXCLUDED_SRCS += Main.c
58 # This file ends up being empty unless we're building for a powerpc
59 # or darwin system, and it is reported that Solaris ld chokes on it when
61 ifeq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
62 ifeq "$(findstring $(TargetOS_CPP), darwin)" ""
63 EXCLUDED_SRCS += AdjustorAsm.S
67 EXCLUDED_SRCS += parallel/SysMan.c
69 # The build system doesn't give us these
70 CMM_SRCS = $(filter-out AutoApply%.cmm, $(wildcard *.cmm)) $(EXTRA_CMM_SRCS)
71 CMM_OBJS = $(patsubst %.cmm,%.$(way_)o, $(CMM_SRCS))
73 CLEAN_FILES += $(CMM_OBJS)
75 # Override the default $(LIBOBJS) (defaults to $(HS_OBJS))
76 LIBOBJS = $(C_OBJS) $(CMM_OBJS)
80 H_FILES = $(wildcard ../includes/*.h) $(wildcard *.h)
82 #-----------------------------------------------------------------------------
83 # Flags for compiling RTS .c and .hc files
85 # gcc provides lots of useful warnings if you ask it.
86 # This is a pretty good list to start with - use a # to comment out
90 WARNING_OPTS += -Wstrict-prototypes
91 WARNING_OPTS += -Wmissing-prototypes
92 WARNING_OPTS += -Wmissing-declarations
93 WARNING_OPTS += -Winline
94 WARNING_OPTS += -Waggregate-return
95 #WARNING_OPTS += -Wpointer-arith
96 #WARNING_OPTS += -Wbad-function-cast
97 #WARNING_OPTS += -Wcast-align
98 #WARNING_OPTS += -Wnested-externs
99 #WARNING_OPTS += -Wshadow
100 #WARNING_OPTS += -Wcast-qual
101 #WARNING_OPTS += -Wno-unused
102 #WARNING_OPTS += -Wredundant-decls
103 #WARNING_OPTS += -Wconversion
105 STANDARD_OPTS += -I../includes -I. -Iparallel -Ism
106 # COMPILING_RTS is only used when building Win32 DLL support.
107 STANDARD_OPTS += -DCOMPILING_RTS
109 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
110 # only included in .c compilations. HC_OPTS included the WAY_* opts, which
111 # must be included in both types of compilations.
113 SRC_CC_OPTS += $(WARNING_OPTS)
114 SRC_CC_OPTS += $(STANDARD_OPTS)
116 SRC_CC_OPTS += $(GhcRtsCcOpts)
117 SRC_HC_OPTS += $(GhcRtsHcOpts)
119 ifneq "$(GhcWithSMP)" "YES"
120 SRC_CC_OPTS += -DNOSMP
121 SRC_HC_OPTS += -optc-DNOSMP
124 ifneq "$(DLLized)" "YES"
125 SRC_HC_OPTS += -static
127 # SRC_HC_OPTS += -fPIC
129 RtsMessages_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
130 RtsFlags_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
131 RtsFlags_CC_OPTS += -DRtsWay=\"rts$(_way)\"
132 RtsFlags_CC_OPTS += -DHostPlatform=\"$(HOSTPLATFORM)\"
133 RtsFlags_CC_OPTS += -DBuildPlatform=\"$(BUILDPLATFORM)\"
134 RtsFlags_CC_OPTS += -DTargetPlatform=\"$(TARGETPLATFORM)\"
137 SRC_HC_OPTS += -I$$PVM_ROOT/include
140 # If -DDEBUG is in effect, adjust package conf accordingly..
141 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
142 PACKAGE_CPP_OPTS += -DDEBUG
145 ifeq "$(HaveLibMingwEx)" "YES"
146 PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
149 ifeq "$(GhciWithDebugger)" "YES"
150 STANDARD_OPTS += -DDEBUGGER
153 ifeq "$(DotnetSupport)" "YES"
156 # Would like to just use SUBDIRS here, but need to
157 # descend into dotnet/ earlier than that.
160 $(MAKE) -C dotnet all
162 # But use SUBDIRS for other recursive targets.
165 LIBOBJS += dotnet/Invoke.o
168 # Suppress uninitialized variable warnings for GC.c
169 GC_CC_OPTS += -Wno-uninitialized
171 #-----------------------------------------------------------------------------
172 # Include the Front panel code?
174 # we need GTK+ for the front panel
175 ifneq "$(GTK_CONFIG)" ""
176 ifeq "$(GhcRtsWithFrontPanel)" "YES"
177 SRC_HC_OPTS += `$(GTK_CONFIG) --cflags` -optc-DRTS_GTK_FRONTPANEL
178 VisCallbacks_CC_OPTS += -Wno-unused
179 SRC_MKDEPENDC_OPTS += `$(GTK_CONFIG) --cflags`
180 else # GhcRtsWithFrontPanel
181 EXCLUDED_SRCS += $(wildcard Vis*.c)
184 EXCLUDED_SRCS += $(wildcard Vis*.c)
187 #-----------------------------------------------------------------------------
188 # Add PAPI library if needed
190 ifeq "$(GhcRtsWithPapi)" "YES"
191 SRC_HC_OPTS += -optc-DUSE_PAPI
192 PACKAGE_CPP_OPTS += -DUSE_PAPI
195 #-----------------------------------------------------------------------------
198 SRC_MKDEPENDC_OPTS += -I. -I../includes
200 # Hack: we define every way-related option here, so that we get (hopefully)
201 # a superset of the dependencies. To do this properly, we should generate
202 # a different set of dependencies for each way. Further hack: PROFILING and
203 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
204 SRC_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
206 # -----------------------------------------------------------------------------
207 # The auto-generated apply code
209 # We want a slightly different version for the unregisterised way, so we make
210 # AutoApply on a per-way basis (eg. AutoApply_p.cmm).
212 ifneq "$(DOING_BIN_DIST)" "YES"
214 AUTO_APPLY_CMM = AutoApply$(_way).cmm
216 ifneq "$(BootingFromHc)" "YES"
217 $(AUTO_APPLY_CMM): $(GHC_GENAPPLY)
219 $(GENAPPLY) $(if $(filter $(way), u debug_u), -u) >$@
222 EXTRA_CMM_SRCS += $(AUTO_APPLY_CMM)
224 CLEAN_FILES += $(AUTO_APPLY_CMM)
228 # -----------------------------------------------------------------------------
230 # Building DLLs is only supported on mingw32 at the moment.
232 ifeq "$(DLLized)" "YES"
233 SRC_BLD_DLL_OPTS += -lHS_imp_stub -lgmp_imp
235 # It's not included in the DLL, but we need to compile it up separately.
238 # Need an import library containing the symbols the RTS uses from the Prelude.
239 # So, to avoid bootstrapping trouble, we build one containing just the syms
240 # we need. Weirdly named to avoid clashing later on when compiling the contents
243 # Note: if you do change the name of the Prelude DLL, the "--dllname <nm>.dll"
244 # below will need to be updated as well.
246 $(DLL_PEN)/HSrts$(_way).dll :: libHS_imp_stub.a
249 dlltool --output-lib libHS_imp_stub.a --def HSprel.def --dllname HSstd.dll
253 # -----------------------------------------------------------------------------
254 # Compile GMP only if we don't have it already
256 # We use GMP's own configuration stuff, because it's all rather hairy
257 # and not worth re-implementing in our Makefile framework.
259 CLEAN_FILES += gmp/libgmp.a
261 # Need to get the GMP vars in through CPP to package.conf.in, and put
262 # quotes around each element.
265 space = $(empty) $(empty)
267 PACKAGE_CPP_OPTS += -DGMP_INCLUDE_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_INCLUDE_DIRS))))'
268 PACKAGE_CPP_OPTS += -DGMP_LIB_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_LIB_DIRS))))'
270 ifneq "$(GMP_INCLUDE_DIRS)" ""
271 SRC_HC_OPTS += -I$(GMP_INCLUDE_DIRS)
272 SRC_CC_OPTS += -I$(GMP_INCLUDE_DIRS)
273 SRC_HSC2HS_OPTS += -I$(GMP_INCLUDE_DIRS)
275 ifneq "$(GMP_LIB_DIRS)" ""
276 SRC_LD_OPTS += -L$(GMP_LIB_DIRS)
279 SRC_CC_OPTS += -I../gmp/gmpbuild
280 SRC_HC_OPTS += -I../gmp/gmpbuild
281 SRC_HSC2HS_OPTS += -I../gmp/gmpbuild
282 SRC_LD_OPTS += -L../gmp/gmpbuild
284 #-----------------------------------------------------------------------------
286 # Building the GUM SysMan
290 all :: parallel/SysMan
292 ifdef solaris2_TARGET_OS
293 __socket_libs = -lsocket -lnsl
298 parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
300 gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
302 CLEAN_FILES += parallel/SysMan.mp_o parallel/SysMan
303 INSTALL_LIBEXECS += parallel/SysMan
306 #-----------------------------------------------------------------------------
307 # Compiling the cmm files
309 # ToDo: should we really include Rts.h here? Required for GNU_ATTRIBUTE().
310 SRC_HC_OPTS += -I. -\#include HCIncludes.h
312 ifeq "$(Windows)" "YES"
313 PrimOps_HC_OPTS += -\#include '<windows.h>' -\#include win32/AsyncIO.h
315 PrimOps_HC_OPTS += -\#include posix/Itimer.h
318 # Otherwise the stack-smash handler gets triggered.
319 ifeq "$(TargetOS_CPP)" "openbsd"
320 SRC_HC_OPTS += -optc-fno-stack-protector
323 # -O3 helps unroll some loops (especially in copy() with a constant argument).
324 sm/Evac_HC_OPTS += -optc-funroll-loops
326 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
327 sm/Compact_HC_OPTS += -optc-finline-limit=2500
329 # -fno-strict-aliasing is required for the runtime, because we often
330 # use a variety of types to represent closure pointers (StgPtr,
331 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
332 # allowed to assume that these pointers do not alias. eg. without
333 # this flag we get problems in GC.c:copy() with gcc 3.4.3, the
334 # upd_evacee() assigments get moved before the object copy.
335 SRC_CC_OPTS += -fno-strict-aliasing
337 # Cmm must be compiled via-C for now, because the NCG can't handle loops
338 SRC_HC_OPTS += -fvia-C
340 # We *want* type-checking of hand-written cmm.
341 SRC_HC_OPTS += -dcmm-lint
343 ifneq "$(BootingFromHc)" "YES"
344 # .cmm files depend on all the .h files, to a first approximation.
345 %.$(way_)o : %.cmm $(H_FILES)
347 $(HC) $(HC_OPTS) -c $< -o $@
350 %.$(way_)hc : %.cmm $(H_FILES)
351 $(HC) $(HC_OPTS) -C $< -o $@
353 %.$(way_)s : %.cmm $(H_FILES)
354 $(HC) $(HC_OPTS) -S $< -o $@
357 #-----------------------------------------------------------------------------
361 # Just libHSrts is installed uniformly across ways
363 ifeq "$(DLLized)" "YES"
364 INSTALL_PROGS += gmp/gmp.dll
365 INSTALL_LIBS += gmp/libgmp_imp.a Main.dll_o
368 #-----------------------------------------------------------------------------
372 include $(TOP)/mk/target.mk
375 $(INSTALL_DIR) $(BIN_DIST_DIR)/rts
376 $(INSTALL_DIR) $(BIN_DIST_DIR)/rts/gmp
377 $(INSTALL_DATA) Makefile $(BIN_DIST_DIR)/rts/
378 $(INSTALL_DATA) package.conf.in $(BIN_DIST_DIR)/rts/
379 ifneq "$(INSTALL_LIBS)" ""
380 $(INSTALL_DATA) $(INSTALL_LIBS) $(BIN_DIST_DIR)/rts/
382 ifneq "$(INSTALL_LIBEXECS)" ""
383 $(INSTALL_PROGRAM) $(INSTALL_LIBEXECS) $(BIN_DIST_DIR)/rts/