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