Makefile 14.9 KB
Newer Older
1
#-----------------------------------------------------------------------------
2
#
3
4
5
#  This is the Makefile for the runtime-system stuff.
#  This stuff is written in C (and cannot be written in Haskell).
#
6
7
8
9
#  .c  files are vanilla C,
#  .hc files are "Haskellized-C", compiled using the C compiler and
#      (possibly) the assembly-mangler.  The GHC driver script
#      knows how to compile this stuff.
10
11

#-----------------------------------------------------------------------------
12
# Preamble
13
14
15

TOP=..

16
17
18
19
# Set UseGhcForCc: this causes the fptools build system to use a different
# set of suffix rules for compiling C code, using $(HC) rather than $(CC)
# and prepending "-optc" to $(CC_OPTS).  NB. must be done before including
# boilerplate.mk below.
20
UseGhcForCc = YES
21

22
23
include $(TOP)/mk/boilerplate.mk

24
25
PACKAGE = rts

26
27
HC=$(GHC_INPLACE)

28
29

# Setting _way here is a nasty hack to make sure we get libHSrts*.a etc
30
# rather than just libHSrts.a when we are installing bindists.
31
32
33
34
ifeq "$(DOING_BIN_DIST)" "YES"
_way = *
endif

35
36
# -----------------------------------------------------------------------------
# RTS ways
37

Ben.Lippmeier@anu.edu.au's avatar
Ben.Lippmeier@anu.edu.au committed
38
WAYS=$(strip $(GhcLibWays) $(GhcRTSWays))
39

40
ifneq "$(findstring debug, $(way))" ""
41
GhcRtsHcOpts=
42
GhcRtsCcOpts=-g -O0
43
44
endif

45
46
47
48
ifeq "$(BeConservative)" "YES"
GhcRtsCcOpts += -DBE_CONSERVATIVE
endif

49
# -----------------------------------------------------------------------------
50

51
52
53
54
55
# There's nothing for Haddock here...
override HADDOCK_DOCS = NO

# -----------------------------------------------------------------------------

56
# Tells the build system not to add various Haskellish options to $(SRC_HC_OPTS)
sof's avatar
sof committed
57
NON_HS_PACKAGE = YES
58

59
# grab sources from these subdirectories
Simon Marlow's avatar
Simon Marlow committed
60
ALL_DIRS = hooks parallel sm eventlog
61

sof's avatar
sof committed
62
63
ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
ALL_DIRS += win32
64
65
else
ALL_DIRS += posix
sof's avatar
sof committed
66
67
endif

68
69
ifneq "$(findstring dyn, $(way))" ""
DYNAMIC_RTS=YES
sof's avatar
sof committed
70
else
71
72
73
74
DYNAMIC_RTS=NO
endif

ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
75
EXCLUDED_SRCS += Main.c
76
77
78
79
80
81
# It's not included in the DLL, but we need to compile it up separately.

all :: Main.$(way_)o
INSTALL_LIBS += Main.$(way_)o
else
EXCLUDED_SRCS += RtsDllMain.c
sof's avatar
sof committed
82
83
endif

84
# This file ends up being empty unless we're building for a powerpc
85
86
# or darwin system, and it is reported that Solaris ld chokes on it when
# building HSrts.o.
87
ifeq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
88
ifeq "$(findstring $(TargetOS_CPP), darwin)" ""
89
90
EXCLUDED_SRCS += AdjustorAsm.S
endif
91
endif
92

93
94
EXCLUDED_SRCS += parallel/SysMan.c

95
96
EXCLUDED_SRCS += dyn-wrapper.c

97
# compile generic patchable dyn-wrapper
98
99
100
101
102
103

DYNWRAPPER_SRC = dyn-wrapper.c
DYNWRAPPER_PROG = dyn-wrapper$(exeext)
$(DYNWRAPPER_PROG): $(DYNWRAPPER_SRC)
	$(HC) -cpp -optc-include -optcdyn-wrapper-patchable-behaviour.h $(INPLACE_EXTRA_FLAGS) $< -o $@

104
# The build system doesn't give us these
105
106
CMM_SRCS = $(filter-out AutoApply%.cmm, $(wildcard *.cmm)) $(EXTRA_CMM_SRCS)
CMM_OBJS = $(patsubst %.cmm,%.$(way_)o, $(CMM_SRCS))
107

108
CLEAN_FILES += $(CMM_OBJS)
109

