Windows DLLs: gmp is in the integer-gmp package now.
[ghc-hetmet.git] / rts / ghc.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009 The University of Glasgow
4 #
5 # This file is part of the GHC build system.
6 #
7 # To understand how the build system works and how to modify it, see
8 #      http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
9 #      http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
10 #
11 # -----------------------------------------------------------------------------
12
13 # -----------------------------------------------------------------------------
14 # Building the RTS
15
16 # We build the RTS with stage 1
17 rts_dist_HC = $(GHC_STAGE1)
18
19 # merge GhcLibWays and GhcRTSWays but strip out duplicates
20 rts_WAYS = $(GhcLibWays) $(filter-out $(GhcLibWays),$(GhcRTSWays))
21
22 ALL_RTS_LIBS = $(foreach way,$(rts_WAYS),rts/dist/build/libHSrts$($(way)_libsuf)) \
23                rts/dist/build/libHSrtsmain.a
24 all_rts : $(ALL_RTS_LIBS)
25
26 # -----------------------------------------------------------------------------
27 # Defining the sources
28
29 ALL_DIRS = hooks parallel sm eventlog
30
31 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
32 ALL_DIRS += win32
33 else
34 ALL_DIRS += posix
35 endif
36
37 EXCLUDED_SRCS += rts/Main.c
38 EXCLUDED_SRCS += rts/parallel/SysMan.c
39 EXCLUDED_SRCS += rts/dyn-wrapper.c
40 EXCLUDED_SRCS += $(wildcard rts/Vis*.c)
41
42 rts_C_SRCS = $(filter-out $(EXCLUDED_SRCS),$(wildcard rts/*.c $(foreach dir,$(ALL_DIRS),rts/$(dir)/*.c)))
43 rts_CMM_SRCS = $(wildcard rts/*.cmm)
44
45 # Don't compile .S files when bootstrapping a new arch
46 ifeq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
47 ifneq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
48 rts_S_SRCS += rts/AdjustorAsm.S
49 else
50 ifneq "$(findstring $(TargetOS_CPP), darwin)" ""
51 rts_S_SRCS += rts/AdjustorAsm.S
52 endif
53 endif
54 endif
55
56 ifeq "$(GhcUnregisterised)" "YES"
57 GENAPPLY_OPTS = -u
58 endif
59
60 rts_AUTO_APPLY_CMM = rts/dist/build/AutoApply.cmm
61
62 $(rts_AUTO_APPLY_CMM): $(GENAPPLY_INPLACE)
63         "$(GENAPPLY_INPLACE)" >$@
64
65 rts/dist/build/sm/Evac_thr.c : rts/sm/Evac.c | $$(dir $$@)/.
66         cp $< $@
67 rts/dist/build/sm/Scav_thr.c : rts/sm/Scav.c | $$(dir $$@)/.
68         cp $< $@
69
70 rts_H_FILES = $(wildcard includes/*.h) $(wildcard rts/*.h)
71
72 # collect the -l flags that we need to link the rts dyn lib.
73 rts/libs.depend : $(GHC_PKG_INPLACE)
74         "$(GHC_PKG_INPLACE)" field rts extra-libraries \
75           | sed -e 's/^extra-libraries: //' -e 's/\([a-z0-9]*\)[ ]*/-l\1 /g' > $@
76
77
78 # ----------------------------------------------------------------------------
79 # On Windows, as the RTS and base libraries have recursive imports,
80 #       we have to break the loop with "import libraries".
81 #       These are made from rts/win32/libHS*.def which contain lists of
82 #       all the symbols in those libraries used by the RTS.
83 #
84 ifneq "$$(findstring dyn, $1)" ""
85 ifeq  "$(HOSTPLATFORM)" "i386-unknown-mingw32" 
86
87 ALL_RTS_DEF_LIBNAMES    = base ghc-prim
88 ALL_RTS_DEF_LIBS        = \
89         rts/dist/build/win32/libHSbase.dll.a \
90         rts/dist/build/win32/libHSghc-prim.dll.a \
91         rts/dist/build/win32/libHSffi.dll.a 
92
93 # -- import libs for the regular Haskell libraries
94 define make-importlib-def # args $1 = lib name
95 rts/dist/build/win32/libHS$1.def : rts/win32/libHS$1.def
96         cat rts/win32/libHS$1.def \
97                 | sed "s/@LibVersion@/$$(libraries/$1_dist-install_VERSION)/" \
98                 | sed "s/@ProjectVersion@/$(ProjectVersion)/" \
99                 > rts/dist/build/win32/libHS$1.def
100                 
101 rts/dist/build/win32/libHS$1.dll.a : rts/dist/build/win32/libHS$1.def
102         "$$(DLLTOOL)"   -d rts/dist/build/win32/libHS$1.def \
103                         -l rts/dist/build/win32/libHS$1.dll.a
104 endef
105 $(foreach lib,$(ALL_RTS_DEF_LIBNAMES),$(eval $(call make-importlib-def,$(lib))))
106
107
108 # -- import libs for libffi
109 rts/dist/build/win32/libHSffi.def : rts/win32/libHSffi.def
110         cat rts/win32/libHSffi.def \
111                 | sed "s/@ProjectVersion@/$(ProjectVersion)/" \
112                 > rts/dist/build/win32/libHSffi.def
113                 
114 rts/dist/build/win32/libHSffi.dll.a : rts/dist/build/win32/libHSffi.def
115         "$(DLLTOOL)"    -d rts/dist/build/win32/libHSffi.def \
116                         -l rts/dist/build/win32/libHSffi.dll.a
117 endif
118 endif
119
120
121 #-----------------------------------------------------------------------------
122 # Building one way
123 define build-rts-way # args: $1 = way
124
125 # The per-way CC_OPTS
126 ifneq "$$(findstring debug, $1)" ""
127 rts_dist_$1_HC_OPTS =
128 rts_dist_$1_CC_OPTS = -g -O0
129 else
130 rts_dist_$1_HC_OPTS = $$(GhcRtsHcOpts)
131 rts_dist_$1_CC_OPTS = $$(GhcRtsCcOpts)
132 endif
133
134 ifneq "$$(findstring thr, $1)" ""
135 rts_$1_EXTRA_C_SRCS  =  rts/dist/build/sm/Evac_thr.c rts/dist/build/sm/Scav_thr.c
136 endif
137
138 $(call distdir-way-opts,rts,dist,$1)
139 $(call c-suffix-rules,rts,dist,$1,YES)
140 $(call cmm-suffix-rules,rts,dist,$1)
141 $(call hs-suffix-rules-srcdir,rts,dist,$1,$$(dir))
142 # hs-suffix-rules-srcdir is needed when BootingFromHc to get the .hc rules
143
144 rts_$1_LIB = rts/dist/build/libHSrts$$($1_libsuf)
145
146 rts_$1_C_OBJS   = $$(patsubst rts/%.c,rts/dist/build/%.$$($1_osuf),$$(rts_C_SRCS)) $$(patsubst %.c,%.$$($1_osuf),$$(rts_$1_EXTRA_C_SRCS))
147 rts_$1_S_OBJS   = $$(patsubst rts/%.S,rts/dist/build/%.$$($1_osuf),$$(rts_S_SRCS))
148 rts_$1_CMM_OBJS = $$(patsubst rts/%.cmm,rts/dist/build/%.$$($1_osuf),$$(rts_CMM_SRCS)) $$(patsubst %.cmm,%.$$($1_osuf),$$(rts_AUTO_APPLY_CMM))
149
150 rts_$1_OBJS = $$(rts_$1_C_OBJS) $$(rts_$1_S_OBJS) $$(rts_$1_CMM_OBJS)
151
152 rts_dist_$1_CC_OPTS += -DRtsWay=$$(DQ)rts_$1$$(DQ)
153
154 # Making a shared library for the RTS.
155 ifneq "$$(findstring dyn, $1)" ""
156 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
157 $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/libs.depend
158         "$$(RM)" $$(RM_OPTS) $$@
159         "$$(rts_dist_HC)" -shared -dynamic -dynload deploy \
160           -no-auto-link-packages `cat rts/libs.depend` $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) -o $$@
161 else
162 $$(rts_$1_LIB) : $$(rts_$1_OBJS) rts/libs.depend
163         "$$(RM)" $$(RM_OPTS) $$@
164         "$$(rts_dist_HC)" -shared -dynamic -dynload deploy \
165           -no-auto-link-packages `cat rts/libs.depend` $$(rts_$1_OBJS) -o $$@
166 endif
167 else
168 $$(rts_$1_LIB) : $$(rts_$1_OBJS)
169         "$$(RM)" $$(RM_OPTS) $$@
170         echo $$(rts_$1_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR)" $$(AR_OPTS) $$(EXTRA_AR_ARGS) $$@
171 endif
172
173 endef
174
175 # And expand the above for each way:
176 $(foreach way,$(rts_WAYS),$(eval $(call build-rts-way,$(way))))
177
178 #-----------------------------------------------------------------------------
179 # Flags for compiling every file
180
181 # We like plenty of warnings.
182 WARNING_OPTS += -Wall
183 ifeq "$(GccLT34)" "YES"
184 WARNING_OPTS += -W
185 else
186 WARNING_OPTS += -Wextra
187 endif
188 WARNING_OPTS += -Wstrict-prototypes 
189 WARNING_OPTS += -Wmissing-prototypes 
190 WARNING_OPTS += -Wmissing-declarations
191 WARNING_OPTS += -Winline
192 WARNING_OPTS += -Waggregate-return
193 WARNING_OPTS += -Wpointer-arith
194 WARNING_OPTS += -Wmissing-noreturn
195 WARNING_OPTS += -Wcast-align
196 WARNING_OPTS += -Wnested-externs
197 WARNING_OPTS += -Wredundant-decls 
198
199 # These ones are hard to avoid:
200 #WARNING_OPTS += -Wconversion
201 #WARNING_OPTS += -Wbad-function-cast
202 #WARNING_OPTS += -Wshadow
203 #WARNING_OPTS += -Wcast-qual
204
205 STANDARD_OPTS += -Iincludes -Irts
206 # COMPILING_RTS is only used when building Win32 DLL support.
207 STANDARD_OPTS += -DCOMPILING_RTS
208
209 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
210 # only included in .c compilations.  HC_OPTS included the WAY_* opts, which
211 # must be included in both types of compilations.
212
213 rts_CC_OPTS += $(WARNING_OPTS)
214 rts_CC_OPTS += $(STANDARD_OPTS)
215
216 rts_HC_OPTS += $(STANDARD_OPTS) -package-name rts
217
218 ifneq "$(GhcWithSMP)" "YES"
219 rts_CC_OPTS += -DNOSMP
220 rts_HC_OPTS += -optc-DNOSMP
221 endif
222
223 ifeq "$(UseLibFFIForAdjustors)" "YES"
224 rts_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
225 endif
226
227 # Mac OS X: make sure we compile for the right OS version
228 rts_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
229 rts_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
230 rts_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
231
232 # Otherwise the stack-smash handler gets triggered.
233 ifneq "$(findstring $(TargetOS_CPP), darwin openbsd)" ""
234 rts_HC_OPTS += -optc-fno-stack-protector
235 endif
236
237 # We *want* type-checking of hand-written cmm.
238 rts_HC_OPTS += -dcmm-lint 
239
240 # -fno-strict-aliasing is required for the runtime, because we often
241 # use a variety of types to represent closure pointers (StgPtr,
242 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
243 # allowed to assume that these pointers do not alias.  eg. without
244 # this flag we get problems in sm/Evac.c:copy() with gcc 3.4.3, the
245 # upd_evacee() assigments get moved before the object copy.
246 rts_CC_OPTS += -fno-strict-aliasing
247
248 rts_CC_OPTS += -fno-common
249
250 ifeq "$(BeConservative)" "YES"
251 rts_CC_OPTS += -DBE_CONSERVATIVE
252 endif
253
254 #-----------------------------------------------------------------------------
255 # Flags for compiling specific files
256
257 # XXX DQ is now the same on all platforms, so get rid of it
258 DQ = \"
259
260 # If RtsMain.c is built with optimisation then the SEH exception stuff on
261 # Windows gets confused.
262 # This has to be in HC rather than CC opts, as otherwise there's a
263 # -optc-O2 that comes after it.
264 rts/RtsMain_HC_OPTS += -optc-O0
265
266 rts/RtsMessages_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
267 rts/RtsUtils_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
268 #
269 rts/RtsUtils_CC_OPTS += -DHostPlatform=$(DQ)$(HOSTPLATFORM)$(DQ)
270 rts/RtsUtils_CC_OPTS += -DHostArch=$(DQ)$(HostArch_CPP)$(DQ)
271 rts/RtsUtils_CC_OPTS += -DHostOS=$(DQ)$(HostOS_CPP)$(DQ)
272 rts/RtsUtils_CC_OPTS += -DHostVendor=$(DQ)$(HostVendor_CPP)$(DQ)
273 #
274 rts/RtsUtils_CC_OPTS += -DBuildPlatform=$(DQ)$(BUILDPLATFORM)$(DQ)
275 rts/RtsUtils_CC_OPTS += -DBuildArch=$(DQ)$(BuildArch_CPP)$(DQ)
276 rts/RtsUtils_CC_OPTS += -DBuildOS=$(DQ)$(BuildOS_CPP)$(DQ)
277 rts/RtsUtils_CC_OPTS += -DBuildVendor=$(DQ)$(BuildVendor_CPP)$(DQ)
278 #
279 rts/RtsUtils_CC_OPTS += -DTargetPlatform=$(DQ)$(TARGETPLATFORM)$(DQ)
280 rts/RtsUtils_CC_OPTS += -DTargetArch=$(DQ)$(TargetArch_CPP)$(DQ)
281 rts/RtsUtils_CC_OPTS += -DTargetOS=$(DQ)$(TargetOS_CPP)$(DQ)
282 rts/RtsUtils_CC_OPTS += -DTargetVendor=$(DQ)$(TargetVendor_CPP)$(DQ)
283 #
284 rts/RtsUtils_CC_OPTS += -DGhcUnregisterised=$(DQ)$(GhcUnregisterised)$(DQ)
285 rts/RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=$(DQ)$(GhcEnableTablesNextToCode)$(DQ)
286
287 # ffi.h triggers prototype warnings, so disable them here:
288 rts/Interpreter_CC_OPTS += -Wno-strict-prototypes
289 rts/Adjustor_CC_OPTS    += -Wno-strict-prototypes
290 rts/sm/Storage_CC_OPTS  += -Wno-strict-prototypes
291
292 # inlining warnings happen in Compact
293 rts/sm/Compact_CC_OPTS += -Wno-inline
294
295 # emits warnings about call-clobbered registers on x86_64
296 rts/StgCRun_CC_OPTS += -w
297
298 rts/RetainerProfile_CC_OPTS += -w
299 rts/RetainerSet_CC_OPTS += -Wno-format
300 # On Windows:
301 rts/win32/ConsoleHandler_CC_OPTS += -w
302 rts/win32/ThrIOManager_CC_OPTS += -w
303 rts/win32/Ticker_CC_OPTS += -w
304 # The above warning supression flags are a temporary kludge.
305 # While working on this module you are encouraged to remove it and fix
306 # any warnings in the module. See
307 #     http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
308 # for details
309
310 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
311 rts/sm/Compact_CC_OPTS += -finline-limit=2500
312
313 # -O3 helps unroll some loops (especially in copy() with a constant argument).
314 rts/sm/Evac_CC_OPTS += -funroll-loops
315 rts/dist/build/sm/Evac_thr_HC_OPTS += -optc-funroll-loops
316
317 # These files are just copies of sm/Evac.c and sm/Scav.c respectively,
318 # but compiled with -DPARALLEL_GC.
319 rts/dist/build/sm/Evac_thr_HC_OPTS += -optc-DPARALLEL_GC -Irts/sm
320 rts/dist/build/sm/Scav_thr_HC_OPTS += -optc-DPARALLEL_GC -Irts/sm
321
322 #-----------------------------------------------------------------------------
323 # Add PAPI library if needed
324
325 ifeq "$(GhcRtsWithPapi)" "YES"
326
327 rts_CC_OPTS             += -DUSE_PAPI
328
329 rts_PACKAGE_CPP_OPTS    += -DUSE_PAPI
330 rts_PACKAGE_CPP_OPTS    += -DPAPI_INCLUDE_DIR=$(PapiIncludeDir)
331 rts_PACKAGE_CPP_OPTS    += -DPAPI_LIB_DIR=$(PapiLibDir)
332
333 ifneq "$(PapiIncludeDir)" ""
334 rts_HC_OPTS     += -I$(PapiIncludeDir)
335 rts_CC_OPTS     += -I$(PapiIncludeDir)
336 rts_HSC2HS_OPTS += -I$(PapiIncludeDir)
337 endif
338 ifneq "$(PapiLibDirs)" ""
339 rts_LD_OPTS     += -L$(PapiLibDirs)
340 endif
341
342 else # GhcRtsWithPapi==YES
343
344 rts_PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=""
345 rts_PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=""
346
347 endif
348
349 # -----------------------------------------------------------------------------
350 # dependencies
351
352 # Hack: we define every way-related option here, so that we get (hopefully)
353 # a superset of the dependencies.  To do this properly, we should generate
354 # a different set of dependencies for each way.  Further hack: PROFILING and
355 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
356 rts_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
357 rts_MKDEPENDC_OPTS += -Irts/sm
358
359 rts_WAYS_DASHED = $(subst $(space),,$(patsubst %,-%,$(strip $(rts_WAYS))))
360 rts_dist_depfile = rts/dist/build/.depend$(rts_WAYS_DASHED)
361
362 rts_dist_C_SRCS  = $(rts_C_SRCS) $(rts_thr_EXTRA_C_SRCS)
363 rts_dist_S_SRCS =  $(rts_S_SRCS)
364 rts_dist_C_FILES = $(rts_C_SRCS) $(rts_thr_EXTRA_C_SRCS) $(rts_S_SRCS)
365
366 $(eval $(call build-dependencies,rts,dist))
367
368 $(rts_dist_depfile) : libffi/dist-install/build/ffi.h
369
370 #-----------------------------------------------------------------------------
371 # libffi stuff
372
373 rts_CC_OPTS     += -Ilibffi/build/include
374 rts_HC_OPTS     += -Ilibffi/build/include
375 rts_HSC2HS_OPTS += -Ilibffi/build/include
376 rts_LD_OPTS     += -Llibffi/build/include
377
378 # -----------------------------------------------------------------------------
379 # compile generic patchable dyn-wrapper
380
381 DYNWRAPPER_SRC = rts/dyn-wrapper.c
382 DYNWRAPPER_PROG = rts/dyn-wrapper$(exeext)
383 $(DYNWRAPPER_PROG): $(DYNWRAPPER_SRC)
384         "$(HC)" -cpp -optc-include -optcdyn-wrapper-patchable-behaviour.h $(INPLACE_EXTRA_FLAGS) $< -o $@
385
386 # -----------------------------------------------------------------------------
387 # build the static lib containing the C main symbol
388
389 rts/dist/build/libHSrtsmain.a : rts/dist/build/Main.o
390         "$(AR)" $(AR_OPTS) $(EXTRA_AR_ARGS) $@ $<
391
392 # -----------------------------------------------------------------------------
393 # The RTS package config
394
395 # If -DDEBUG is in effect, adjust package conf accordingly..
396 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
397 rts_PACKAGE_CPP_OPTS += -DDEBUG
398 endif
399
400 ifeq "$(HaveLibMingwEx)" "YES"
401 rts_PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
402 endif
403
404 $(eval $(call manual-package-config,rts))
405
406 ifneq "$(BootingFromHc)" "YES"
407 rts/package.conf.inplace : $(includes_H_CONFIG) $(includes_H_PLATFORM)
408 endif
409
410 # -----------------------------------------------------------------------------
411 # installing
412
413 install : install_rts
414
415 .PHONY: install_rts
416 install_rts:
417         $(INSTALL_DIR) "$(DESTDIR)$(ghclibdir)"
418         $(INSTALL_DIR) "$(DESTDIR)$(ghclibdir)/include"
419         "$(CP)" $(ALL_RTS_LIBS) "$(DESTDIR)$(ghclibdir)"
420
421 # -----------------------------------------------------------------------------
422 # cleaning
423
424 $(eval $(call clean-target,rts,dist,rts/dist))
425
426 BINDIST_EXTRAS += rts/package.conf.in
427 BINDIST_EXTRAS += $(ALL_RTS_LIBS)
428