Fix a whole heap of speling errrs in the docs
[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 ifeq "$(BeConservative)" "YES"
39 GhcRtsCcOpts += -DBE_CONSERVATIVE
40 endif
41
42 # -----------------------------------------------------------------------------
43
44 # There's nothing for Haddock here...
45 override HADDOCK_DOCS = NO
46
47 # -----------------------------------------------------------------------------
48
49 # Tells the build system not to add various Haskellish options to $(SRC_HC_OPTS)
50 NON_HS_PACKAGE = YES
51
52 # grab sources from these subdirectories
53 ALL_DIRS = hooks parallel sm
54
55 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
56 ALL_DIRS += win32
57 else
58 ALL_DIRS += posix
59 endif
60
61 ifneq "$(findstring dyn, $(way))" ""
62 DYNAMIC_RTS=YES
63 else
64 DYNAMIC_RTS=NO
65 endif
66
67 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
68 EXCLUDED_SRCS += Main.c
69 # It's not included in the DLL, but we need to compile it up separately.
70
71 all :: Main.$(way_)o
72 INSTALL_LIBS += Main.$(way_)o
73 else
74 EXCLUDED_SRCS += RtsDllMain.c
75 endif
76
77 # This file ends up being empty unless we're building for a powerpc
78 # or darwin system, and it is reported that Solaris ld chokes on it when
79 # building HSrts.o.
80 ifeq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
81 ifeq "$(findstring $(TargetOS_CPP), darwin)" ""
82 EXCLUDED_SRCS += AdjustorAsm.S
83 endif
84 endif
85
86 EXCLUDED_SRCS += parallel/SysMan.c
87
88 # The build system doesn't give us these
89 CMM_SRCS = $(filter-out AutoApply%.cmm, $(wildcard *.cmm)) $(EXTRA_CMM_SRCS)
90 CMM_OBJS = $(patsubst %.cmm,%.$(way_)o, $(CMM_SRCS))
91
92 CLEAN_FILES += $(CMM_OBJS)
93
94 # Override the default $(LIBOBJS) (defaults to $(HS_OBJS))
95 LIBOBJS = $(C_OBJS) $(CMM_OBJS)
96
97 SplitObjs=NO
98
99 H_FILES = $(wildcard ../includes/*.h) $(wildcard *.h)
100
101 #-----------------------------------------------------------------------------
102 # Flags for compiling RTS .c and .hc files
103
104 # gcc provides lots of useful warnings if you ask it.
105 # This is a pretty good list to start with - use a # to comment out
106 # any you don't like.
107 WARNING_OPTS += -Wall
108 WARNING_OPTS += -W
109 WARNING_OPTS += -Wstrict-prototypes
110 WARNING_OPTS += -Wmissing-prototypes
111 WARNING_OPTS += -Wmissing-declarations
112 WARNING_OPTS += -Winline
113 WARNING_OPTS += -Waggregate-return
114 #WARNING_OPTS += -Wpointer-arith
115 #WARNING_OPTS += -Wbad-function-cast
116 #WARNING_OPTS += -Wcast-align
117 #WARNING_OPTS += -Wnested-externs
118 #WARNING_OPTS += -Wshadow
119 #WARNING_OPTS += -Wcast-qual
120 #WARNING_OPTS += -Wno-unused
121 #WARNING_OPTS += -Wredundant-decls
122 #WARNING_OPTS += -Wconversion
123
124 STANDARD_OPTS += -I../includes -I. -Iparallel -Ism
125 # COMPILING_RTS is only used when building Win32 DLL support.
126 STANDARD_OPTS += -DCOMPILING_RTS
127
128 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
129 # only included in .c compilations. HC_OPTS included the WAY_* opts, which
130 # must be included in both types of compilations.
131
132 SRC_CC_OPTS += $(WARNING_OPTS)
133 SRC_CC_OPTS += $(STANDARD_OPTS)
134
135 SRC_CC_OPTS += $(GhcRtsCcOpts)
136 SRC_HC_OPTS += $(GhcRtsHcOpts) $(STANDARD_OPTS) -package-name rts
137
138 ifneq "$(GhcWithSMP)" "YES"
139 SRC_CC_OPTS += -DNOSMP
140 SRC_HC_OPTS += -optc-DNOSMP
141 endif
142
143 ifneq "$(DYNAMIC_RTS)" "YES"
144 SRC_HC_OPTS += -static
145 else
146 LIB_LD_OPTS += -ignore-package base -ignore-package rts
147 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
148 BASE_VERSION=$(strip $(shell grep version: $(TOP)/libraries/base/base.cabal | cut -f2 -d:))
149 BASE_NAME=HSbase-$(BASE_VERSION)-ghc$(ProjectVersion)$(soext)
150 BASE_DIST_LIB=$(TOP)/libraries/base/dist/build
151 BASE_IMPORT_LIBRARY=$(BASE_DIST_LIB)/lib$(BASE_NAME).a
152 LIB_DEPS=$(BASE_IMPORT_LIBRARY)
153 LIB_LD_OPTS += -L$(BASE_DIST_LIB) -l$(BASE_NAME)
154 # We extract a good bit of information out of the rts package.conf by going via ghc-pkg
155 LIB_LD_OPTS += $(foreach lib,$(shell $(GHC_PKG_INPLACE) field rts extra-libraries | sed -e s/extra-libraries://),"-l$(lib)")
156 LIB_LD_OPTS += $(foreach libdir,$(shell $(GHC_PKG_INPLACE) field rts library-dirs | sed -e s/library-dirs://),"-L$(libdir)")
157 endif
158 endif
159
160 ifeq "$(Windows)" "YES"
161 # On Windows GHC does its own commandline parsing, so we need extra
162 # doublequote protection. Sigh.
163 DQ = \\\"
164 else
165 DQ = \"
166 endif
167
168 # If Main.c is built with optimisation then the SEH exception stuff on
169 # Windows gets confused.
170 # This has to be in HC rather than CC opts, as otherwise there's a
171 # -optc-O2 that comes after it.
172 Main_HC_OPTS += -optc-O0
173
174 RtsMessages_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
175 RtsUtils_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
176 RtsUtils_CC_OPTS += -DRtsWay=$(DQ)rts$(_way)$(DQ)
177 RtsUtils_CC_OPTS += -DHostPlatform=$(DQ)$(HOSTPLATFORM)$(DQ)
178 RtsUtils_CC_OPTS += -DBuildPlatform=$(DQ)$(BUILDPLATFORM)$(DQ)
179 RtsUtils_CC_OPTS += -DTargetPlatform=$(DQ)$(TARGETPLATFORM)$(DQ)
180 RtsUtils_CC_OPTS += -DGhcUnregisterised=$(DQ)$(GhcUnregisterised)$(DQ)
181 RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=$(DQ)$(GhcEnableTablesNextToCode)$(DQ)
182
183 StgCRun_CC_OPTS += -w
184 Typeable_CC_OPTS += -w
185 RetainerProfile_CC_OPTS += -w
186 sm/Compact_CC_OPTS += -w
187 # On Windows:
188 win32/ConsoleHandler_CC_OPTS += -w
189 win32/ThrIOManager_CC_OPTS += -w
190 win32/Ticker_CC_OPTS += -w
191 Threads_CC_OPTS += -w
192 Capability_CC_OPTS += -w
193 Schedule_CC_OPTS += -w
194 # The above warning supression flags are a temporary kludge.
195 # While working on this module you are encouraged to remove it and fix
196 # any warnings in the module. See
197 # http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
198 # for details
199
200 ifeq "$(way)" "mp"
201 SRC_HC_OPTS += -I$$PVM_ROOT/include
202 endif
203
204 # If -DDEBUG is in effect, adjust package conf accordingly..
205 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
206 PACKAGE_CPP_OPTS += -DDEBUG
207 endif
208
209 ifeq "$(HaveLibMingwEx)" "YES"
210 PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
211 endif
212
213 ifeq "$(GhciWithDebugger)" "YES"
214 STANDARD_OPTS += -DDEBUGGER
215 endif
216
217 ifeq "$(DotnetSupport)" "YES"
218
219 #
220 # Would like to just use SUBDIRS here, but need to
221 # descend into dotnet/ earlier than that.
222 #
223 all ::
224 $(MAKE) -C dotnet all
225
226 # But use SUBDIRS for other recursive targets.
227 SUBDIRS += dotnet
228
229 LIBOBJS += dotnet/Invoke.o
230 endif
231
232 # Suppress uninitialized variable warnings for GC.c
233 GC_CC_OPTS += -Wno-uninitialized
234
235 #-----------------------------------------------------------------------------
236 # Include the Front panel code?
237
238 # we need GTK+ for the front panel
239 ifneq "$(GTK_CONFIG)" ""
240 ifeq "$(GhcRtsWithFrontPanel)" "YES"
241 SRC_HC_OPTS += `$(GTK_CONFIG) --cflags` -optc-DRTS_GTK_FRONTPANEL
242 VisCallbacks_CC_OPTS += -Wno-unused
243 SRC_MKDEPENDC_OPTS += `$(GTK_CONFIG) --cflags`
244 else # GhcRtsWithFrontPanel
245 EXCLUDED_SRCS += $(wildcard Vis*.c)
246 endif
247 else # GTK_CONFIG
248 EXCLUDED_SRCS += $(wildcard Vis*.c)
249 endif
250
251 #-----------------------------------------------------------------------------
252 # Add PAPI library if needed
253
254 ifeq "$(GhcRtsWithPapi)" "YES"
255 SRC_HC_OPTS += -optc-DUSE_PAPI
256 PACKAGE_CPP_OPTS += -DUSE_PAPI
257 endif
258
259 #-----------------------------------------------------------------------------
260 # make depend setup
261
262 SRC_MKDEPENDC_OPTS += -I. -I../includes
263
264 # Hack: we define every way-related option here, so that we get (hopefully)
265 # a superset of the dependencies. To do this properly, we should generate
266 # a different set of dependencies for each way. Further hack: PROFILING and
267 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
268 SRC_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
269
270 # -----------------------------------------------------------------------------
271 # The auto-generated apply code
272
273 # We want a slightly different version for the unregisterised way, so we make
274 # AutoApply on a per-way basis (eg. AutoApply_p.cmm).
275
276 ifneq "$(DOING_BIN_DIST)" "YES"
277
278 AUTO_APPLY_CMM = AutoApply$(_way).cmm
279
280 ifneq "$(BootingFromHc)" "YES"
281 $(AUTO_APPLY_CMM): $(GHC_GENAPPLY)
282 @$(RM) $@
283 $(GENAPPLY) $(if $(filter $(way), u debug_u), -u) >$@
284 endif
285
286 EXTRA_CMM_SRCS += $(AUTO_APPLY_CMM)
287
288 CLEAN_FILES += $(AUTO_APPLY_CMM)
289
290 endif
291
292 # -----------------------------------------------------------------------------
293 # Compile GMP only if we don't have it already
294 #
295 # We use GMP's own configuration stuff, because it's all rather hairy
296 # and not worth re-implementing in our Makefile framework.
297
298 CLEAN_FILES += gmp/libgmp.a
299
300 # Need to get the GMP vars in through CPP to package.conf.in, and put
301 # quotes around each element.
302
303 empty =
304 space = $(empty) $(empty)
305 comma = ,
306 PACKAGE_CPP_OPTS += -DGMP_INCLUDE_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_INCLUDE_DIRS))))'
307 PACKAGE_CPP_OPTS += -DGMP_LIB_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_LIB_DIRS))))'
308
309 ifneq "$(GMP_INCLUDE_DIRS)" ""
310 SRC_HC_OPTS += -I$(GMP_INCLUDE_DIRS)
311 SRC_CC_OPTS += -I$(GMP_INCLUDE_DIRS)
312 SRC_HSC2HS_OPTS += -I$(GMP_INCLUDE_DIRS)
313 endif
314 ifneq "$(GMP_LIB_DIRS)" ""
315 SRC_LD_OPTS += -L$(GMP_LIB_DIRS)
316 endif
317
318 SRC_CC_OPTS += -I../gmp/gmpbuild
319 SRC_HC_OPTS += -I../gmp/gmpbuild
320 SRC_HSC2HS_OPTS += -I../gmp/gmpbuild
321 SRC_LD_OPTS += -L../gmp/gmpbuild
322
323 #-----------------------------------------------------------------------------
324 #
325 # Building the GUM SysMan
326 #
327
328 ifeq "$(way)" "mp"
329 all :: parallel/SysMan
330
331 ifdef solaris2_TARGET_OS
332 __socket_libs = -lsocket -lnsl
333 else
334 __socket_libs =
335 endif
336
337 parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
338 $(RM) $@
339 gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
340
341 CLEAN_FILES += parallel/SysMan.mp_o parallel/SysMan
342 INSTALL_LIBEXECS += parallel/SysMan
343 endif
344
345 #-----------------------------------------------------------------------------
346 # Compiling the cmm files
347
348 # ToDo: should we really include Rts.h here? Required for GNU_ATTRIBUTE().
349 SRC_HC_OPTS += -I. -\#include HCIncludes.h
350
351 ifeq "$(Windows)" "YES"
352 PrimOps_HC_OPTS += -\#include '<windows.h>' -\#include win32/AsyncIO.h
353 else
354 PrimOps_HC_OPTS += -\#include posix/Itimer.h
355 endif
356
357 # Otherwise the stack-smash handler gets triggered.
358 ifeq "$(TargetOS_CPP)" "openbsd"
359 SRC_HC_OPTS += -optc-fno-stack-protector
360 endif
361
362 # -O3 helps unroll some loops (especially in copy() with a constant argument).
363 sm/Evac_HC_OPTS += -optc-funroll-loops
364
365 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
366 sm/Compact_HC_OPTS += -optc-finline-limit=2500
367
368 # -fno-strict-aliasing is required for the runtime, because we often
369 # use a variety of types to represent closure pointers (StgPtr,
370 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
371 # allowed to assume that these pointers do not alias. eg. without
372 # this flag we get problems in GC.c:copy() with gcc 3.4.3, the
373 # upd_evacee() assigments get moved before the object copy.
374 SRC_CC_OPTS += -fno-strict-aliasing
375
376 # We *want* type-checking of hand-written cmm.
377 SRC_HC_OPTS += -dcmm-lint
378
379 ifneq "$(BootingFromHc)" "YES"
380 # .cmm files depend on all the .h files, to a first approximation.
381 %.$(way_)o : %.cmm $(H_FILES)
382 $(HC_PRE_OPTS)
383 $(HC) $(HC_OPTS) -c $< -o $@
384 $(HC_POST_OPTS)
385
386 %.$(way_)hc : %.cmm $(H_FILES)
387 $(HC) $(HC_OPTS) -C $< -o $@
388
389 %.$(way_)s : %.cmm $(H_FILES)
390 $(HC) $(HC_OPTS) -S $< -o $@
391 endif
392
393 #-----------------------------------------------------------------------------
394 #
395 # Files to install
396 #
397 # Just libHSrts is installed uniformly across ways
398 #
399
400 include $(TOP)/mk/target.mk
401
402 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
403 $(BASE_IMPORT_LIBRARY): $(LIBRARY).a
404 $(MAKE) -C ../libraries/ make.library.base
405 # just for the timestamps
406 touch $(BASE_IMPORT_LIBRARY)
407 endif
408
409 #-----------------------------------------------------------------------------
410 #
411 # binary-dist
412
413 binary-dist:
414 $(INSTALL_DIR) $(BIN_DIST_DIR)/rts
415 $(INSTALL_DIR) $(BIN_DIST_DIR)/rts/gmp
416 $(INSTALL_DATA) Makefile $(BIN_DIST_DIR)/rts/
417 $(INSTALL_DATA) package.conf.in $(BIN_DIST_DIR)/rts/
418 ifneq "$(INSTALL_LIBS)" ""
419 $(INSTALL_DATA) $(INSTALL_LIBS) $(BIN_DIST_DIR)/rts/
420 endif
421 ifneq "$(INSTALL_LIBEXECS)" ""
422 $(INSTALL_PROGRAM) $(INSTALL_LIBEXECS) $(BIN_DIST_DIR)/rts/
423 endif