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