Add unreg/tables-next-code output to +RTS --info
[ghc-hetmet.git] / rts / Makefile
1 #-----------------------------------------------------------------------------
2 #
3 #  This is the Makefile for the runtime-system stuff.
4 #  This stuff is written in C (and cannot be written in Haskell).
5 #
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.
10
11 #-----------------------------------------------------------------------------
12 # Preamble
13
14 TOP=..
15
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.
20 UseGhcForCc = YES
21
22 include $(TOP)/mk/boilerplate.mk
23
24 PACKAGE = rts
25
26 HC=$(GHC_INPLACE)
27
28 # -----------------------------------------------------------------------------
29 # RTS ways
30
31 WAYS=$(GhcLibWays) $(GhcRTSWays)
32
33 ifneq "$(findstring debug, $(way))" ""
34 GhcRtsHcOpts=
35 GhcRtsCcOpts=-g -O0
36 endif
37
38 # -----------------------------------------------------------------------------
39
40 # Tells the build system not to add various Haskellish options to $(SRC_HC_OPTS)
41 NON_HS_PACKAGE = YES
42
43 # grab sources from these subdirectories
44 ALL_DIRS = hooks parallel sm
45
46 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
47 ALL_DIRS += win32
48 else
49 ALL_DIRS += posix
50 endif
51
52 ifneq "$(DLLized)" "YES"
53 EXCLUDED_SRCS += RtsDllMain.c
54 else
55 EXCLUDED_SRCS += Main.c
56 endif
57
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
60 # building HSrts.o.
61 ifeq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
62 ifeq "$(findstring $(TargetOS_CPP), darwin)" ""
63 EXCLUDED_SRCS += AdjustorAsm.S
64 endif
65 endif
66
67 EXCLUDED_SRCS += parallel/SysMan.c
68
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))
72
73 CLEAN_FILES += $(CMM_OBJS)
74
75 # Override the default $(LIBOBJS) (defaults to $(HS_OBJS))
76 LIBOBJS = $(C_OBJS) $(CMM_OBJS)
77
78 SplitObjs=NO
79
80 H_FILES = $(wildcard ../includes/*.h) $(wildcard *.h)
81
82 #-----------------------------------------------------------------------------
83 # Flags for compiling RTS .c and .hc files
84
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
87 # any you don't like.
88 WARNING_OPTS += -Wall
89 WARNING_OPTS += -W
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
104
105 STANDARD_OPTS += -I../includes -I. -Iparallel -Ism
106 # COMPILING_RTS is only used when building Win32 DLL support.
107 STANDARD_OPTS += -DCOMPILING_RTS
108
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.
112
113 SRC_CC_OPTS += $(WARNING_OPTS)
114 SRC_CC_OPTS += $(STANDARD_OPTS)
115
116 SRC_CC_OPTS += $(GhcRtsCcOpts)
117 SRC_HC_OPTS += $(GhcRtsHcOpts)
118
119 ifneq "$(GhcWithSMP)" "YES"
120 SRC_CC_OPTS += -DNOSMP
121 SRC_HC_OPTS += -optc-DNOSMP
122 endif
123
124 ifneq "$(DLLized)" "YES"
125 SRC_HC_OPTS += -static
126 endif
127 # SRC_HC_OPTS += -fPIC
128
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)\"
135 RtsFlags_CC_OPTS += -DGhcUnregisterised=\"$(GhcUnregisterised)\"
136 RtsFlags_CC_OPTS += -DGhcEnableTablesNextToCode=\"$(GhcEnableTablesNextToCode)\"
137
138 ifeq "$(way)" "mp"
139 SRC_HC_OPTS += -I$$PVM_ROOT/include
140 endif
141
142 # If -DDEBUG is in effect, adjust package conf accordingly..
143 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
144 PACKAGE_CPP_OPTS += -DDEBUG
145 endif
146
147 ifeq "$(HaveLibMingwEx)" "YES"
148 PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
149 endif
150
151 ifeq "$(GhciWithDebugger)" "YES"
152 STANDARD_OPTS += -DDEBUGGER
153 endif
154
155 ifeq "$(DotnetSupport)" "YES"
156
157
158 # Would like to just use SUBDIRS here, but need to
159 # descend into dotnet/ earlier than that.
160 #
161 all ::
162         $(MAKE) -C dotnet all
163
164 # But use SUBDIRS for other recursive targets.
165 SUBDIRS += dotnet
166
167 LIBOBJS += dotnet/Invoke.o
168 endif
169
170 # Suppress uninitialized variable warnings for GC.c
171 GC_CC_OPTS      += -Wno-uninitialized
172
173 #-----------------------------------------------------------------------------
174 # Include the Front panel code?
175
176 # we need GTK+ for the front panel
177 ifneq "$(GTK_CONFIG)" ""
178 ifeq "$(GhcRtsWithFrontPanel)" "YES"
179 SRC_HC_OPTS             += `$(GTK_CONFIG) --cflags` -optc-DRTS_GTK_FRONTPANEL
180 VisCallbacks_CC_OPTS    += -Wno-unused
181 SRC_MKDEPENDC_OPTS      += `$(GTK_CONFIG) --cflags`
182 else # GhcRtsWithFrontPanel
183 EXCLUDED_SRCS           += $(wildcard Vis*.c)
184 endif
185 else # GTK_CONFIG
186 EXCLUDED_SRCS           += $(wildcard Vis*.c)
187 endif
188
189 #-----------------------------------------------------------------------------
190 # Add PAPI library if needed
191
192 ifeq "$(GhcRtsWithPapi)" "YES"
193 SRC_HC_OPTS             += -optc-DUSE_PAPI
194 PACKAGE_CPP_OPTS        += -DUSE_PAPI
195 endif
196
197 #-----------------------------------------------------------------------------
198 # make depend setup
199
200 SRC_MKDEPENDC_OPTS += -I. -I../includes
201
202 # Hack: we define every way-related option here, so that we get (hopefully)
203 # a superset of the dependencies.  To do this properly, we should generate
204 # a different set of dependencies for each way.  Further hack: PROFILING and
205 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
206 SRC_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
207
208 # -----------------------------------------------------------------------------
209 # The auto-generated apply code
210
211 # We want a slightly different version for the unregisterised way, so we make
212 # AutoApply on a per-way basis (eg. AutoApply_p.cmm).
213
214 ifneq "$(DOING_BIN_DIST)" "YES"
215
216 AUTO_APPLY_CMM = AutoApply$(_way).cmm
217
218 ifneq "$(BootingFromHc)" "YES"
219 $(AUTO_APPLY_CMM): $(GHC_GENAPPLY)
220         @$(RM) $@
221         $(GENAPPLY) $(if $(filter $(way), u debug_u), -u) >$@
222 endif
223
224 EXTRA_CMM_SRCS += $(AUTO_APPLY_CMM)
225
226 CLEAN_FILES += $(AUTO_APPLY_CMM)
227
228 endif
229
230 # -----------------------------------------------------------------------------
231 #
232 #  Building DLLs is only supported on mingw32 at the moment.
233 #
234 ifeq "$(DLLized)" "YES"
235 SRC_BLD_DLL_OPTS += -lHS_imp_stub -lgmp_imp
236
237 # It's not included in the DLL, but we need to compile it up separately.
238 all :: Main.dll_o
239
240 # Need an import library containing the symbols the RTS uses from the Prelude.
241 # So, to avoid bootstrapping trouble, we build one containing just the syms
242 # we need. Weirdly named to avoid clashing later on when compiling the contents
243 # of ghc/lib/..
244 #
245 # Note: if you do change the name of the Prelude DLL, the "--dllname <nm>.dll"
246 # below will need to be updated as well.
247
248 $(DLL_PEN)/HSrts$(_way).dll :: libHS_imp_stub.a
249
250 libHS_imp_stub.a :
251         dlltool --output-lib libHS_imp_stub.a --def HSprel.def --dllname HSstd.dll
252
253 endif
254
255 # -----------------------------------------------------------------------------
256 # Compile GMP only if we don't have it already
257 #
258 # We use GMP's own configuration stuff, because it's all rather hairy
259 # and not worth re-implementing in our Makefile framework.
260
261 CLEAN_FILES += gmp/libgmp.a
262
263 # Need to get the GMP vars in through CPP to package.conf.in, and put
264 # quotes around each element.
265
266 empty =
267 space = $(empty) $(empty)
268 comma = ,
269 PACKAGE_CPP_OPTS += -DGMP_INCLUDE_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_INCLUDE_DIRS))))'
270 PACKAGE_CPP_OPTS += -DGMP_LIB_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_LIB_DIRS))))'
271
272 ifneq "$(GMP_INCLUDE_DIRS)" ""
273 SRC_HC_OPTS += -I$(GMP_INCLUDE_DIRS)
274 SRC_CC_OPTS += -I$(GMP_INCLUDE_DIRS)
275 SRC_HSC2HS_OPTS += -I$(GMP_INCLUDE_DIRS)
276 endif
277 ifneq "$(GMP_LIB_DIRS)" ""
278 SRC_LD_OPTS += -L$(GMP_LIB_DIRS)
279 endif
280
281 SRC_CC_OPTS += -I../gmp/gmpbuild
282 SRC_HC_OPTS += -I../gmp/gmpbuild
283 SRC_HSC2HS_OPTS += -I../gmp/gmpbuild
284 SRC_LD_OPTS += -L../gmp/gmpbuild
285
286 #-----------------------------------------------------------------------------
287 #
288 # Building the GUM SysMan
289 #
290
291 ifeq "$(way)" "mp"
292 all :: parallel/SysMan
293
294 ifdef solaris2_TARGET_OS
295 __socket_libs = -lsocket -lnsl
296 else
297 __socket_libs =
298 endif
299
300 parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
301         $(RM) $@
302         gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
303
304 CLEAN_FILES  += parallel/SysMan.mp_o parallel/SysMan
305 INSTALL_LIBEXECS += parallel/SysMan
306 endif
307
308 #-----------------------------------------------------------------------------
309 # Compiling the cmm files
310
311 # ToDo: should we really include Rts.h here?  Required for GNU_ATTRIBUTE().
312 SRC_HC_OPTS += -I. -\#include HCIncludes.h
313
314 ifeq "$(Windows)" "YES"
315 PrimOps_HC_OPTS += -\#include '<windows.h>' -\#include win32/AsyncIO.h
316 else
317 PrimOps_HC_OPTS += -\#include posix/Itimer.h
318 endif
319
320 # Otherwise the stack-smash handler gets triggered.
321 ifeq "$(TargetOS_CPP)" "openbsd"
322 SRC_HC_OPTS += -optc-fno-stack-protector
323 endif
324
325 # -O3 helps unroll some loops (especially in copy() with a constant argument).
326 sm/Evac_HC_OPTS += -optc-funroll-loops
327
328 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
329 sm/Compact_HC_OPTS += -optc-finline-limit=2500
330
331 # -fno-strict-aliasing is required for the runtime, because we often
332 # use a variety of types to represent closure pointers (StgPtr,
333 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
334 # allowed to assume that these pointers do not alias.  eg. without
335 # this flag we get problems in GC.c:copy() with gcc 3.4.3, the
336 # upd_evacee() assigments get moved before the object copy.
337 SRC_CC_OPTS += -fno-strict-aliasing
338
339 # Cmm must be compiled via-C for now, because the NCG can't handle loops
340 SRC_HC_OPTS += -fvia-C
341
342 # We *want* type-checking of hand-written cmm.
343 SRC_HC_OPTS += -dcmm-lint 
344
345 ifneq "$(BootingFromHc)" "YES"
346 # .cmm files depend on all the .h files, to a first approximation.
347 %.$(way_)o : %.cmm $(H_FILES)
348         $(HC_PRE_OPTS)
349         $(HC) $(HC_OPTS) -c $< -o $@
350         $(HC_POST_OPTS)
351
352 %.$(way_)hc : %.cmm $(H_FILES)
353         $(HC) $(HC_OPTS) -C $< -o $@
354
355 %.$(way_)s : %.cmm $(H_FILES)
356         $(HC) $(HC_OPTS) -S $< -o $@
357 endif
358
359 #-----------------------------------------------------------------------------
360 #
361 # Files to install
362 #
363 # Just libHSrts is installed uniformly across ways
364 #
365 ifeq "$(DLLized)" "YES"
366 INSTALL_PROGS += gmp/gmp.dll
367 INSTALL_LIBS += gmp/libgmp_imp.a Main.dll_o
368 endif
369
370 #-----------------------------------------------------------------------------
371 #
372 # binary-dist
373
374 include $(TOP)/mk/target.mk
375
376 binary-dist:
377         $(INSTALL_DIR)                         $(BIN_DIST_DIR)/rts
378         $(INSTALL_DIR)                         $(BIN_DIST_DIR)/rts/gmp
379         $(INSTALL_DATA)    Makefile            $(BIN_DIST_DIR)/rts/
380         $(INSTALL_DATA)    package.conf.in     $(BIN_DIST_DIR)/rts/
381 ifneq "$(INSTALL_LIBS)" ""
382         $(INSTALL_DATA)    $(INSTALL_LIBS)     $(BIN_DIST_DIR)/rts/
383 endif
384 ifneq "$(INSTALL_LIBEXECS)" ""
385         $(INSTALL_PROGRAM) $(INSTALL_LIBEXECS) $(BIN_DIST_DIR)/rts/
386 endif