[project @ 2005-03-08 04:45:29 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 # system, and it is reported that Solaris ld chokes on it when building
62 # HSrts.o.
63 ifeq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
64 EXCLUDED_SRCS += AdjustorAsm.S
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
106 # COMPILING_RTS is only used when building Win32 DLL support.
107 STANDARD_OPTS += -DCOMPILING_RTS
108
109 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
110 STANDARD_OPTS += -Iwin32
111 endif
112
113 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
114 # only included in .c compilations.  HC_OPTS included the WAY_* opts, which
115 # must be included in both types of compilations.
116
117 SRC_CC_OPTS += $(WARNING_OPTS)
118 SRC_CC_OPTS += $(STANDARD_OPTS)
119
120 SRC_CC_OPTS += $(GhcRtsCcOpts)
121 SRC_HC_OPTS += $(GhcRtsHcOpts)
122
123 ifneq "$(DLLized)" "YES"
124 SRC_HC_OPTS += -static
125 endif
126 # SRC_HC_OPTS += -fPIC
127
128 ifeq "$(way)" "mp"
129 SRC_HC_OPTS += -I$$PVM_ROOT/include
130 endif
131
132 # If -DDEBUG is in effect, adjust package conf accordingly..
133 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
134 PACKAGE_CPP_OPTS += -DDEBUG
135 endif
136
137 ifeq "$(HaveLibMingwEx)" "YES"
138 PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
139 endif
140
141 ifeq "$(DotnetSupport)" "YES"
142
143
144 # Would like to just use SUBDIRS here, but need to
145 # descend into dotnet/ earlier than that.
146 #
147 all ::
148         $(MAKE) -C dotnet all
149
150 # But use SUBDIRS for other recursive targets.
151 SUBDIRS += dotnet
152
153 LIBOBJS += dotnet/Invoke.o
154 endif
155
156 # Suppress uninitialized variable warnings for GC.c
157 GC_CC_OPTS      += -Wno-uninitialized
158
159 #-----------------------------------------------------------------------------
160 # Include the Front panel code?
161
162 # we need GTK+ for the front panel
163 ifneq "$(GTK_CONFIG)" ""
164 ifeq "$(GhcRtsWithFrontPanel)" "YES"
165 SRC_HC_OPTS             += `$(GTK_CONFIG) --cflags` -optc-DRTS_GTK_FRONTPANEL
166 VisCallbacks_CC_OPTS    += -Wno-unused
167 SRC_MKDEPENDC_OPTS      += `$(GTK_CONFIG) --cflags`
168 else # GhcRtsWithFrontPanel
169 EXCLUDED_SRCS           += $(wildcard Vis*.c)
170 endif
171 else # GTK_CONFIG
172 EXCLUDED_SRCS           += $(wildcard Vis*.c)
173 endif
174
175 #-----------------------------------------------------------------------------
176 # make depend setup
177
178 SRC_MKDEPENDC_OPTS += -I. -I../includes
179
180 # Hack: we define every way-related option here, so that we get (hopefully)
181 # a superset of the dependencies.  To do this properly, we should generate
182 # a different set of dependencies for each way.  Further hack: PROFILING and
183 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
184 SRC_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
185
186 # -----------------------------------------------------------------------------
187 # The auto-generated apply code
188
189 # We want a slightly different version for the unregisterised way, so we make
190 # AutoApply on a per-way basis (eg. AutoApply_p.cmm).
191
192 AUTO_APPLY_CMM = AutoApply$(_way).cmm
193
194 ifneq "$(BootingFromHc)" "YES"
195 $(AUTO_APPLY_CMM): $(GHC_GENAPPLY)
196         @$(RM) $@
197         $(GHC_GENAPPLY) $(if $(filter $(way), u debug_u), -u) >$@
198 endif
199
200 EXTRA_CMM_SRCS += $(AUTO_APPLY_CMM)
201
202 CLEAN_FILES += $(AUTO_APPLY_CMM)
203
204 # -----------------------------------------------------------------------------
205 #
206 #  Building DLLs is only supported on mingw32 at the moment.
207 #
208 ifeq "$(DLLized)" "YES"
209 SRC_BLD_DLL_OPTS += -lHS_imp_stub -lgmp_imp
210
211 # It's not included in the DLL, but we need to compile it up separately.
212 all :: Main.dll_o
213
214 # Need an import library containing the symbols the RTS uses from the Prelude.
215 # So, to avoid bootstrapping trouble, we build one containing just the syms
216 # we need. Weirdly named to avoid clashing later on when compiling the contents
217 # of ghc/lib/..
218 #
219 # Note: if you do change the name of the Prelude DLL, the "--dllname <nm>.dll"
220 # below will need to be updated as well.
221
222 $(DLL_PEN)/HSrts$(_way).dll :: libHS_imp_stub.a
223
224 libHS_imp_stub.a :
225         dlltool --output-lib libHS_imp_stub.a --def HSprel.def --dllname HSstd.dll
226
227 endif
228
229 # -----------------------------------------------------------------------------
230 # Compile GMP only if we don't have it already
231 #
232 # We use GMP's own configuration stuff, because it's all rather hairy
233 # and not worth re-implementing in our Makefile framework.
234
235 ifneq "$(HaveLibGmp)" "YES"
236 ifneq "$(HaveFrameworkGMP)" "YES"
237 boot ::
238         if [ -f gmp/config.status ]; then \
239            cd gmp && CC=$(WhatGccIsCalled) ./config.status; \
240         else \
241            cd gmp && CC=$(WhatGccIsCalled) ./configure --enable-shared=no \
242                         --host=`echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g'`; \
243         fi
244
245 # Slight cheatage here to pass host as target, but x-compilation isn't supported by ghc.
246
247 ifeq "$(way)" ""
248 all :: gmp/libgmp.a
249
250 ifeq "$(DLLized)" "YES"
251 all :: $(DLL_PEN)/gmp.dll
252
253 $(DLL_PEN)/gmp.dll:
254         $(MAKE) -C gmp gmp.dll
255         $(MV) gmp/gmp.dll $(DLL_PEN)
256 endif
257 endif
258
259 install :: gmp/libgmp.a
260
261 ifeq "$(way)" ""
262 clean distclean maintainer-clean ::
263         -$(MAKE) -C gmp MAKEFLAGS= $@
264
265 INSTALL_LIBS += gmp/libgmp.a
266 endif
267 endif
268
269 gmp/libgmp.a ::
270         $(MAKE) -C gmp MAKEFLAGS=
271         @$(CP) gmp/.libs/libgmp.a gmp
272         @$(RANLIB) gmp/libgmp.a
273 endif
274
275 CLEAN_FILES += gmp/libgmp.a
276
277 #-----------------------------------------------------------------------------
278 #
279 # Building the GUM SysMan
280 #
281
282 ifeq "$(way)" "mp"
283 all :: parallel/SysMan
284
285 ifdef solaris2_TARGET_OS
286 __socket_libs = -lsocket -lnsl
287 else
288 __socket_libs =
289 endif
290
291 parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
292         $(RM) $@
293         gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
294
295 CLEAN_FILES  += parallel/SysMan.mp_o parallel/SysMan
296 INSTALL_LIBEXECS += parallel/SysMan
297 endif
298
299 #-----------------------------------------------------------------------------
300 # Compiling the cmm files
301
302 # ToDo: should we really include Rts.h here?  Required for GNU_ATTRIBUTE().
303 SRC_HC_OPTS += \
304   -I. \
305   -\#include Prelude.h \
306   -\#include Rts.h \
307   -\#include RtsFlags.h \
308   -\#include RtsUtils.h \
309   -\#include StgRun.h \
310   -\#include Schedule.h \
311   -\#include Printer.h \
312   -\#include Sanity.h \
313   -\#include STM.h \
314   -\#include Storage.h \
315   -\#include SchedAPI.h \
316   -\#include Timer.h \
317   -\#include Itimer.h \
318   -\#include ProfHeap.h \
319   -\#include LdvProfile.h \
320   -\#include Profiling.h \
321   -\#include Apply.h
322
323 ifeq "$(Windows)" "YES"
324 PrimOps_HC_OPTS += -\#include '<windows.h>' -\#include win32/AsyncIO.h
325 endif
326
327 # Cmm must be compiled via-C for now, because the NCG can't handle loops
328 SRC_HC_OPTS += -fvia-C
329
330 # We *want* type-checking of hand-written cmm.
331 SRC_HC_OPTS += -dcmm-lint 
332
333 ifneq "$(BootingFromHc)" "YES"
334 # .cmm files depend on all the .h files, to a first approximation.
335 %.$(way_)o : %.cmm $(H_FILES)
336         $(HC_PRE_OPTS)
337         $(HC) $(HC_OPTS) -c $< -o $@
338         $(HC_POST_OPTS)
339
340 %.$(way_)hc : %.cmm $(H_FILES)
341         $(HC) $(HC_OPTS) -C $< -o $@
342
343 %.$(way_)s : %.cmm $(H_FILES)
344         $(HC) $(HC_OPTS) -S $< -o $@
345 endif
346
347 #-----------------------------------------------------------------------------
348 #
349 # Files to install
350 #
351 # Just libHSrts is installed uniformly across ways
352 #
353 INSTALL_LIBS += $(LIBRARY)
354 ifeq "$(DLLized)" "YES"
355 INSTALL_PROGS += $(DLL_NAME) gmp/gmp.dll
356 INSTALL_LIBS += $(patsubst %.a,%_imp.a,$(LIBARY))
357 INSTALL_LIBS += gmp/libgmp_imp.a Main.dll_o
358 endif
359
360 include $(TOP)/mk/target.mk