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