[project @ 2005-09-12 00:10:09 by wolfgang]
[ghc-hetmet.git] / ghc / 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
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
48
49 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
50 ALL_DIRS += win32
51 EXCLUDED_SRCS += Itimer.c Select.c Signals.c
52 endif
53
54 ifneq "$(DLLized)" "YES"
55 EXCLUDED_SRCS += RtsDllMain.c
56 else
57 EXCLUDED_SRCS += Main.c
58 endif
59
60 # This file ends up being empty unless we're building for a powerpc
61 # or darwin system, and it is reported that Solaris ld chokes on it when
62 # building HSrts.o.
63 ifeq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
64 ifeq "$(findstring $(TargetOS_CPP), darwin)" ""
65 EXCLUDED_SRCS += AdjustorAsm.S
66 endif
67 endif
68
69 EXCLUDED_SRCS += parallel/SysMan.c
70
71 # The build system doesn't give us these
72 CMM_SRCS = $(filter-out AutoApply%.cmm, $(wildcard *.cmm)) $(EXTRA_CMM_SRCS)
73 CMM_OBJS = $(patsubst %.cmm,%.$(way_)o, $(CMM_SRCS))
74
75 CLEAN_FILES += $(CMM_OBJS)
76
77 # Override the default $(LIBOBJS) (defaults to $(HS_OBJS))
78 LIBOBJS = $(C_OBJS) $(CMM_OBJS)
79
80 SplitObjs=NO
81
82 H_FILES = $(wildcard ../includes/*.h) $(wildcard *.h)
83
84 #-----------------------------------------------------------------------------
85 # Flags for compiling RTS .c and .hc files
86
87 # gcc provides lots of useful warnings if you ask it.
88 # This is a pretty good list to start with - use a # to comment out
89 # any you don't like.
90 WARNING_OPTS += -Wall 
91 WARNING_OPTS += -W
92 WARNING_OPTS += -Wstrict-prototypes 
93 WARNING_OPTS += -Wmissing-prototypes 
94 WARNING_OPTS += -Wmissing-declarations
95 WARNING_OPTS += -Winline
96 WARNING_OPTS += -Waggregate-return
97 #WARNING_OPTS += -Wpointer-arith
98 WARNING_OPTS += -Wbad-function-cast
99 #WARNING_OPTS += -Wcast-align
100 #WARNING_OPTS += -Wnested-externs
101 #WARNING_OPTS += -Wshadow
102 #WARNING_OPTS += -Wcast-qual
103 #WARNING_OPTS += -Wno-unused 
104 #WARNING_OPTS += -Wredundant-decls 
105 #WARNING_OPTS += -Wconversion
106
107 STANDARD_OPTS += -I../includes -I. -Iparallel
108 # COMPILING_RTS is only used when building Win32 DLL support.
109 STANDARD_OPTS += -DCOMPILING_RTS
110
111 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
112 STANDARD_OPTS += -Iwin32
113 endif
114
115 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
116 # only included in .c compilations.  HC_OPTS included the WAY_* opts, which
117 # must be included in both types of compilations.
118
119 SRC_CC_OPTS += $(WARNING_OPTS)
120 SRC_CC_OPTS += $(STANDARD_OPTS)
121
122 SRC_CC_OPTS += $(GhcRtsCcOpts)
123 SRC_HC_OPTS += $(GhcRtsHcOpts)
124
125 ifneq "$(DLLized)" "YES"
126 SRC_HC_OPTS += -static
127 endif
128 # SRC_HC_OPTS += -fPIC
129
130 ifeq "$(way)" "mp"
131 SRC_HC_OPTS += -I$$PVM_ROOT/include
132 endif
133
134 # If -DDEBUG is in effect, adjust package conf accordingly..
135 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
136 PACKAGE_CPP_OPTS += -DDEBUG
137 endif
138
139 ifeq "$(HaveLibMingwEx)" "YES"
140 PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
141 endif
142
143 ifeq "$(DotnetSupport)" "YES"
144
145
146 # Would like to just use SUBDIRS here, but need to
147 # descend into dotnet/ earlier than that.
148 #
149 all ::
150         $(MAKE) -C dotnet all
151
152 # But use SUBDIRS for other recursive targets.
153 SUBDIRS += dotnet
154
155 LIBOBJS += dotnet/Invoke.o
156 endif
157
158 # Suppress uninitialized variable warnings for GC.c
159 GC_CC_OPTS      += -Wno-uninitialized
160
161 #-----------------------------------------------------------------------------
162 # Include the Front panel code?
163
164 # we need GTK+ for the front panel
165 ifneq "$(GTK_CONFIG)" ""
166 ifeq "$(GhcRtsWithFrontPanel)" "YES"
167 SRC_HC_OPTS             += `$(GTK_CONFIG) --cflags` -optc-DRTS_GTK_FRONTPANEL
168 VisCallbacks_CC_OPTS    += -Wno-unused
169 SRC_MKDEPENDC_OPTS      += `$(GTK_CONFIG) --cflags`
170 else # GhcRtsWithFrontPanel
171 EXCLUDED_SRCS           += $(wildcard Vis*.c)
172 endif
173 else # GTK_CONFIG
174 EXCLUDED_SRCS           += $(wildcard Vis*.c)
175 endif
176
177 #-----------------------------------------------------------------------------
178 # make depend setup
179
180 SRC_MKDEPENDC_OPTS += -I. -I../includes
181
182 # Hack: we define every way-related option here, so that we get (hopefully)
183 # a superset of the dependencies.  To do this properly, we should generate
184 # a different set of dependencies for each way.  Further hack: PROFILING and
185 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
186 SRC_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
187
188 # -----------------------------------------------------------------------------
189 # The auto-generated apply code
190
191 # We want a slightly different version for the unregisterised way, so we make
192 # AutoApply on a per-way basis (eg. AutoApply_p.cmm).
193
194 AUTO_APPLY_CMM = AutoApply$(_way).cmm
195
196 ifneq "$(BootingFromHc)" "YES"
197 $(AUTO_APPLY_CMM): $(GHC_GENAPPLY)
198         @$(RM) $@
199         $(GHC_GENAPPLY) $(if $(filter $(way), u debug_u), -u) >$@
200 endif
201
202 EXTRA_CMM_SRCS += $(AUTO_APPLY_CMM)
203
204 CLEAN_FILES += $(AUTO_APPLY_CMM)
205
206 # -----------------------------------------------------------------------------
207 #
208 #  Building DLLs is only supported on mingw32 at the moment.
209 #
210 ifeq "$(DLLized)" "YES"
211 SRC_BLD_DLL_OPTS += -lHS_imp_stub -lgmp_imp
212
213 # It's not included in the DLL, but we need to compile it up separately.
214 all :: Main.dll_o
215
216 # Need an import library containing the symbols the RTS uses from the Prelude.
217 # So, to avoid bootstrapping trouble, we build one containing just the syms
218 # we need. Weirdly named to avoid clashing later on when compiling the contents
219 # of ghc/lib/..
220 #
221 # Note: if you do change the name of the Prelude DLL, the "--dllname <nm>.dll"
222 # below will need to be updated as well.
223
224 $(DLL_PEN)/HSrts$(_way).dll :: libHS_imp_stub.a
225
226 libHS_imp_stub.a :
227         dlltool --output-lib libHS_imp_stub.a --def HSprel.def --dllname HSstd.dll
228
229 endif
230
231 # -----------------------------------------------------------------------------
232 # Compile GMP only if we don't have it already
233 #
234 # We use GMP's own configuration stuff, because it's all rather hairy
235 # and not worth re-implementing in our Makefile framework.
236
237 ifneq "$(HaveLibGmp)" "YES"
238 ifneq "$(HaveFrameworkGMP)" "YES"
239 boot ::
240         if [ -f gmp/config.status ]; then \
241            cd gmp && CC=$(WhatGccIsCalled) ./config.status; \
242         else \
243            cd gmp && CC=$(WhatGccIsCalled) ./configure --enable-shared=no \
244                         --host=`echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g'`; \
245         fi
246
247 # Slight cheatage here to pass host as target, but x-compilation isn't supported by ghc.
248
249 ifeq "$(way)" ""
250 all :: gmp/libgmp.a
251
252 ifeq "$(DLLized)" "YES"
253 all :: $(DLL_PEN)/gmp.dll
254
255 $(DLL_PEN)/gmp.dll:
256         $(MAKE) -C gmp gmp.dll
257         $(MV) gmp/gmp.dll $(DLL_PEN)
258 endif
259 endif
260
261 install :: gmp/libgmp.a
262
263 ifeq "$(way)" ""
264 clean distclean maintainer-clean ::
265         -$(MAKE) -C gmp MAKEFLAGS= $@
266
267 INSTALL_LIBS += gmp/libgmp.a
268 endif
269 endif
270
271 gmp/libgmp.a ::
272         $(MAKE) -C gmp MAKEFLAGS=
273         @$(CP) gmp/.libs/libgmp.a gmp
274         @$(RANLIB) gmp/libgmp.a
275 endif
276
277 CLEAN_FILES += gmp/libgmp.a
278
279 #-----------------------------------------------------------------------------
280 #
281 # Building the GUM SysMan
282 #
283
284 ifeq "$(way)" "mp"
285 all :: parallel/SysMan
286
287 ifdef solaris2_TARGET_OS
288 __socket_libs = -lsocket -lnsl
289 else
290 __socket_libs =
291 endif
292
293 parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
294         $(RM) $@
295         gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
296
297 CLEAN_FILES  += parallel/SysMan.mp_o parallel/SysMan
298 INSTALL_LIBEXECS += parallel/SysMan
299 endif
300
301 #-----------------------------------------------------------------------------
302 # Compiling the cmm files
303
304 # ToDo: should we really include Rts.h here?  Required for GNU_ATTRIBUTE().
305 SRC_HC_OPTS += \
306   -I. \
307   -\#include Prelude.h \
308   -\#include Rts.h \
309   -\#include RtsFlags.h \
310   -\#include RtsUtils.h \
311   -\#include StgRun.h \
312   -\#include Schedule.h \
313   -\#include Printer.h \
314   -\#include Sanity.h \
315   -\#include STM.h \
316   -\#include Storage.h \
317   -\#include SchedAPI.h \
318   -\#include Timer.h \
319   -\#include Itimer.h \
320   -\#include ProfHeap.h \
321   -\#include LdvProfile.h \
322   -\#include Profiling.h \
323   -\#include OSThreads.h \
324   -\#include Apply.h \
325   -\#include SMP.h
326
327 ifeq "$(Windows)" "YES"
328 PrimOps_HC_OPTS += -\#include '<windows.h>' -\#include win32/AsyncIO.h
329 endif
330
331 # -O3 helps unroll some loops (especially in copy() with a constant argument).
332 # -fno-strict-aliasing is a hack because we often mix StgPtr and StgClosure pointers
333 # to the same object, and gcc will assume these don't alias.  eg. it happens in
334 # copy() with gcc 3.4.3, the upd_evacee() assigments get moved before the object copy.
335 GC_HC_OPTS += -optc-O3 -optc-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 INSTALL_LIBS += $(LIBRARY)
364 ifeq "$(DLLized)" "YES"
365 INSTALL_PROGS += $(DLL_NAME) gmp/gmp.dll
366 INSTALL_LIBS += $(patsubst %.a,%_imp.a,$(LIBARY))
367 INSTALL_LIBS += gmp/libgmp_imp.a Main.dll_o
368 endif
369
370 include $(TOP)/mk/target.mk