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)\"
132 SRC_HC_OPTS += -I$$PVM_ROOT/include
135 # If -DDEBUG is in effect, adjust package conf accordingly..
136 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
137 PACKAGE_CPP_OPTS += -DDEBUG
140 ifeq "$(HaveLibMingwEx)" "YES"
141 PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
144 ifeq "$(GhciWithDebugger)" "YES"
145 STANDARD_OPTS += -DDEBUGGER
148 ifeq "$(DotnetSupport)" "YES"
151 # Would like to just use SUBDIRS here, but need to
152 # descend into dotnet/ earlier than that.
155 $(MAKE) -C dotnet all
157 # But use SUBDIRS for other recursive targets.
160 LIBOBJS += dotnet/Invoke.o
163 # Suppress uninitialized variable warnings for GC.c
164 GC_CC_OPTS += -Wno-uninitialized
166 #-----------------------------------------------------------------------------
167 # Include the Front panel code?
169 # we need GTK+ for the front panel
170 ifneq "$(GTK_CONFIG)" ""
171 ifeq "$(GhcRtsWithFrontPanel)" "YES"
172 SRC_HC_OPTS += `$(GTK_CONFIG) --cflags` -optc-DRTS_GTK_FRONTPANEL
173 VisCallbacks_CC_OPTS += -Wno-unused
174 SRC_MKDEPENDC_OPTS += `$(GTK_CONFIG) --cflags`
175 else # GhcRtsWithFrontPanel
176 EXCLUDED_SRCS += $(wildcard Vis*.c)
179 EXCLUDED_SRCS += $(wildcard Vis*.c)
182 #-----------------------------------------------------------------------------
183 # Add PAPI library if needed
185 ifeq "$(GhcRtsWithPapi)" "YES"
186 SRC_HC_OPTS += -optc-DUSE_PAPI
187 PACKAGE_CPP_OPTS += -DUSE_PAPI
190 #-----------------------------------------------------------------------------
193 SRC_MKDEPENDC_OPTS += -I. -I../includes
195 # Hack: we define every way-related option here, so that we get (hopefully)
196 # a superset of the dependencies. To do this properly, we should generate
197 # a different set of dependencies for each way. Further hack: PROFILING and
198 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
199 SRC_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
201 # -----------------------------------------------------------------------------
202 # The auto-generated apply code
204 # We want a slightly different version for the unregisterised way, so we make
205 # AutoApply on a per-way basis (eg. AutoApply_p.cmm).
207 ifneq "$(DOING_BIN_DIST)" "YES"
209 AUTO_APPLY_CMM = AutoApply$(_way).cmm
211 ifneq "$(BootingFromHc)" "YES"
212 $(AUTO_APPLY_CMM): $(GHC_GENAPPLY)
214 $(GENAPPLY) $(if $(filter $(way), u debug_u), -u) >$@
217 EXTRA_CMM_SRCS += $(AUTO_APPLY_CMM)
219 CLEAN_FILES += $(AUTO_APPLY_CMM)
223 # -----------------------------------------------------------------------------
225 # Building DLLs is only supported on mingw32 at the moment.
227 ifeq "$(DLLized)" "YES"
228 SRC_BLD_DLL_OPTS += -lHS_imp_stub -lgmp_imp
230 # It's not included in the DLL, but we need to compile it up separately.
233 # Need an import library containing the symbols the RTS uses from the Prelude.
234 # So, to avoid bootstrapping trouble, we build one containing just the syms
235 # we need. Weirdly named to avoid clashing later on when compiling the contents
238 # Note: if you do change the name of the Prelude DLL, the "--dllname <nm>.dll"
239 # below will need to be updated as well.
241 $(DLL_PEN)/HSrts$(_way).dll :: libHS_imp_stub.a
244 dlltool --output-lib libHS_imp_stub.a --def HSprel.def --dllname HSstd.dll
248 # -----------------------------------------------------------------------------
249 # Compile GMP only if we don't have it already
251 # We use GMP's own configuration stuff, because it's all rather hairy
252 # and not worth re-implementing in our Makefile framework.
254 CLEAN_FILES += gmp/libgmp.a
256 # Need to get the GMP vars in through CPP to package.conf.in, and put
257 # quotes around each element.
260 space = $(empty) $(empty)
262 PACKAGE_CPP_OPTS += -DGMP_INCLUDE_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_INCLUDE_DIRS))))'
263 PACKAGE_CPP_OPTS += -DGMP_LIB_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_LIB_DIRS))))'
265 ifneq "$(GMP_INCLUDE_DIRS)" ""
266 SRC_HC_OPTS += -I$(GMP_INCLUDE_DIRS)
267 SRC_CC_OPTS += -I$(GMP_INCLUDE_DIRS)
268 SRC_HSC2HS_OPTS += -I$(GMP_INCLUDE_DIRS)
270 ifneq "$(GMP_LIB_DIRS)" ""
271 SRC_LD_OPTS += -L$(GMP_LIB_DIRS)
274 SRC_CC_OPTS += -I../gmp/gmpbuild
275 SRC_HC_OPTS += -I../gmp/gmpbuild
276 SRC_HSC2HS_OPTS += -I../gmp/gmpbuild
277 SRC_LD_OPTS += -L../gmp/gmpbuild
279 #-----------------------------------------------------------------------------
281 # Building the GUM SysMan
285 all :: parallel/SysMan
287 ifdef solaris2_TARGET_OS
288 __socket_libs = -lsocket -lnsl
293 parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
295 gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
297 CLEAN_FILES += parallel/SysMan.mp_o parallel/SysMan
298 INSTALL_LIBEXECS += parallel/SysMan
301 #-----------------------------------------------------------------------------
302 # Compiling the cmm files
304 # ToDo: should we really include Rts.h here? Required for GNU_ATTRIBUTE().
305 SRC_HC_OPTS += -I. -\#include HCIncludes.h
307 ifeq "$(Windows)" "YES"
308 PrimOps_HC_OPTS += -\#include '<windows.h>' -\#include win32/AsyncIO.h
310 PrimOps_HC_OPTS += -\#include posix/Itimer.h
313 # Otherwise the stack-smash handler gets triggered.
314 ifeq "$(TargetOS_CPP)" "openbsd"
315 SRC_HC_OPTS += -optc-fno-stack-protector
318 # -O3 helps unroll some loops (especially in copy() with a constant argument).
319 sm/Evac_HC_OPTS += -optc-funroll-loops
321 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
322 sm/Compact_HC_OPTS += -optc-finline-limit=2500
324 # -fno-strict-aliasing is required for the runtime, because we often
325 # use a variety of types to represent closure pointers (StgPtr,
326 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
327 # allowed to assume that these pointers do not alias. eg. without
328 # this flag we get problems in GC.c:copy() with gcc 3.4.3, the
329 # upd_evacee() assigments get moved before the object copy.
330 SRC_CC_OPTS += -fno-strict-aliasing
332 # Cmm must be compiled via-C for now, because the NCG can't handle loops
333 SRC_HC_OPTS += -fvia-C
335 # We *want* type-checking of hand-written cmm.
336 SRC_HC_OPTS += -dcmm-lint
338 ifneq "$(BootingFromHc)" "YES"
339 # .cmm files depend on all the .h files, to a first approximation.
340 %.$(way_)o : %.cmm $(H_FILES)
342 $(HC) $(HC_OPTS) -c $< -o $@
345 %.$(way_)hc : %.cmm $(H_FILES)
346 $(HC) $(HC_OPTS) -C $< -o $@
348 %.$(way_)s : %.cmm $(H_FILES)
349 $(HC) $(HC_OPTS) -S $< -o $@
352 #-----------------------------------------------------------------------------
356 # Just libHSrts is installed uniformly across ways
358 ifeq "$(DLLized)" "YES"
359 INSTALL_PROGS += gmp/gmp.dll
360 INSTALL_LIBS += gmp/libgmp_imp.a Main.dll_o
363 #-----------------------------------------------------------------------------
367 include $(TOP)/mk/target.mk
370 $(INSTALL_DIR) $(BIN_DIST_DIR)/rts
371 $(INSTALL_DIR) $(BIN_DIST_DIR)/rts/gmp
372 $(INSTALL_DATA) Makefile $(BIN_DIST_DIR)/rts/
373 $(INSTALL_DATA) package.conf.in $(BIN_DIST_DIR)/rts/
374 ifneq "$(INSTALL_LIBS)" ""
375 $(INSTALL_DATA) $(INSTALL_LIBS) $(BIN_DIST_DIR)/rts/
377 ifneq "$(INSTALL_LIBEXECS)" ""
378 $(INSTALL_PROGRAM) $(INSTALL_LIBEXECS) $(BIN_DIST_DIR)/rts/