39322baca0216c2fb4804d523e1779b9bfbb5427
[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) thr debug
35
36 ifneq "$(findstring p, $(GhcLibWays))" ""
37 WAYS += thr_p debug_p
38 endif
39
40 # Way 'thr':
41 WAY_thr_NAME=threaded
42 WAY_thr_HC_OPTS=-optc-DTHREADED_RTS
43
44 # Way 'thr_p':
45 WAY_thr_p_NAME=threaded profiled
46 WAY_thr_p_HC_OPTS=-optc-DTHREADED_RTS -prof
47
48 # Way 'debug':
49 WAY_debug_NAME=debug
50 WAY_debug_HC_OPTS=-optc-DDEBUG
51
52 # Way 'debug_p':
53 WAY_debug_p_NAME=debug profiled
54 WAY_debug_p_HC_OPTS=-optc-DDEBUG -prof
55
56 ifneq "$(findstring debug, $(way))" ""
57 GhcRtsHcOpts=
58 GhcRtsCcOpts=-g
59 endif
60
61 # -----------------------------------------------------------------------------
62
63 # Tells the build system not to add various Haskellish options to $(SRC_HC_OPTS)
64 NON_HS_PACKAGE = YES
65
66 # grab sources from these subdirectories
67 ALL_DIRS = hooks parallel
68
69 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
70 ALL_DIRS += win32
71 EXCLUDED_SRCS += Itimer.c Select.c Signals.c
72 endif
73
74 ifneq "$(DLLized)" "YES"
75 EXCLUDED_SRCS += RtsDllMain.c
76 else
77 EXCLUDED_SRCS += Main.c
78 endif
79
80 EXCLUDED_SRCS += parallel/SysMan.c
81
82 # The build system doesn't give us these
83 HC_SRCS = $(filter %.hc, $(SRCS))
84 HC_OBJS = $(patsubst %.hc,%.$(way_)o, $(HC_SRCS))
85
86 CLEAN_FILES += $(HC_OBJS)
87
88 # Override the default $(LIBOBJS) (defaults to $(HS_OBJS))
89 LIBOBJS = $(C_OBJS) $(HC_OBJS)
90
91 SplitObjs=NO
92
93 #-----------------------------------------------------------------------------
94 # Flags for compiling RTS .c and .hc files
95
96 # gcc provides lots of useful warnings if you ask it.
97 # This is a pretty good list to start with - use a # to comment out
98 # any you don't like.
99 WARNING_OPTS += -Wall 
100 WARNING_OPTS += -W
101 WARNING_OPTS += -Wstrict-prototypes 
102 WARNING_OPTS += -Wmissing-prototypes 
103 WARNING_OPTS += -Wmissing-declarations
104 WARNING_OPTS += -Winline
105 WARNING_OPTS += -Waggregate-return
106 #WARNING_OPTS += -Wpointer-arith
107 WARNING_OPTS += -Wbad-function-cast
108 #WARNING_OPTS += -Wcast-align
109 #WARNING_OPTS += -Wnested-externs
110 #WARNING_OPTS += -Wshadow
111 #WARNING_OPTS += -Wcast-qual
112 #WARNING_OPTS += -Wno-unused 
113 #WARNING_OPTS += -Wredundant-decls 
114 #WARNING_OPTS += -Wconversion
115
116 STANDARD_OPTS += -I../includes -I. -Iparallel
117 # COMPILING_RTS is only used when building Win32 DLL support.
118 STANDARD_OPTS += -DCOMPILING_RTS
119
120 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
121 STANDARD_OPTS += -Iwin32
122 endif
123
124 # HC_OPTS is included in both .c and .hc compilations, whereas CC_OPTS is
125 # only included in .c compilations.  HC_OPTS included the WAY_* opts, which
126 # must be included in both types of compilations.
127
128 SRC_CC_OPTS += $(WARNING_OPTS)
129 SRC_CC_OPTS += $(STANDARD_OPTS)
130
131 SRC_CC_OPTS += $(GhcRtsCcOpts)
132 SRC_HC_OPTS += $(GhcRtsHcOpts)
133
134 ifneq "$(DLLized)" "YES"
135 SRC_HC_OPTS += -static
136 endif
137 # SRC_HC_OPTS += -fPIC
138
139 ifeq "$(way)" "mp"
140 SRC_HC_OPTS += -I$$PVM_ROOT/include
141 endif
142
143 # If -DDEBUG is in effect, adjust package conf accordingly..
144 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
145 PACKAGE_CPP_OPTS += -DDEBUG
146 endif
147
148 ifeq "$(HaveLibMingwEx)" "YES"
149 PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
150 endif
151
152 ifeq "$(DotnetSupport)" "YES"
153
154
155 # Would like to just use SUBDIRS here, but need to
156 # descend into dotnet/ earlier than that.
157 #
158 all ::
159         $(MAKE) -C dotnet all
160
161 # But use SUBDIRS for other recursive targets.
162 SUBDIRS += dotnet
163
164 LIBOBJS += dotnet/Invoke.o
165 endif
166
167 #-----------------------------------------------------------------------------
168 # Include the Front panel code?
169
170 # we need GTK+ for the front panel
171 ifneq "$(GTK_CONFIG)" ""
172 ifeq "$(GhcRtsWithFrontPanel)" "YES"
173 SRC_HC_OPTS             += `$(GTK_CONFIG) --cflags` -optc-DRTS_GTK_FRONTPANEL
174 VisCallbacks_CC_OPTS    += -Wno-unused
175 SRC_MKDEPENDC_OPTS      += `$(GTK_CONFIG) --cflags`
176 else # GhcRtsWithFrontPanel
177 EXCLUDED_SRCS           += $(wildcard Vis*.c)
178 endif
179 else # GTK_CONFIG
180 EXCLUDED_SRCS           += $(wildcard Vis*.c)
181 endif
182
183 #-----------------------------------------------------------------------------
184 # make depend setup
185
186 MKDEPENDC_SRCS     = $(C_SRCS) $(HC_SRCS)
187 SRC_MKDEPENDC_OPTS += -I. -I../includes
188
189 # -----------------------------------------------------------------------------
190 # The auto-generated apply code
191
192 AUTO_APPLY = AutoApply.hc
193
194 ifneq "$(BootingFromHc)" "YES"
195 $(AUTO_APPLY): $(GHC_GENAPPLY)
196         @$(RM) $@
197         $(GHC_GENAPPLY) >$@
198 endif
199
200 EXTRA_SRCS += $(AUTO_APPLY)
201
202 CLEAN_FILES += $(AUTO_APPLY)
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 "$(HaveFrameworkHaskellSupport)" "YES"
237 boot ::
238         cd gmp && CC=$(WhatGccIsCalled) ./configure --enable-shared=no \
239                 --host=`echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g'`
240
241 # Slight cheatage here to pass host as target, but x-compilation isn't supported by ghc.
242
243 all :: gmp/libgmp.a
244
245 ifeq "$(DLLized)" "YES"
246 all :: $(DLL_PEN)/gmp.dll
247
248 $(DLL_PEN)/gmp.dll:
249         $(MAKE) -C gmp gmp.dll
250         $(MV) gmp/gmp.dll $(DLL_PEN)
251 endif
252
253 install :: gmp/libgmp.a
254
255 ifeq "$(way)" ""
256 clean distclean maintainer-clean ::
257         -$(MAKE) -C gmp MAKEFLAGS= $@
258
259 INSTALL_LIBS += gmp/libgmp.a
260 endif
261 endif
262
263 gmp/libgmp.a ::
264         $(MAKE) -C gmp MAKEFLAGS=
265         @$(CP) gmp/.libs/libgmp.a gmp
266         @$(RANLIB) gmp/libgmp.a
267 endif
268
269 CLEAN_FILES += gmp/libgmp.a
270
271 #-----------------------------------------------------------------------------
272 #
273 # Building the GUM SysMan
274 #
275
276 ifeq "$(way)" "mp"
277 all :: parallel/SysMan
278
279 ifdef solaris2_TARGET_OS
280 __socket_libs = -lsocket -lnsl
281 else
282 __socket_libs =
283 endif
284
285 parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
286         $(RM) $@
287         gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
288
289 CLEAN_FILES  += parallel/SysMan.mp_o parallel/SysMan
290 INSTALL_LIBEXECS += parallel/SysMan
291 endif
292
293 #-----------------------------------------------------------------------------
294 #
295 # Files to install
296 #
297 # Just libHSrts is installed uniformly across ways
298 #
299 INSTALL_LIBS += $(LIBRARY)
300 ifeq "$(DLLized)" "YES"
301 INSTALL_PROGS += $(DLL_NAME) gmp/gmp.dll
302 INSTALL_LIBS += $(patsubst %.a,%_imp.a,$(LIBARY))
303 INSTALL_LIBS += gmp/libgmp_imp.a Main.dll_o
304 endif
305
306 include $(TOP)/mk/target.mk