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