[project @ 2003-05-29 12:59:55 by simonmar]
[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 = $(shell if (test "x$(BootingFromHc)" = "xYES"); then echo NO; else echo YES; fi)
24
25 include $(TOP)/mk/boilerplate.mk
26
27 HC=$(GHC_INPLACE)
28
29 WAYS=$(GhcLibWays)
30
31 PACKAGE = rts
32
33 # Tells the build system not to add various Haskellish options to $(SRC_HC_OPTS)
34 NON_HS_PACKAGE = YES
35
36 # grab sources from these subdirectories
37 ALL_DIRS = hooks parallel
38
39 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
40 ALL_DIRS += win32
41 EXCLUDED_SRCS += Itimer.c Select.c Signals.c
42 endif
43
44 ifneq "$(DLLized)" "YES"
45 EXCLUDED_SRCS += RtsDllMain.c
46 else
47 EXCLUDED_SRCS += Main.c
48 endif
49
50 EXCLUDED_SRCS += parallel/SysMan.c
51
52 # The build system doesn't give us these
53 HC_SRCS = $(filter %.hc, $(SRCS))
54 HC_OBJS = $(patsubst %.hc,%.$(way_)o, $(HC_SRCS))
55
56 CLEAN_FILES += $(HC_OBJS)
57
58 # Override the default $(LIBOBJS) (defaults to $(HS_OBJS))
59 LIBOBJS = $(C_OBJS) $(HC_OBJS)
60
61 SplitObjs=NO
62
63 #-----------------------------------------------------------------------------
64 # Flags for compiling RTS .c and .hc files
65
66 # gcc provides lots of useful warnings if you ask it.
67 # This is a pretty good list to start with - use a # to comment out
68 # any you don't like.
69 WARNING_OPTS += -Wall 
70 WARNING_OPTS += -W
71 WARNING_OPTS += -Wstrict-prototypes 
72 WARNING_OPTS += -Wmissing-prototypes 
73 WARNING_OPTS += -Wmissing-declarations
74 WARNING_OPTS += -Winline
75 WARNING_OPTS += -Waggregate-return
76 #WARNING_OPTS += -Wpointer-arith
77 WARNING_OPTS += -Wbad-function-cast
78 #WARNING_OPTS += -Wcast-align
79 #WARNING_OPTS += -Wnested-externs
80 #WARNING_OPTS += -Wshadow
81 #WARNING_OPTS += -Wcast-qual
82 #WARNING_OPTS += -Wno-unused 
83 #WARNING_OPTS += -Wredundant-decls 
84 #WARNING_OPTS += -Wconversion
85
86 STANDARD_OPTS += -I../includes -I. -Iparallel
87 # COMPILING_RTS is only used when building Win32 DLL support.
88 STANDARD_OPTS += -DCOMPILING_RTS
89
90 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
91 STANDARD_OPTS += -Iwin32
92 endif
93
94 # HC_OPTS is included in both .c and .hc compilations, whereas CC_OPTS is
95 # only included in .c compilations.  HC_OPTS included the WAY_* opts, which
96 # must be included in both types of compilations.
97
98 SRC_CC_OPTS += $(WARNING_OPTS)
99 SRC_CC_OPTS += $(STANDARD_OPTS)
100
101 SRC_CC_OPTS += $(GhcRtsCcOpts)
102 SRC_HC_OPTS += $(GhcRtsHcOpts)
103
104 ifneq "$(DLLized)" "YES"
105 SRC_HC_OPTS += -static
106 endif
107 # SRC_HC_OPTS += -fPIC
108
109 ifeq "$(way)" "mp"
110 SRC_HC_OPTS += -I$$PVM_ROOT/include
111 endif
112
113 ifeq "$(BootingFromHc)" "YES"
114 # use the normal $(CC) when booting from .hc files
115 SRC_CC_OPTS += $(HC_OPTS)
116 endif
117
118 # Currently, you only get 'threads support' in the normal
119 # way.
120 ifeq "$(GhcRtsThreaded)" "YES"
121 ifeq "$(way)" ""
122 SRC_CC_OPTS += -DTHREADED_RTS
123 PACKAGE_CPP_OPTS += -DTHREADED_RTS
124 endif
125 endif
126
127 # If -DDEBUG is in effect, adjust package conf accordingly..
128 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
129 PACKAGE_CPP_OPTS += -DDEBUG
130 endif
131
132 ifeq "$(HaveLibMingwEx)" "YES"
133 PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
134 endif
135
136 #-----------------------------------------------------------------------------
137 # Include the Front panel code?
138
139 # we need GTK+ for the front panel
140 ifneq "$(GTK_CONFIG)" ""
141 ifeq "$(GhcRtsWithFrontPanel)" "YES"
142 SRC_HC_OPTS             += `$(GTK_CONFIG) --cflags` -optc-DRTS_GTK_FRONTPANEL
143 VisCallbacks_CC_OPTS    += -Wno-unused
144 else # GhcRtsWithFrontPanel
145 EXCLUDED_SRCS           += $(wildcard Vis*.c)
146 endif
147 else # GTK_CONFIG
148 EXCLUDED_SRCS           += $(wildcard Vis*.c)
149 endif
150
151 #-----------------------------------------------------------------------------
152 # make depend setup
153
154 MKDEPENDC_SRCS     = $(C_SRCS) $(HC_SRCS)
155 SRC_MKDEPENDC_OPTS += -I. -I../includes
156
157 # -----------------------------------------------------------------------------
158 # The auto-generated apply code
159
160 AUTO_APPLY = AutoApply.hc
161
162 gen_apply : GenApply.hs
163         $(GHC) -o $@ -I$(GHC_INCLUDE_DIR) GenApply.hs 
164
165 $(AUTO_APPLY): $(GHC_GENAPPLY)
166         @$(RM) $@
167         $(GHC_GENAPPLY) >$@
168
169 EXTRA_SRCS += $(AUTO_APPLY)
170
171 CLEAN_FILES += $(AUTO_APPLY)
172
173 # -----------------------------------------------------------------------------
174 #
175 #  Building DLLs is only supported on mingw32 at the moment.
176 #
177 ifeq "$(DLLized)" "YES"
178 SRC_BLD_DLL_OPTS += -lHS_imp_stub -lgmp_imp
179
180 # It's not included in the DLL, but we need to compile it up separately.
181 all :: Main.dll_o
182
183 # Need an import library containing the symbols the RTS uses from the Prelude.
184 # So, to avoid bootstrapping trouble, we build one containing just the syms
185 # we need. Weirdly named to avoid clashing later on when compiling the contents
186 # of ghc/lib/..
187 #
188 # Note: if you do change the name of the Prelude DLL, the "--dllname <nm>.dll"
189 # below will need to be updated as well.
190
191 $(DLL_PEN)/HSrts$(_way).dll :: libHS_imp_stub.a
192
193 libHS_imp_stub.a :
194         dlltool --output-lib libHS_imp_stub.a --def HSprel.def --dllname HSstd.dll
195
196 endif
197
198 # -----------------------------------------------------------------------------
199 # Compile GMP only if we don't have it already
200 #
201 # We use GMP's own configuration stuff, because it's all rather hairy
202 # and not worth re-implementing in our Makefile framework.
203
204 ifneq "$(HaveLibGmp)" "YES"
205 ifneq "$(HaveFrameworkHaskellSupport)" "YES"
206 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
207 boot ::
208         cd gmp && ./configure --enable-shared=no \
209                 --host=`echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g'`
210 else
211 # Pass --target to configure of GMP, so that building for mingwin under
212 # cygwin works properly (when the host is not the same as the target)
213 boot ::
214         cd gmp && CC=$(WhatGccIsCalled) ./configure --enable-shared=no --target=$(HOSTPLATFORM)
215 endif
216
217 # Slight cheatage here to pass host as target, but x-compilation isn't supported by ghc.
218
219 all :: gmp/libgmp.a
220
221 ifeq "$(DLLized)" "YES"
222 all :: $(DLL_PEN)/gmp.dll
223
224 $(DLL_PEN)/gmp.dll:
225         $(MAKE) -C gmp gmp.dll
226         $(MV) gmp/gmp.dll $(DLL_PEN)
227 endif
228
229 install :: gmp/libgmp.a
230
231 ifeq "$(way)" ""
232 clean distclean maintainer-clean ::
233         -$(MAKE) -C gmp MAKEFLAGS= $@
234
235 INSTALL_LIBS += gmp/libgmp.a
236 endif
237 endif
238
239 gmp/libgmp.a ::
240         $(MAKE) -C gmp MAKEFLAGS=
241         @$(CP) gmp/.libs/libgmp.a gmp
242         @$(RANLIB) gmp/libgmp.a
243 endif
244
245 CLEAN_FILES += gmp/libgmp.a
246
247 #-----------------------------------------------------------------------------
248 #
249 # Building the GUM SysMan
250 #
251
252 ifeq "$(way)" "mp"
253 all :: parallel/SysMan
254
255 ifdef solaris2_TARGET_OS
256 __socket_libs = -lsocket -lnsl
257 else
258 __socket_libs =
259 endif
260
261 parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
262         $(RM) $@
263         gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
264
265 CLEAN_FILES  += parallel/SysMan.mp_o parallel/SysMan
266 INSTALL_LIBEXECS += parallel/SysMan
267 endif
268
269 #-----------------------------------------------------------------------------
270 #
271 # Files to install
272 #
273 # Just libHSrts is installed uniformly across ways
274 #
275 INSTALL_LIBS += $(LIBRARY)
276 ifeq "$(DLLized)" "YES"
277 INSTALL_PROGS += $(DLL_NAME) gmp/gmp.dll
278 INSTALL_LIBS += $(patsubst %.a,%_imp.a,$(LIBARY))
279 INSTALL_LIBS += gmp/libgmp_imp.a Main.dll_o
280 endif
281
282 include $(TOP)/mk/target.mk