25fcb4f8f3d58d091303de60d78f72ab33ca8f73
[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 # Building one way
79
80 define build-rts-way # args: $1 = way
81
82 # The per-way CC_OPTS
83 ifneq "$$(findstring debug, $1)" ""
84 rts_dist_$1_HC_OPTS =
85 rts_dist_$1_CC_OPTS = -g -O0
86 else
87 rts_dist_$1_HC_OPTS = $$(GhcRtsHcOpts)
88 rts_dist_$1_CC_OPTS = $$(GhcRtsCcOpts)
89 endif
90
91 ifneq "$$(findstring thr, $1)" ""
92 rts_$1_EXTRA_C_SRCS  =  rts/dist/build/sm/Evac_thr.c rts/dist/build/sm/Scav_thr.c
93 endif
94
95 $(call distdir-way-opts,rts,dist,$1)
96 $(call c-suffix-rules,rts,dist,$1,YES)
97 $(call cmm-suffix-rules,rts,dist,$1)
98 $(call hs-suffix-rules-srcdir,rts,dist,$1,$$(dir))
99 # hs-suffix-rules-srcdir is needed when BootingFromHc to get the .hc rules
100
101 rts_$1_LIB = rts/dist/build/libHSrts$$($1_libsuf)
102
103 rts_$1_C_OBJS   = $$(patsubst rts/%.c,rts/dist/build/%.$$($1_osuf),$$(rts_C_SRCS)) $$(patsubst %.c,%.$$($1_osuf),$$(rts_$1_EXTRA_C_SRCS))
104 rts_$1_S_OBJS   = $$(patsubst rts/%.S,rts/dist/build/%.$$($1_osuf),$$(rts_S_SRCS))
105 rts_$1_CMM_OBJS = $$(patsubst rts/%.cmm,rts/dist/build/%.$$($1_osuf),$$(rts_CMM_SRCS)) $$(patsubst %.cmm,%.$$($1_osuf),$$(rts_AUTO_APPLY_CMM))
106
107 rts_$1_OBJS = $$(rts_$1_C_OBJS) $$(rts_$1_S_OBJS) $$(rts_$1_CMM_OBJS)
108
109 rts_dist_$1_CC_OPTS += -DRtsWay=$$(DQ)rts_$1$$(DQ)
110
111 ifneq "$$(findstring dyn, $1)" ""
112 $$(rts_$1_LIB) : $$(rts_$1_OBJS) rts/libs.depend
113         "$$(RM)" $$(RM_OPTS) $$@
114         "$$(rts_dist_HC)" -shared -dynamic -dynload deploy \
115           -no-auto-link-packages `cat rts/libs.depend` $$(rts_$1_OBJS) -o $$@
116 else
117 $$(rts_$1_LIB) : $$(rts_$1_OBJS)
118         "$$(RM)" $$(RM_OPTS) $$@
119         echo $$(rts_$1_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR)" $$(AR_OPTS) $$(EXTRA_AR_ARGS) $$@
120 endif
121
122 endef
123
124 # And expand the above for each way:
125 $(foreach way,$(rts_WAYS),$(eval $(call build-rts-way,$(way))))
126
127 #-----------------------------------------------------------------------------
128 # Flags for compiling every file
129
130 # We like plenty of warnings.
131 WARNING_OPTS += -Wall
132 ifeq "$(GccLT34)" "YES"
133 WARNING_OPTS += -W
134 else
135 WARNING_OPTS += -Wextra
136 endif
137 WARNING_OPTS += -Wstrict-prototypes 
138 WARNING_OPTS += -Wmissing-prototypes 
139 WARNING_OPTS += -Wmissing-declarations
140 WARNING_OPTS += -Winline
141 WARNING_OPTS += -Waggregate-return
142 WARNING_OPTS += -Wpointer-arith
143 WARNING_OPTS += -Wmissing-noreturn
144 WARNING_OPTS += -Wcast-align
145 WARNING_OPTS += -Wnested-externs
146 WARNING_OPTS += -Wredundant-decls 
147
148 # These ones are hard to avoid:
149 #WARNING_OPTS += -Wconversion
150 #WARNING_OPTS += -Wbad-function-cast
151 #WARNING_OPTS += -Wshadow
152 #WARNING_OPTS += -Wcast-qual
153
154 STANDARD_OPTS += -Iincludes -Irts
155 # COMPILING_RTS is only used when building Win32 DLL support.
156 STANDARD_OPTS += -DCOMPILING_RTS
157
158 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
159 # only included in .c compilations.  HC_OPTS included the WAY_* opts, which
160 # must be included in both types of compilations.
161
162 rts_CC_OPTS += $(WARNING_OPTS)
163 rts_CC_OPTS += $(STANDARD_OPTS)
164
165 rts_HC_OPTS += $(STANDARD_OPTS) -package-name rts
166
167 ifneq "$(GhcWithSMP)" "YES"
168 rts_CC_OPTS += -DNOSMP
169 rts_HC_OPTS += -optc-DNOSMP
170 endif
171
172 ifeq "$(UseLibFFIForAdjustors)" "YES"
173 rts_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
174 endif
175
176 # Mac OS X: make sure we compile for the right OS version
177 rts_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
178 rts_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
179 rts_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
180
181 # Otherwise the stack-smash handler gets triggered.
182 ifneq "$(findstring $(TargetOS_CPP), darwin openbsd)" ""
183 rts_HC_OPTS += -optc-fno-stack-protector
184 endif
185
186 # We *want* type-checking of hand-written cmm.
187 rts_HC_OPTS += -dcmm-lint 
188
189 # -fno-strict-aliasing is required for the runtime, because we often
190 # use a variety of types to represent closure pointers (StgPtr,
191 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
192 # allowed to assume that these pointers do not alias.  eg. without
193 # this flag we get problems in sm/Evac.c:copy() with gcc 3.4.3, the
194 # upd_evacee() assigments get moved before the object copy.
195 rts_CC_OPTS += -fno-strict-aliasing
196
197 rts_CC_OPTS += -fno-common
198
199 ifeq "$(BeConservative)" "YES"
200 rts_CC_OPTS += -DBE_CONSERVATIVE
201 endif
202
203 #-----------------------------------------------------------------------------
204 # Flags for compiling specific files
205
206 # XXX DQ is now the same on all platforms, so get rid of it
207 DQ = \"
208
209 # If RtsMain.c is built with optimisation then the SEH exception stuff on
210 # Windows gets confused.
211 # This has to be in HC rather than CC opts, as otherwise there's a
212 # -optc-O2 that comes after it.
213 rts/RtsMain_HC_OPTS += -optc-O0
214
215 rts/RtsMessages_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
216 rts/RtsUtils_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
217 #
218 rts/RtsUtils_CC_OPTS += -DHostPlatform=$(DQ)$(HOSTPLATFORM)$(DQ)
219 rts/RtsUtils_CC_OPTS += -DHostArch=$(DQ)$(HostArch_CPP)$(DQ)
220 rts/RtsUtils_CC_OPTS += -DHostOS=$(DQ)$(HostOS_CPP)$(DQ)
221 rts/RtsUtils_CC_OPTS += -DHostVendor=$(DQ)$(HostVendor_CPP)$(DQ)
222 #
223 rts/RtsUtils_CC_OPTS += -DBuildPlatform=$(DQ)$(BUILDPLATFORM)$(DQ)
224 rts/RtsUtils_CC_OPTS += -DBuildArch=$(DQ)$(BuildArch_CPP)$(DQ)
225 rts/RtsUtils_CC_OPTS += -DBuildOS=$(DQ)$(BuildOS_CPP)$(DQ)
226 rts/RtsUtils_CC_OPTS += -DBuildVendor=$(DQ)$(BuildVendor_CPP)$(DQ)
227 #
228 rts/RtsUtils_CC_OPTS += -DTargetPlatform=$(DQ)$(TARGETPLATFORM)$(DQ)
229 rts/RtsUtils_CC_OPTS += -DTargetArch=$(DQ)$(TargetArch_CPP)$(DQ)
230 rts/RtsUtils_CC_OPTS += -DTargetOS=$(DQ)$(TargetOS_CPP)$(DQ)
231 rts/RtsUtils_CC_OPTS += -DTargetVendor=$(DQ)$(TargetVendor_CPP)$(DQ)
232 #
233 rts/RtsUtils_CC_OPTS += -DGhcUnregisterised=$(DQ)$(GhcUnregisterised)$(DQ)
234 rts/RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=$(DQ)$(GhcEnableTablesNextToCode)$(DQ)
235
236 # ffi.h triggers prototype warnings, so disable them here:
237 rts/Interpreter_CC_OPTS += -Wno-strict-prototypes
238 rts/Adjustor_CC_OPTS    += -Wno-strict-prototypes
239 rts/sm/Storage_CC_OPTS  += -Wno-strict-prototypes
240
241 # inlining warnings happen in Compact
242 rts/sm/Compact_CC_OPTS += -Wno-inline
243
244 # emits warnings about call-clobbered registers on x86_64
245 rts/StgCRun_CC_OPTS += -w
246
247 rts/RetainerProfile_CC_OPTS += -w
248 rts/RetainerSet_CC_OPTS += -Wno-format
249 # On Windows:
250 rts/win32/ConsoleHandler_CC_OPTS += -w
251 rts/win32/ThrIOManager_CC_OPTS += -w
252 rts/win32/Ticker_CC_OPTS += -w
253 # The above warning supression flags are a temporary kludge.
254 # While working on this module you are encouraged to remove it and fix
255 # any warnings in the module. See
256 #     http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
257 # for details
258
259 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
260 rts/sm/Compact_CC_OPTS += -finline-limit=2500
261
262 # -O3 helps unroll some loops (especially in copy() with a constant argument).
263 rts/sm/Evac_CC_OPTS += -funroll-loops
264 rts/dist/build/sm/Evac_thr_HC_OPTS += -optc-funroll-loops
265
266 # These files are just copies of sm/Evac.c and sm/Scav.c respectively,
267 # but compiled with -DPARALLEL_GC.
268 rts/dist/build/sm/Evac_thr_HC_OPTS += -optc-DPARALLEL_GC -Irts/sm
269 rts/dist/build/sm/Scav_thr_HC_OPTS += -optc-DPARALLEL_GC -Irts/sm
270
271 #-----------------------------------------------------------------------------
272 # Add PAPI library if needed
273
274 ifeq "$(GhcRtsWithPapi)" "YES"
275
276 rts_CC_OPTS             += -DUSE_PAPI
277
278 rts_PACKAGE_CPP_OPTS    += -DUSE_PAPI
279 rts_PACKAGE_CPP_OPTS    += -DPAPI_INCLUDE_DIR=$(PapiIncludeDir)
280 rts_PACKAGE_CPP_OPTS    += -DPAPI_LIB_DIR=$(PapiLibDir)
281
282 ifneq "$(PapiIncludeDir)" ""
283 rts_HC_OPTS     += -I$(PapiIncludeDir)
284 rts_CC_OPTS     += -I$(PapiIncludeDir)
285 rts_HSC2HS_OPTS += -I$(PapiIncludeDir)
286 endif
287 ifneq "$(PapiLibDirs)" ""
288 rts_LD_OPTS     += -L$(PapiLibDirs)
289 endif
290
291 else # GhcRtsWithPapi==YES
292
293 rts_PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=""
294 rts_PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=""
295
296 endif
297
298 # -----------------------------------------------------------------------------
299 # dependencies
300
301 # Hack: we define every way-related option here, so that we get (hopefully)
302 # a superset of the dependencies.  To do this properly, we should generate
303 # a different set of dependencies for each way.  Further hack: PROFILING and
304 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
305 rts_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
306 rts_MKDEPENDC_OPTS += -Irts/sm
307
308 rts_WAYS_DASHED = $(subst $(space),,$(patsubst %,-%,$(strip $(rts_WAYS))))
309 rts_dist_depfile = rts/dist/build/.depend$(rts_WAYS_DASHED)
310
311 rts_dist_C_SRCS  = $(rts_C_SRCS) $(rts_thr_EXTRA_C_SRCS)
312 rts_dist_S_SRCS =  $(rts_S_SRCS)
313 rts_dist_C_FILES = $(rts_C_SRCS) $(rts_thr_EXTRA_C_SRCS) $(rts_S_SRCS)
314
315 $(eval $(call build-dependencies,rts,dist))
316
317 $(rts_dist_depfile) : libffi/dist-install/build/ffi.h
318
319 #-----------------------------------------------------------------------------
320 # libffi stuff
321
322 rts_CC_OPTS     += -Ilibffi/build/include
323 rts_HC_OPTS     += -Ilibffi/build/include
324 rts_HSC2HS_OPTS += -Ilibffi/build/include
325 rts_LD_OPTS     += -Llibffi/build/include
326
327 # -----------------------------------------------------------------------------
328 # compile generic patchable dyn-wrapper
329
330 DYNWRAPPER_SRC = rts/dyn-wrapper.c
331 DYNWRAPPER_PROG = rts/dyn-wrapper$(exeext)
332 $(DYNWRAPPER_PROG): $(DYNWRAPPER_SRC)
333         "$(HC)" -cpp -optc-include -optcdyn-wrapper-patchable-behaviour.h $(INPLACE_EXTRA_FLAGS) $< -o $@
334
335 # -----------------------------------------------------------------------------
336 # build the static lib containing the C main symbol
337
338 rts/dist/build/libHSrtsmain.a : rts/dist/build/Main.o
339         "$(AR)" $(AR_OPTS) $(EXTRA_AR_ARGS) $@ $<
340
341 # -----------------------------------------------------------------------------
342 # The RTS package config
343
344 # If -DDEBUG is in effect, adjust package conf accordingly..
345 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
346 rts_PACKAGE_CPP_OPTS += -DDEBUG
347 endif
348
349 ifeq "$(HaveLibMingwEx)" "YES"
350 rts_PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
351 endif
352
353 $(eval $(call manual-package-config,rts))
354
355 ifneq "$(BootingFromHc)" "YES"
356 rts/package.conf.inplace : $(includes_H_CONFIG) $(includes_H_PLATFORM)
357 endif
358
359 # -----------------------------------------------------------------------------
360 # installing
361
362 install : install_rts
363
364 .PHONY: install_rts
365 install_rts:
366         $(INSTALL_DIR) "$(DESTDIR)$(ghclibdir)"
367         $(INSTALL_DIR) "$(DESTDIR)$(ghclibdir)/include"
368         "$(CP)" $(ALL_RTS_LIBS) "$(DESTDIR)$(ghclibdir)"
369
370 # -----------------------------------------------------------------------------
371 # cleaning
372
373 $(eval $(call clean-target,rts,dist,rts/dist))
374
375 BINDIST_EXTRAS += rts/package.conf.in
376 BINDIST_EXTRAS += $(ALL_RTS_LIBS)
377