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 # Other sorta independent, compile-once subdirs are:
12 # gmp -- GNU multi-precision library (for Integer)
14 #-----------------------------------------------------------------------------
19 # Set UseGhcForCc: this causes the fptools build system to use a different
20 # set of suffix rules for compiling C code, using $(HC) rather than $(CC)
21 # and prepending "-optc" to $(CC_OPTS). NB. must be done before including
22 # boilerplate.mk below.
25 include $(TOP)/mk/boilerplate.mk
31 # -----------------------------------------------------------------------------
34 WAYS=$(GhcLibWays) $(GhcRTSWays)
36 ifneq "$(findstring debug, $(way))" ""
41 # -----------------------------------------------------------------------------
43 # Tells the build system not to add various Haskellish options to $(SRC_HC_OPTS)
46 # grab sources from these subdirectories
47 ALL_DIRS = hooks parallel
49 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
55 ifneq "$(DLLized)" "YES"
56 EXCLUDED_SRCS += RtsDllMain.c
58 EXCLUDED_SRCS += Main.c
61 # This file ends up being empty unless we're building for a powerpc
62 # or darwin system, and it is reported that Solaris ld chokes on it when
64 ifeq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
65 ifeq "$(findstring $(TargetOS_CPP), darwin)" ""
66 EXCLUDED_SRCS += AdjustorAsm.S
70 EXCLUDED_SRCS += parallel/SysMan.c
72 # The build system doesn't give us these
73 CMM_SRCS = $(filter-out AutoApply%.cmm, $(wildcard *.cmm)) $(EXTRA_CMM_SRCS)
74 CMM_OBJS = $(patsubst %.cmm,%.$(way_)o, $(CMM_SRCS))
76 CLEAN_FILES += $(CMM_OBJS)
78 # Override the default $(LIBOBJS) (defaults to $(HS_OBJS))
79 LIBOBJS = $(C_OBJS) $(CMM_OBJS)
83 H_FILES = $(wildcard ../includes/*.h) $(wildcard *.h)
85 #-----------------------------------------------------------------------------
86 # Flags for compiling RTS .c and .hc files
88 # gcc provides lots of useful warnings if you ask it.
89 # This is a pretty good list to start with - use a # to comment out
93 WARNING_OPTS += -Wstrict-prototypes
94 WARNING_OPTS += -Wmissing-prototypes
95 WARNING_OPTS += -Wmissing-declarations
96 WARNING_OPTS += -Winline
97 WARNING_OPTS += -Waggregate-return
98 #WARNING_OPTS += -Wpointer-arith
99 WARNING_OPTS += -Wbad-function-cast
100 #WARNING_OPTS += -Wcast-align
101 #WARNING_OPTS += -Wnested-externs
102 #WARNING_OPTS += -Wshadow
103 #WARNING_OPTS += -Wcast-qual
104 #WARNING_OPTS += -Wno-unused
105 #WARNING_OPTS += -Wredundant-decls
106 #WARNING_OPTS += -Wconversion
108 STANDARD_OPTS += -I../includes -I. -Iparallel
109 # COMPILING_RTS is only used when building Win32 DLL support.
110 STANDARD_OPTS += -DCOMPILING_RTS
112 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
113 # only included in .c compilations. HC_OPTS included the WAY_* opts, which
114 # must be included in both types of compilations.
116 SRC_CC_OPTS += $(WARNING_OPTS)
117 SRC_CC_OPTS += $(STANDARD_OPTS)
119 SRC_CC_OPTS += $(GhcRtsCcOpts)
120 SRC_HC_OPTS += $(GhcRtsHcOpts)
122 ifneq "$(DLLized)" "YES"
123 SRC_HC_OPTS += -static
125 # SRC_HC_OPTS += -fPIC
128 SRC_HC_OPTS += -I$$PVM_ROOT/include
131 # If -DDEBUG is in effect, adjust package conf accordingly..
132 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
133 PACKAGE_CPP_OPTS += -DDEBUG
136 ifeq "$(HaveLibMingwEx)" "YES"
137 PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
140 ifeq "$(DotnetSupport)" "YES"
143 # Would like to just use SUBDIRS here, but need to
144 # descend into dotnet/ earlier than that.
147 $(MAKE) -C dotnet all
149 # But use SUBDIRS for other recursive targets.
152 LIBOBJS += dotnet/Invoke.o
155 # Suppress uninitialized variable warnings for GC.c
156 GC_CC_OPTS += -Wno-uninitialized
158 #-----------------------------------------------------------------------------
159 # Include the Front panel code?
161 # we need GTK+ for the front panel
162 ifneq "$(GTK_CONFIG)" ""
163 ifeq "$(GhcRtsWithFrontPanel)" "YES"
164 SRC_HC_OPTS += `$(GTK_CONFIG) --cflags` -optc-DRTS_GTK_FRONTPANEL
165 VisCallbacks_CC_OPTS += -Wno-unused
166 SRC_MKDEPENDC_OPTS += `$(GTK_CONFIG) --cflags`
167 else # GhcRtsWithFrontPanel
168 EXCLUDED_SRCS += $(wildcard Vis*.c)
171 EXCLUDED_SRCS += $(wildcard Vis*.c)
174 #-----------------------------------------------------------------------------
177 SRC_MKDEPENDC_OPTS += -I. -I../includes
179 # Hack: we define every way-related option here, so that we get (hopefully)
180 # a superset of the dependencies. To do this properly, we should generate
181 # a different set of dependencies for each way. Further hack: PROFILING and
182 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
183 SRC_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
185 # -----------------------------------------------------------------------------
186 # The auto-generated apply code
188 # We want a slightly different version for the unregisterised way, so we make
189 # AutoApply on a per-way basis (eg. AutoApply_p.cmm).
191 AUTO_APPLY_CMM = AutoApply$(_way).cmm
193 ifneq "$(BootingFromHc)" "YES"
194 $(AUTO_APPLY_CMM): $(GHC_GENAPPLY)
196 $(GHC_GENAPPLY) $(if $(filter $(way), u debug_u), -u) >$@
199 EXTRA_CMM_SRCS += $(AUTO_APPLY_CMM)
201 CLEAN_FILES += $(AUTO_APPLY_CMM)
203 # -----------------------------------------------------------------------------
205 # Building DLLs is only supported on mingw32 at the moment.
207 ifeq "$(DLLized)" "YES"
208 SRC_BLD_DLL_OPTS += -lHS_imp_stub -lgmp_imp
210 # It's not included in the DLL, but we need to compile it up separately.
213 # Need an import library containing the symbols the RTS uses from the Prelude.
214 # So, to avoid bootstrapping trouble, we build one containing just the syms
215 # we need. Weirdly named to avoid clashing later on when compiling the contents
218 # Note: if you do change the name of the Prelude DLL, the "--dllname <nm>.dll"
219 # below will need to be updated as well.
221 $(DLL_PEN)/HSrts$(_way).dll :: libHS_imp_stub.a
224 dlltool --output-lib libHS_imp_stub.a --def HSprel.def --dllname HSstd.dll
228 # -----------------------------------------------------------------------------
229 # Compile GMP only if we don't have it already
231 # We use GMP's own configuration stuff, because it's all rather hairy
232 # and not worth re-implementing in our Makefile framework.
234 ifneq "$(HaveLibGmp)" "YES"
235 ifneq "$(HaveFrameworkGMP)" "YES"
237 if [ -f gmp/config.status ]; then \
238 cd gmp && CC=$(WhatGccIsCalled) ./config.status; \
240 cd gmp && CC=$(WhatGccIsCalled) ./configure --enable-shared=no \
241 --host=`echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g'`; \
244 # Slight cheatage here to pass host as target, but x-compilation isn't supported by ghc.
249 ifeq "$(DLLized)" "YES"
250 all :: $(DLL_PEN)/gmp.dll
253 $(MAKE) -C gmp gmp.dll
254 $(MV) gmp/gmp.dll $(DLL_PEN)
258 install :: gmp/libgmp.a
261 clean distclean maintainer-clean ::
262 -$(MAKE) -C gmp MAKEFLAGS= $@
264 INSTALL_LIBS += gmp/libgmp.a
269 $(MAKE) -C gmp MAKEFLAGS=
270 @$(CP) gmp/.libs/libgmp.a gmp
271 @$(RANLIB) gmp/libgmp.a
274 CLEAN_FILES += gmp/libgmp.a
276 #-----------------------------------------------------------------------------
278 # Building the GUM SysMan
282 all :: parallel/SysMan
284 ifdef solaris2_TARGET_OS
285 __socket_libs = -lsocket -lnsl
290 parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
292 gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
294 CLEAN_FILES += parallel/SysMan.mp_o parallel/SysMan
295 INSTALL_LIBEXECS += parallel/SysMan
298 #-----------------------------------------------------------------------------
299 # Compiling the cmm files
301 # ToDo: should we really include Rts.h here? Required for GNU_ATTRIBUTE().
304 -\#include Prelude.h \
306 -\#include RtsFlags.h \
307 -\#include RtsUtils.h \
308 -\#include StgRun.h \
309 -\#include Schedule.h \
310 -\#include Printer.h \
311 -\#include Sanity.h \
313 -\#include Storage.h \
314 -\#include SchedAPI.h \
316 -\#include ProfHeap.h \
317 -\#include LdvProfile.h \
318 -\#include Profiling.h \
319 -\#include OSThreads.h \
323 ifeq "$(Windows)" "YES"
324 PrimOps_HC_OPTS += -\#include '<windows.h>' -\#include win32/AsyncIO.h
326 PrimOps_HC_OPTS += -\#include posix/Itimer.h
329 # -O3 helps unroll some loops (especially in copy() with a constant argument).
330 # -fno-strict-aliasing is a hack because we often mix StgPtr and StgClosure pointers
331 # to the same object, and gcc will assume these don't alias. eg. it happens in
332 # copy() with gcc 3.4.3, the upd_evacee() assigments get moved before the object copy.
333 GC_HC_OPTS += -optc-O3 -optc-fno-strict-aliasing
335 # Cmm must be compiled via-C for now, because the NCG can't handle loops
336 SRC_HC_OPTS += -fvia-C
338 # We *want* type-checking of hand-written cmm.
339 SRC_HC_OPTS += -dcmm-lint
341 ifneq "$(BootingFromHc)" "YES"
342 # .cmm files depend on all the .h files, to a first approximation.
343 %.$(way_)o : %.cmm $(H_FILES)
345 $(HC) $(HC_OPTS) -c $< -o $@
348 %.$(way_)hc : %.cmm $(H_FILES)
349 $(HC) $(HC_OPTS) -C $< -o $@
351 %.$(way_)s : %.cmm $(H_FILES)
352 $(HC) $(HC_OPTS) -S $< -o $@
355 #-----------------------------------------------------------------------------
359 # Just libHSrts is installed uniformly across ways
361 INSTALL_LIBS += $(LIBRARY)
362 ifeq "$(DLLized)" "YES"
363 INSTALL_PROGS += $(DLL_NAME) gmp/gmp.dll
364 INSTALL_LIBS += $(patsubst %.a,%_imp.a,$(LIBARY))
365 INSTALL_LIBS += gmp/libgmp_imp.a Main.dll_o
368 include $(TOP)/mk/target.mk