Fix the +RTS -V0 option introduced recently; it didn't work at all, now it does.
[ghc.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
131 ifeq "$(way)" "mp"
132 SRC_HC_OPTS += -I$$PVM_ROOT/include
133 endif
134
135 # If -DDEBUG is in effect, adjust package conf accordingly..
136 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
137 PACKAGE_CPP_OPTS += -DDEBUG
138 endif
139
140 ifeq "$(HaveLibMingwEx)" "YES"
141 PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
142 endif
143
144 ifeq "$(GhciWithDebugger)" "YES"
145 STANDARD_OPTS += -DDEBUGGER
146 endif
147
148 ifeq "$(DotnetSupport)" "YES"
149
150 #
151 # Would like to just use SUBDIRS here, but need to
152 # descend into dotnet/ earlier than that.
153 #
154 all ::
155 $(MAKE) -C dotnet all
156
157 # But use SUBDIRS for other recursive targets.
158 SUBDIRS += dotnet
159
160 LIBOBJS += dotnet/Invoke.o
161 endif
162
163 # Suppress uninitialized variable warnings for GC.c
164 GC_CC_OPTS += -Wno-uninitialized
165
166 #-----------------------------------------------------------------------------
167 # Include the Front panel code?
168
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)
177 endif
178 else # GTK_CONFIG
179 EXCLUDED_SRCS += $(wildcard Vis*.c)
180 endif
181
182 #-----------------------------------------------------------------------------
183 # Add PAPI library if needed
184
185 ifeq "$(GhcRtsWithPapi)" "YES"
186 SRC_HC_OPTS += -optc-DUSE_PAPI
187 PACKAGE_CPP_OPTS += -DUSE_PAPI
188 endif
189
190 #-----------------------------------------------------------------------------
191 # make depend setup
192
193 SRC_MKDEPENDC_OPTS += -I. -I../includes
194
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
200
201 # -----------------------------------------------------------------------------
202 # The auto-generated apply code
203
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).
206
207 ifneq "$(DOING_BIN_DIST)" "YES"
208
209 AUTO_APPLY_CMM = AutoApply$(_way).cmm
210
211 ifneq "$(BootingFromHc)" "YES"
212 $(AUTO_APPLY_CMM): $(GHC_GENAPPLY)
213 @$(RM) $@
214 $(GENAPPLY) $(if $(filter $(way), u debug_u), -u) >$@
215 endif
216
217 EXTRA_CMM_SRCS += $(AUTO_APPLY_CMM)
218
219 CLEAN_FILES += $(AUTO_APPLY_CMM)
220
221 endif
222
223 # -----------------------------------------------------------------------------
224 #
225 # Building DLLs is only supported on mingw32 at the moment.
226 #
227 ifeq "$(DLLized)" "YES"
228 SRC_BLD_DLL_OPTS += -lHS_imp_stub -lgmp_imp
229
230 # It's not included in the DLL, but we need to compile it up separately.
231 all :: Main.dll_o
232
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
236 # of ghc/lib/..
237 #
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.
240
241 $(DLL_PEN)/HSrts$(_way).dll :: libHS_imp_stub.a
242
243 libHS_imp_stub.a :
244 dlltool --output-lib libHS_imp_stub.a --def HSprel.def --dllname HSstd.dll
245
246 endif
247
248 # -----------------------------------------------------------------------------
249 # Compile GMP only if we don't have it already
250 #
251 # We use GMP's own configuration stuff, because it's all rather hairy
252 # and not worth re-implementing in our Makefile framework.
253
254 CLEAN_FILES += gmp/libgmp.a
255
256 # Need to get the GMP vars in through CPP to package.conf.in, and put
257 # quotes around each element.
258
259 empty =
260 space = $(empty) $(empty)
261 comma = ,
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))))'
264
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)
269 endif
270 ifneq "$(GMP_LIB_DIRS)" ""
271 SRC_LD_OPTS += -L$(GMP_LIB_DIRS)
272 endif
273
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
278
279 #-----------------------------------------------------------------------------
280 #
281 # Building the GUM SysMan
282 #
283
284 ifeq "$(way)" "mp"
285 all :: parallel/SysMan
286
287 ifdef solaris2_TARGET_OS
288 __socket_libs = -lsocket -lnsl
289 else
290 __socket_libs =
291 endif
292
293 parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
294 $(RM) $@
295 gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
296
297 CLEAN_FILES += parallel/SysMan.mp_o parallel/SysMan
298 INSTALL_LIBEXECS += parallel/SysMan
299 endif
300
301 #-----------------------------------------------------------------------------
302 # Compiling the cmm files
303
304 # ToDo: should we really include Rts.h here? Required for GNU_ATTRIBUTE().
305 SRC_HC_OPTS += -I. -\#include HCIncludes.h
306
307 ifeq "$(Windows)" "YES"
308 PrimOps_HC_OPTS += -\#include '<windows.h>' -\#include win32/AsyncIO.h
309 else
310 PrimOps_HC_OPTS += -\#include posix/Itimer.h
311 endif
312
313 # Otherwise the stack-smash handler gets triggered.
314 ifeq "$(TargetOS_CPP)" "openbsd"
315 SRC_HC_OPTS += -optc-fno-stack-protector
316 endif
317
318 # -O3 helps unroll some loops (especially in copy() with a constant argument).
319 sm/Evac_HC_OPTS += -optc-funroll-loops
320
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
323
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
331
332 # Cmm must be compiled via-C for now, because the NCG can't handle loops
333 # SRC_HC_OPTS += -fvia-C
334
335 # We *want* type-checking of hand-written cmm.
336 SRC_HC_OPTS += -dcmm-lint
337
338 ifneq "$(BootingFromHc)" "YES"
339 # .cmm files depend on all the .h files, to a first approximation.
340 %.$(way_)o : %.cmm $(H_FILES)
341 $(HC_PRE_OPTS)
342 $(HC) $(HC_OPTS) -c $< -o $@
343 $(HC_POST_OPTS)
344
345 %.$(way_)hc : %.cmm $(H_FILES)
346 $(HC) $(HC_OPTS) -C $< -o $@
347
348 %.$(way_)s : %.cmm $(H_FILES)
349 $(HC) $(HC_OPTS) -S $< -o $@
350 endif
351
352 #-----------------------------------------------------------------------------
353 #
354 # Files to install
355 #
356 # Just libHSrts is installed uniformly across ways
357 #
358 ifeq "$(DLLized)" "YES"
359 INSTALL_PROGS += gmp/gmp.dll
360 INSTALL_LIBS += gmp/libgmp_imp.a Main.dll_o
361 endif
362
363 #-----------------------------------------------------------------------------
364 #
365 # binary-dist
366
367 include $(TOP)/mk/target.mk
368
369 binary-dist:
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/
376 endif
377 ifneq "$(INSTALL_LIBEXECS)" ""
378 $(INSTALL_PROGRAM) $(INSTALL_LIBEXECS) $(BIN_DIST_DIR)/rts/
379 endif