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