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