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