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