cd96f7f813e7ba32124173ecf7166d4fc5eafa26
[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 #  Other sorta independent, compile-once subdirs are:
12 #       gmp             -- GNU multi-precision library (for Integer)
13
14 #-----------------------------------------------------------------------------
15 # Preamble
16
17 TOP=..
18
19 # Set UseGhcForCc: this causes the fptools build system to use a different
20 # set of suffix rules for compiling C code, using $(HC) rather than $(CC)
21 # and prepending "-optc" to $(CC_OPTS).  NB. must be done before including
22 # boilerplate.mk below.
23 UseGhcForCc = YES
24
25 include $(TOP)/mk/boilerplate.mk
26
27 PACKAGE = rts
28
29 HC=$(GHC_INPLACE)
30
31 # -----------------------------------------------------------------------------
32 # RTS ways
33
34 WAYS=$(GhcLibWays) $(GhcRTSWays)
35
36 ifneq "$(findstring debug, $(way))" ""
37 GhcRtsHcOpts=
38 GhcRtsCcOpts=-g -O0
39 endif
40
41 # -----------------------------------------------------------------------------
42
43 # Tells the build system not to add various Haskellish options to $(SRC_HC_OPTS)
44 NON_HS_PACKAGE = YES
45
46 # grab sources from these subdirectories
47 ALL_DIRS = hooks parallel sm
48
49 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
50 ALL_DIRS += win32
51 else
52 ALL_DIRS += posix
53 endif
54
55 ifneq "$(DLLized)" "YES"
56 EXCLUDED_SRCS += RtsDllMain.c
57 else
58 EXCLUDED_SRCS += Main.c
59 endif
60
61 # This file ends up being empty unless we're building for a powerpc
62 # or darwin system, and it is reported that Solaris ld chokes on it when
63 # building HSrts.o.
64 ifeq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
65 ifeq "$(findstring $(TargetOS_CPP), darwin)" ""
66 EXCLUDED_SRCS += AdjustorAsm.S
67 endif
68 endif
69
70 EXCLUDED_SRCS += parallel/SysMan.c
71
72 # The build system doesn't give us these
73 CMM_SRCS = $(filter-out AutoApply%.cmm, $(wildcard *.cmm)) $(EXTRA_CMM_SRCS)
74 CMM_OBJS = $(patsubst %.cmm,%.$(way_)o, $(CMM_SRCS))
75
76 CLEAN_FILES += $(CMM_OBJS)
77
78 # Override the default $(LIBOBJS) (defaults to $(HS_OBJS))
79 LIBOBJS = $(C_OBJS) $(CMM_OBJS)
80
81 SplitObjs=NO
82
83 H_FILES = $(wildcard ../includes/*.h) $(wildcard *.h)
84
85 #-----------------------------------------------------------------------------
86 # Flags for compiling RTS .c and .hc files
87
88 # gcc provides lots of useful warnings if you ask it.
89 # This is a pretty good list to start with - use a # to comment out
90 # any you don't like.
91 WARNING_OPTS += -Wall
92 WARNING_OPTS += -W
93 WARNING_OPTS += -Wstrict-prototypes 
94 WARNING_OPTS += -Wmissing-prototypes 
95 WARNING_OPTS += -Wmissing-declarations
96 WARNING_OPTS += -Winline
97 WARNING_OPTS += -Waggregate-return
98 #WARNING_OPTS += -Wpointer-arith
99 #WARNING_OPTS += -Wbad-function-cast
100 #WARNING_OPTS += -Wcast-align
101 #WARNING_OPTS += -Wnested-externs
102 #WARNING_OPTS += -Wshadow
103 #WARNING_OPTS += -Wcast-qual
104 #WARNING_OPTS += -Wno-unused 
105 #WARNING_OPTS += -Wredundant-decls 
106 #WARNING_OPTS += -Wconversion
107
108 STANDARD_OPTS += -I../includes -I. -Iparallel -Ism
109 # COMPILING_RTS is only used when building Win32 DLL support.
110 STANDARD_OPTS += -DCOMPILING_RTS
111
112 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
113 # only included in .c compilations.  HC_OPTS included the WAY_* opts, which
114 # must be included in both types of compilations.
115
116 SRC_CC_OPTS += $(WARNING_OPTS)
117 SRC_CC_OPTS += $(STANDARD_OPTS)
118
119 SRC_CC_OPTS += $(GhcRtsCcOpts)
120 SRC_HC_OPTS += $(GhcRtsHcOpts)
121
122 ifneq "$(GhcWithSMP)" "YES"
123 SRC_CC_OPTS += -DNOSMP
124 SRC_HC_OPTS += -optc-DNOSMP
125 endif
126
127 ifneq "$(DLLized)" "YES"
128 SRC_HC_OPTS += -static
129 endif
130 # SRC_HC_OPTS += -fPIC
131
132 RtsMessages_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
133
134 ifeq "$(way)" "mp"
135 SRC_HC_OPTS += -I$$PVM_ROOT/include
136 endif
137
138 # If -DDEBUG is in effect, adjust package conf accordingly..
139 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
140 PACKAGE_CPP_OPTS += -DDEBUG
141 endif
142
143 ifeq "$(HaveLibMingwEx)" "YES"
144 PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
145 endif
146
147 ifeq "$(GhciWithDebugger)" "YES"
148 STANDARD_OPTS += -DDEBUGGER
149 endif
150
151 ifeq "$(DotnetSupport)" "YES"
152
153
154 # Would like to just use SUBDIRS here, but need to
155 # descend into dotnet/ earlier than that.
156 #
157 all ::
158         $(MAKE) -C dotnet all
159
160 # But use SUBDIRS for other recursive targets.
161 SUBDIRS += dotnet
162
163 LIBOBJS += dotnet/Invoke.o
164 endif
165
166 # Suppress uninitialized variable warnings for GC.c
167 GC_CC_OPTS      += -Wno-uninitialized
168
169 #-----------------------------------------------------------------------------
170 # Include the Front panel code?
171
172 # we need GTK+ for the front panel
173 ifneq "$(GTK_CONFIG)" ""
174 ifeq "$(GhcRtsWithFrontPanel)" "YES"
175 SRC_HC_OPTS             += `$(GTK_CONFIG) --cflags` -optc-DRTS_GTK_FRONTPANEL
176 VisCallbacks_CC_OPTS    += -Wno-unused
177 SRC_MKDEPENDC_OPTS      += `$(GTK_CONFIG) --cflags`
178 else # GhcRtsWithFrontPanel
179 EXCLUDED_SRCS           += $(wildcard Vis*.c)
180 endif
181 else # GTK_CONFIG
182 EXCLUDED_SRCS           += $(wildcard Vis*.c)
183 endif
184
185 #-----------------------------------------------------------------------------
186 # Add PAPI library if needed
187
188 ifeq "$(GhcRtsWithPapi)" "YES"
189 SRC_HC_OPTS             += -optc-DUSE_PAPI
190 PACKAGE_CPP_OPTS        += -DUSE_PAPI
191 endif
192
193 #-----------------------------------------------------------------------------
194 # make depend setup
195
196 SRC_MKDEPENDC_OPTS += -I. -I../includes
197
198 # Hack: we define every way-related option here, so that we get (hopefully)
199 # a superset of the dependencies.  To do this properly, we should generate
200 # a different set of dependencies for each way.  Further hack: PROFILING and
201 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
202 SRC_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
203
204 # -----------------------------------------------------------------------------
205 # The auto-generated apply code
206
207 # We want a slightly different version for the unregisterised way, so we make
208 # AutoApply on a per-way basis (eg. AutoApply_p.cmm).
209
210 ifneq "$(DOING_BIN_DIST)" "YES"
211
212 AUTO_APPLY_CMM = AutoApply$(_way).cmm
213
214 ifneq "$(BootingFromHc)" "YES"
215 $(AUTO_APPLY_CMM): $(GHC_GENAPPLY)
216         @$(RM) $@
217         $(GENAPPLY) $(if $(filter $(way), u debug_u), -u) >$@
218 endif
219
220 EXTRA_CMM_SRCS += $(AUTO_APPLY_CMM)
221
222 CLEAN_FILES += $(AUTO_APPLY_CMM)
223
224 endif
225
226 # -----------------------------------------------------------------------------
227 #
228 #  Building DLLs is only supported on mingw32 at the moment.
229 #
230 ifeq "$(DLLized)" "YES"
231 SRC_BLD_DLL_OPTS += -lHS_imp_stub -lgmp_imp
232
233 # It's not included in the DLL, but we need to compile it up separately.
234 all :: Main.dll_o
235
236 # Need an import library containing the symbols the RTS uses from the Prelude.
237 # So, to avoid bootstrapping trouble, we build one containing just the syms
238 # we need. Weirdly named to avoid clashing later on when compiling the contents
239 # of ghc/lib/..
240 #
241 # Note: if you do change the name of the Prelude DLL, the "--dllname <nm>.dll"
242 # below will need to be updated as well.
243
244 $(DLL_PEN)/HSrts$(_way).dll :: libHS_imp_stub.a
245
246 libHS_imp_stub.a :
247         dlltool --output-lib libHS_imp_stub.a --def HSprel.def --dllname HSstd.dll
248
249 endif
250
251 # -----------------------------------------------------------------------------
252 # Compile GMP only if we don't have it already
253 #
254 # We use GMP's own configuration stuff, because it's all rather hairy
255 # and not worth re-implementing in our Makefile framework.
256
257 ifneq "$(HaveLibGmp)" "YES"
258 ifneq "$(HaveFrameworkGMP)" "YES"
259 boot ::
260         if [ -f gmp/config.status ]; then \
261            cd gmp && CC=$(WhatGccIsCalled) ./config.status; \
262         else \
263            cd gmp && CC=$(WhatGccIsCalled) $(SHELL) configure --enable-shared=no \
264                         --host=`echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g'`; \
265         fi
266
267 # Slight cheatage here to pass host as target, but x-compilation isn't supported by ghc.
268
269 ifeq "$(way)" ""
270 all :: gmp/libgmp.a
271
272 ifeq "$(DLLized)" "YES"
273 all :: $(DLL_PEN)/gmp.dll
274
275 $(DLL_PEN)/gmp.dll:
276         $(MAKE) -C gmp gmp.dll
277         $(MV) gmp/gmp.dll $(DLL_PEN)
278 endif
279 endif
280
281 install :: gmp/libgmp.a
282
283 ifeq "$(way)" ""
284 clean distclean maintainer-clean ::
285         -$(MAKE) -C gmp MAKEFLAGS= $@
286
287 INSTALL_LIBS += gmp/libgmp.a
288 endif
289 endif
290
291 gmp/libgmp.a ::
292         $(MAKE) -C gmp MAKEFLAGS=
293         @$(CP) gmp/.libs/libgmp.a gmp
294         @$(RANLIB) gmp/libgmp.a
295 endif
296
297 CLEAN_FILES += gmp/libgmp.a
298
299 # Need to get the GMP vars in through CPP to package.conf.in, and put
300 # quotes around each element.
301
302 empty =
303 space = $(empty) $(empty)
304 comma = ,
305 PACKAGE_CPP_OPTS += -DGMP_INCLUDE_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_INCLUDE_DIRS))))'
306 PACKAGE_CPP_OPTS += -DGMP_LIB_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_LIB_DIRS))))'
307
308 ifneq "$(GMP_INCLUDE_DIRS)" ""
309 SRC_HC_OPTS += -I$(GMP_INCLUDE_DIRS)
310 SRC_CC_OPTS += -I$(GMP_INCLUDE_DIRS)
311 SRC_HSC2HS_OPTS += -I$(GMP_INCLUDE_DIRS)
312 endif
313 ifneq "$(GMP_LIB_DIRS)" ""
314 SRC_LD_OPTS += -L$(GMP_LIB_DIRS)
315 endif
316
317 #-----------------------------------------------------------------------------
318 #
319 # Building the GUM SysMan
320 #
321
322 ifeq "$(way)" "mp"
323 all :: parallel/SysMan
324
325 ifdef solaris2_TARGET_OS
326 __socket_libs = -lsocket -lnsl
327 else
328 __socket_libs =
329 endif
330
331 parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
332         $(RM) $@
333         gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
334
335 CLEAN_FILES  += parallel/SysMan.mp_o parallel/SysMan
336 INSTALL_LIBEXECS += parallel/SysMan
337 endif
338
339 #-----------------------------------------------------------------------------
340 # Compiling the cmm files
341
342 # ToDo: should we really include Rts.h here?  Required for GNU_ATTRIBUTE().
343 SRC_HC_OPTS += -I. -\#include HCIncludes.h
344
345 ifeq "$(Windows)" "YES"
346 PrimOps_HC_OPTS += -\#include '<windows.h>' -\#include win32/AsyncIO.h
347 else
348 PrimOps_HC_OPTS += -\#include posix/Itimer.h
349 endif
350
351 # Otherwise the stack-smash handler gets triggered.
352 ifeq "$(TargetOS_CPP)" "openbsd"
353 SRC_HC_OPTS += -optc-fno-stack-protector
354 endif
355
356 # -O3 helps unroll some loops (especially in copy() with a constant argument).
357 sm/Evac_HC_OPTS += -optc-funroll-loops
358
359 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
360 sm/Compact_HC_OPTS += -optc-finline-limit=2500
361
362 # -fno-strict-aliasing is required for the runtime, because we often
363 # use a variety of types to represent closure pointers (StgPtr,
364 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
365 # allowed to assume that these pointers do not alias.  eg. without
366 # this flag we get problems in GC.c:copy() with gcc 3.4.3, the
367 # upd_evacee() assigments get moved before the object copy.
368 SRC_CC_OPTS += -fno-strict-aliasing
369
370 # Cmm must be compiled via-C for now, because the NCG can't handle loops
371 SRC_HC_OPTS += -fvia-C
372
373 # We *want* type-checking of hand-written cmm.
374 SRC_HC_OPTS += -dcmm-lint 
375
376 ifneq "$(BootingFromHc)" "YES"
377 # .cmm files depend on all the .h files, to a first approximation.
378 %.$(way_)o : %.cmm $(H_FILES)
379         $(HC_PRE_OPTS)
380         $(HC) $(HC_OPTS) -c $< -o $@
381         $(HC_POST_OPTS)
382
383 %.$(way_)hc : %.cmm $(H_FILES)
384         $(HC) $(HC_OPTS) -C $< -o $@
385
386 %.$(way_)s : %.cmm $(H_FILES)
387         $(HC) $(HC_OPTS) -S $< -o $@
388 endif
389
390 #-----------------------------------------------------------------------------
391 #
392 # Files to install
393 #
394 # Just libHSrts is installed uniformly across ways
395 #
396 ifeq "$(DLLized)" "YES"
397 INSTALL_PROGS += gmp/gmp.dll
398 INSTALL_LIBS += gmp/libgmp_imp.a Main.dll_o
399 endif
400
401 #-----------------------------------------------------------------------------
402 #
403 # binary-dist
404
405 include $(TOP)/mk/target.mk
406
407 binary-dist:
408         $(INSTALL_DIR)                         $(BIN_DIST_DIR)/rts
409         $(INSTALL_DIR)                         $(BIN_DIST_DIR)/rts/gmp
410         $(INSTALL_DATA)    Makefile            $(BIN_DIST_DIR)/rts/
411         $(INSTALL_DATA)    package.conf.in     $(BIN_DIST_DIR)/rts/
412 ifneq "$(INSTALL_LIBS)" ""
413         $(INSTALL_DATA)    $(INSTALL_LIBS)     $(BIN_DIST_DIR)/rts/
414 endif
415 ifneq "$(INSTALL_LIBEXECS)" ""
416         $(INSTALL_PROGRAM) $(INSTALL_LIBEXECS) $(BIN_DIST_DIR)/rts/
417 endif