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