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