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