110
# Override the default $(LIBOBJS) (defaults to $(HS_OBJS))
111
LIBOBJS = $(C_OBJS) $(CMM_OBJS)
112
113

SplitObjs=NO
114

115
116
H_FILES = $(wildcard ../includes/*.h) $(wildcard *.h)

117
118
119
#-----------------------------------------------------------------------------
# Flags for compiling RTS .c and .hc files

120
121
122
# gcc provides lots of useful warnings if you ask it.
# This is a pretty good list to start with - use a # to comment out
# any you don't like.
123
WARNING_OPTS += -Wall
124
125
126
127
128
129
130
WARNING_OPTS += -W
WARNING_OPTS += -Wstrict-prototypes 
WARNING_OPTS += -Wmissing-prototypes 
WARNING_OPTS += -Wmissing-declarations
WARNING_OPTS += -Winline
WARNING_OPTS += -Waggregate-return
#WARNING_OPTS += -Wpointer-arith
131
#WARNING_OPTS += -Wbad-function-cast
132
#WARNING_OPTS += -Wcast-align
133
134
135
136
137
138
139
#WARNING_OPTS += -Wnested-externs
#WARNING_OPTS += -Wshadow
#WARNING_OPTS += -Wcast-qual
#WARNING_OPTS += -Wno-unused 
#WARNING_OPTS += -Wredundant-decls 
#WARNING_OPTS += -Wconversion

Simon Marlow's avatar
Simon Marlow committed
140
141
STANDARD_OPTS += -I../includes -I. -Iparallel -Ism -Ieventlog

sof's avatar
sof committed
142
143
# COMPILING_RTS is only used when building Win32 DLL support.
STANDARD_OPTS += -DCOMPILING_RTS
sof's avatar
sof committed
144

145
# HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
146
147
148
# only included in .c compilations.  HC_OPTS included the WAY_* opts, which
# must be included in both types of compilations.

149
SRC_CC_OPTS += $(WARNING_OPTS)
sof's avatar
sof committed
150
SRC_CC_OPTS += $(STANDARD_OPTS)
151

152
SRC_CC_OPTS += $(GhcRtsCcOpts)
153
SRC_HC_OPTS += $(GhcRtsHcOpts) $(STANDARD_OPTS) -package-name rts
sof's avatar
sof committed
154

155
156
157
158
159
ifneq "$(GhcWithSMP)" "YES"
SRC_CC_OPTS += -DNOSMP
SRC_HC_OPTS += -optc-DNOSMP
endif

160
161
ifeq "$(UseLibFFIForAdjustors)" "YES"
SRC_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
162
163
endif

164
165
166
167
168
169
ifeq "$(Windows)" "YES"
# SDM: when compiled with -fasm the RTS currently has bogus references to 
# __imp_base_ things, so working around for now:
SRC_HC_OPTS = -fvia-C
endif

170
ifneq "$(DYNAMIC_RTS)" "YES"
171
SRC_HC_OPTS += -static
172
173
174
else
LIB_LD_OPTS += -ignore-package base -ignore-package rts
ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
175
176
177
LIB_DEPS=buildbase
.PHONY: buildbase

178
BASE_DIST_LIB=$(TOP)/libraries/base/dist/build
179
180

# The following must be a one liner otherwise its evaluation won't be delayed until base/rts packages are properly registered
181
LIB_LD_OPTS = $(foreach lib,$(shell $(GHC_PKG_INPLACE) field base hs-libraries | sed -e 's/hs-libraries: //'),"-l$(lib)-ghc$(ProjectVersion)$(soext)") $(foreach lib,$(shell $(GHC_PKG_INPLACE) field rts extra-libraries | sed -e s/extra-libraries://),"-l$(lib)") $(foreach libdir,$(shell $(GHC_PKG_INPLACE) field base library-dirs | sed -e 's/library-dirs: //' | sed -e s,\\\\,/,g) $(shell $(GHC_PKG_INPLACE) field rts library-dirs | sed -e s/library-dirs:// | sed -e s/\\\\/\\\\\\\\/g),"-L$(libdir)")
182
endif
sof's avatar
sof committed
183
endif
184

185
186
187
188
189
# Mac OS X: make sure we compile for the right OS version
SRC_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
SRC_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
LIB_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))

190
# XXX DQ is now the same on all platforms, so get rid of it
191
192
DQ = \"

193
194
195
196
197
198
# If Main.c is built with optimisation then the SEH exception stuff on
# Windows gets confused.
# This has to be in HC rather than CC opts, as otherwise there's a
# -optc-O2 that comes after it.
Main_HC_OPTS += -optc-O0

199
200
201
RtsMessages_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
RtsUtils_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
RtsUtils_CC_OPTS += -DRtsWay=$(DQ)rts$(_way)$(DQ)
202
#
203
RtsUtils_CC_OPTS += -DHostPlatform=$(DQ)$(HOSTPLATFORM)$(DQ)
204
205
206
207
RtsUtils_CC_OPTS += -DHostArch=$(DQ)$(HostArch_CPP)$(DQ)
RtsUtils_CC_OPTS += -DHostOS=$(DQ)$(HostOS_CPP)$(DQ)
RtsUtils_CC_OPTS += -DHostVendor=$(DQ)$(HostVendor_CPP)$(DQ)
#
208
RtsUtils_CC_OPTS += -DBuildPlatform=$(DQ)$(BUILDPLATFORM)$(DQ)
209
210
211
212
RtsUtils_CC_OPTS += -DBuildArch=$(DQ)$(BuildArch_CPP)$(DQ)
RtsUtils_CC_OPTS += -DBuildOS=$(DQ)$(BuildOS_CPP)$(DQ)
RtsUtils_CC_OPTS += -DBuildVendor=$(DQ)$(BuildVendor_CPP)$(DQ)
#
213
RtsUtils_CC_OPTS += -DTargetPlatform=$(DQ)$(TARGETPLATFORM)$(DQ)
214
215
216
217
RtsUtils_CC_OPTS += -DTargetArch=$(DQ)$(TargetArch_CPP)$(DQ)
RtsUtils_CC_OPTS += -DTargetOS=$(DQ)$(TargetOS_CPP)$(DQ)
RtsUtils_CC_OPTS += -DTargetVendor=$(DQ)$(TargetVendor_CPP)$(DQ)
#
218
219
RtsUtils_CC_OPTS += -DGhcUnregisterised=$(DQ)$(GhcUnregisterised)$(DQ)
RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=$(DQ)$(GhcEnableTablesNextToCode)$(DQ)
220

221
222
# ffi.h triggers prototype warnings, so disable them here:
Interpreter_CC_OPTS += -Wno-strict-prototypes
223
Adjustor_CC_OPTS += -Wno-strict-prototypes
224
sm/Storage_CC_OPTS += -Wno-strict-prototypes
225

226
227
228
229
StgCRun_CC_OPTS += -w
Typeable_CC_OPTS += -w
RetainerProfile_CC_OPTS += -w
sm/Compact_CC_OPTS += -w
Ian Lynagh's avatar
Ian Lynagh committed
230
231
232
233
# On Windows:
win32/ConsoleHandler_CC_OPTS += -w
win32/ThrIOManager_CC_OPTS += -w
win32/Ticker_CC_OPTS += -w
234
235
236
237
238
239
# The above warning supression flags are a temporary kludge.
# While working on this module you are encouraged to remove it and fix
# any warnings in the module. See
#     http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
# for details

240
241
242
243
ifeq "$(way)" "mp"
SRC_HC_OPTS += -I$$PVM_ROOT/include
endif

sof's avatar
sof committed
244
# If -DDEBUG is in effect, adjust package conf accordingly..
245
246
247
248
249
250
ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
PACKAGE_CPP_OPTS += -DDEBUG
endif

ifeq "$(HaveLibMingwEx)" "YES"
PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
sof's avatar
sof committed
251
252
endif

253
254
255
256
ifeq "$(GhciWithDebugger)" "YES"
STANDARD_OPTS += -DDEBUGGER
endif

sof's avatar
sof committed
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
ifeq "$(DotnetSupport)" "YES"

# 
# Would like to just use SUBDIRS here, but need to
# descend into dotnet/ earlier than that.
#
all ::
	$(MAKE) -C dotnet all

# But use SUBDIRS for other recursive targets.
SUBDIRS += dotnet

LIBOBJS += dotnet/Invoke.o
endif

272
273
274
# Suppress uninitialized variable warnings for GC.c
GC_CC_OPTS 	+= -Wno-uninitialized

275
276
277
278
279
280
#-----------------------------------------------------------------------------
# Include the Front panel code?

# we need GTK+ for the front panel
ifneq "$(GTK_CONFIG)" ""
ifeq "$(GhcRtsWithFrontPanel)" "YES"
281
SRC_HC_OPTS 		+= `$(GTK_CONFIG) --cflags` -optc-DRTS_GTK_FRONTPANEL
282
VisCallbacks_CC_OPTS 	+= -Wno-unused
283
SRC_MKDEPENDC_OPTS	+= `$(GTK_CONFIG) --cflags`
284
285
286
287
288
289
else # GhcRtsWithFrontPanel
EXCLUDED_SRCS		+= $(wildcard Vis*.c)
endif
else # GTK_CONFIG
EXCLUDED_SRCS		+= $(wildcard Vis*.c)
endif
290

291
292
293
#-----------------------------------------------------------------------------
# Add PAPI library if needed

294
ifeq "$(GhcRtsWithPapi)" "YES"
295

296
SRC_CC_OPTS		+= -DUSE_PAPI
297
PACKAGE_CPP_OPTS	+= -DUSE_PAPI
298
299
300
301
302
303
304
305

PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=$(PapiIncludeDir)
PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=$(PapiLibDir)

ifneq "$(PapiIncludeDir)" ""
SRC_HC_OPTS += -I$(PapiIncludeDir)
SRC_CC_OPTS += -I$(PapiIncludeDir)
SRC_HSC2HS_OPTS += -I$(PapiIncludeDir)
306
endif
307
308
309
310
ifneq "$(PapiLibDirs)" ""
SRC_LD_OPTS += -L$(PapiLibDirs)
endif

311
312
else # GhcRtsWithPapi==YES

313
PACKAGE_CPP_OPTS += -DPAPI_INCLUDE_DIR=""
314
315
316
PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=""

endif
317

318
#-----------------------------------------------------------------------------
319
# make depend setup
320

321
322
SRC_MKDEPENDC_OPTS += -I. -I../includes

323
324
325
326
# Hack: we define every way-related option here, so that we get (hopefully)
# a superset of the dependencies.  To do this properly, we should generate
# a different set of dependencies for each way.  Further hack: PROFILING and
# TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
Simon Marlow's avatar
Simon Marlow committed
327
SRC_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG -DEVENTLOG
328

329
330
331
# -----------------------------------------------------------------------------
# The auto-generated apply code

332
333
334
# We want a slightly different version for the unregisterised way, so we make
# AutoApply on a per-way basis (eg. AutoApply_p.cmm).

Ian Lynagh's avatar
Ian Lynagh committed
335
336
ifneq "$(DOING_BIN_DIST)" "YES"

337
AUTO_APPLY_CMM = AutoApply$(_way).cmm
338

339
ifneq "$(BootingFromHc)" "YES"
340
$(AUTO_APPLY_CMM): $(GHC_GENAPPLY)
341
	@$(RM) $@
342
	$(GENAPPLY) $(if $(filter $(way), u debug_u), -u) >$@
343
endif
344

345
EXTRA_CMM_SRCS += $(AUTO_APPLY_CMM)
346

347
CLEAN_FILES += $(AUTO_APPLY_CMM)
348

Ian Lynagh's avatar
Ian Lynagh committed
349
350
endif

351
# -----------------------------------------------------------------------------
352

353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# Need to get the GMP vars in through CPP to package.conf.in, and put
# quotes around each element.

empty =
space = $(empty) $(empty)
comma = ,
PACKAGE_CPP_OPTS += -DGMP_INCLUDE_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_INCLUDE_DIRS))))'
PACKAGE_CPP_OPTS += -DGMP_LIB_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_LIB_DIRS))))'

ifneq "$(GMP_INCLUDE_DIRS)" ""
SRC_HC_OPTS += -I$(GMP_INCLUDE_DIRS)
SRC_CC_OPTS += -I$(GMP_INCLUDE_DIRS)
SRC_HSC2HS_OPTS += -I$(GMP_INCLUDE_DIRS)
endif
ifneq "$(GMP_LIB_DIRS)" ""
SRC_LD_OPTS += -L$(GMP_LIB_DIRS)
endif

371
372
373
374
375
SRC_CC_OPTS += -I../gmp/gmpbuild
SRC_HC_OPTS += -I../gmp/gmpbuild
SRC_HSC2HS_OPTS += -I../gmp/gmpbuild
SRC_LD_OPTS += -L../gmp/gmpbuild

376
377
378
379
380
381
382
383
#-----------------------------------------------------------------------------
# libffi stuff

SRC_CC_OPTS     += -I../libffi/build/include
SRC_HC_OPTS     += -I../libffi/build/include
SRC_HSC2HS_OPTS += -I../libffi/build/include
SRC_LD_OPTS     += -L../libffi/build/include

384
385
386
387
388
389
#-----------------------------------------------------------------------------
#
# Building the GUM SysMan
#

ifeq "$(way)" "mp"
390
all :: parallel/SysMan
391
392
393
394
395
396
397

ifdef solaris2_TARGET_OS
__socket_libs = -lsocket -lnsl
else
__socket_libs =
endif

398
parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
399
	$(RM) $@
400
	gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
401

402
403
CLEAN_FILES  += parallel/SysMan.mp_o parallel/SysMan
INSTALL_LIBEXECS += parallel/SysMan
404
405
endif

406
407
408
409
#-----------------------------------------------------------------------------
# Compiling the cmm files

# ToDo: should we really include Rts.h here?  Required for GNU_ATTRIBUTE().
410
SRC_HC_OPTS += -I.
411

412
413
414
415
416
# Otherwise the stack-smash handler gets triggered.
ifeq "$(TargetOS_CPP)" "openbsd"
SRC_HC_OPTS += -optc-fno-stack-protector
endif

417
# -O3 helps unroll some loops (especially in copy() with a constant argument).
418
sm/Evac_HC_OPTS += -optc-funroll-loops
419

420
421
ifneq "$(findstring thr, $(way))" ""
EXTRA_SRCS += sm/Evac_thr.c sm/Scav_thr.c
422
CLEAN_FILES += sm/Evac_thr.c sm/Scav_thr.c
423
424
425
426
427
428
429
430

sm/Evac_thr.c : sm/Evac.c
	cp $< $@
sm/Scav_thr.c : sm/Scav.c
	cp $< $@

sm/Evac_thr_HC_OPTS += -optc-DPARALLEL_GC
sm/Scav_thr_HC_OPTS += -optc-DPARALLEL_GC
431
432

sm/Evac_thr_HC_OPTS += -optc-funroll-loops
433
434
435
436
else
EXCLUDED_SRCS += sm/Evac_thr.c sm/Scav_thr.c
endif

437
# Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
438
sm/Compact_HC_OPTS += -optc-finline-limit=2500
439

440
441
442
443
# -fno-strict-aliasing is required for the runtime, because we often
# use a variety of types to represent closure pointers (StgPtr,
# StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
# allowed to assume that these pointers do not alias.  eg. without
444
# this flag we get problems in sm/Evac.c:copy() with gcc 3.4.3, the
445
446
# upd_evacee() assigments get moved before the object copy.
SRC_CC_OPTS += -fno-strict-aliasing
447

448
449
450
# We *want* type-checking of hand-written cmm.
SRC_HC_OPTS += -dcmm-lint 

451
ifneq "$(BootingFromHc)" "YES"
452
453
454
455
456
457
458
459
460
461
462
# .cmm files depend on all the .h files, to a first approximation.
%.$(way_)o : %.cmm $(H_FILES)
	$(HC_PRE_OPTS)
	$(HC) $(HC_OPTS) -c $< -o $@
	$(HC_POST_OPTS)

%.$(way_)hc : %.cmm $(H_FILES)
	$(HC) $(HC_OPTS) -C $< -o $@

%.$(way_)s : %.cmm $(H_FILES)
	$(HC) $(HC_OPTS) -S $< -o $@
463
endif
464

465
466
467
468
469
470
#-----------------------------------------------------------------------------
#
# Files to install
#
# Just libHSrts is installed uniformly across ways
#
471
472
473
474

include $(TOP)/mk/target.mk

ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
475
476
477
478
# $(LIBRARY).a is not the static library libHSrts.a but
# libHSrts.dll.a, the import library for dynamic linking required for
# linking the dynamic version of base
buildbase: $(LIBRARY).a
479
480
	$(MAKE) way="" -C ../libraries/ make.library.ghc-prim
	$(MAKE) way="" -C ../libraries/ make.library.integer-gmp
481
	$(MAKE) way="" -C ../libraries/ make.library.base
sof's avatar
sof committed
482
endif
483

484
485
486
487
#-----------------------------------------------------------------------------
#
# binary-dist

488
489
490
BINDIST_EXTRAS += package.conf.in
BINDIST_EXTRAS += $(INSTALL_LIBS)
BINDIST_EXTRAS += $(INSTALL_LIBEXECS)
491
492
493
494
495

# Setting _way here is a nasty hack to make sure we get libHSrts*.a etc
# rather than just libHSrts.a when we are making bindists.
binary-dist: _way=*

496
497
include $(TOP)/mk/bindist.mk