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