ghc.mk 22 KB
Newer Older
1 2 3 4 5 6 7
# -----------------------------------------------------------------------------
#
# (c) 2009 The University of Glasgow
#
# This file is part of the GHC build system.
#
# To understand how the build system works and how to modify it, see
8 9
#      https://gitlab.haskell.org/ghc/ghc/wikis/building/architecture
#      https://gitlab.haskell.org/ghc/ghc/wikis/building/modifying
10 11 12
#
# -----------------------------------------------------------------------------

Ian Lynagh's avatar
Ian Lynagh committed
13 14 15 16 17 18
# -----------------------------------------------------------------------------
# Building the RTS

# We build the RTS with stage 1
rts_dist_HC = $(GHC_STAGE1)

19 20 21
rts_INSTALL_INFO = rts
rts_VERSION = 1.0

22 23 24 25 26 27 28 29
# Minimum supported Windows version.
# These numbers can be found at:
#  https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx
# If we're compiling on windows, enforce that we only support Vista SP1+
# Adding this here means it doesn't have to be done in individual .c files
# and also centralizes the versioning.
rts_WINVER = 0x06000100

30 31
# merge GhcLibWays and GhcRTSWays but strip out duplicates
rts_WAYS = $(GhcLibWays) $(filter-out $(GhcLibWays),$(GhcRTSWays))
Ian Lynagh's avatar
Ian Lynagh committed
32
rts_dist_WAYS = $(rts_WAYS)
Ian Lynagh's avatar
Ian Lynagh committed
33

34
ALL_RTS_LIBS = $(foreach way,$(rts_WAYS),rts/dist/build/libHSrts$($(way)_libsuf))
35
$(eval $(call all-target,rts,$(ALL_RTS_LIBS)))
Ian Lynagh's avatar
Ian Lynagh committed
36 37 38 39

# -----------------------------------------------------------------------------
# Defining the sources

40
ALL_DIRS = hooks sm eventlog linker
Ian Lynagh's avatar
Ian Lynagh committed
41

42
ifeq "$(TargetOS_CPP)" "mingw32"
Ian Lynagh's avatar
Ian Lynagh committed
43 44 45 46 47
ALL_DIRS += win32
else
ALL_DIRS += posix
endif

48
rts_C_SRCS := $(wildcard rts/*.c $(foreach dir,$(ALL_DIRS),rts/$(dir)/*.c))
49
rts_C_HOOK_SRCS := $(wildcard rts/hooks/*.c)
50
rts_CMM_SRCS := $(wildcard rts/*.cmm)
Ian Lynagh's avatar
Ian Lynagh committed
51

Ian Lynagh's avatar
Ian Lynagh committed
52
# Don't compile .S files when bootstrapping a new arch
53
ifneq "$(PORTING_HOST)" "YES"
54
ifneq "$(findstring $(TargetArch_CPP), i386 powerpc powerpc64)" ""
Ian Lynagh's avatar
Ian Lynagh committed
55 56
rts_S_SRCS += rts/AdjustorAsm.S
endif
57
# this matches substrings of powerpc64le, including "powerpc" and "powerpc64"
58
ifneq "$(findstring $(TargetArch_CPP), powerpc64le)" ""
59 60
# unregisterised builds use the mini interpreter
ifneq "$(GhcUnregisterised)" "YES"
61 62
rts_S_SRCS += rts/StgCRunAsm.S
endif
Ian Lynagh's avatar
Ian Lynagh committed
63
endif
64
endif
Ian Lynagh's avatar
Ian Lynagh committed
65 66 67 68 69 70 71

ifeq "$(GhcUnregisterised)" "YES"
GENAPPLY_OPTS = -u
endif

rts_AUTO_APPLY_CMM = rts/dist/build/AutoApply.cmm

72 73
$(rts_AUTO_APPLY_CMM): $$(genapply_INPLACE)
	"$(genapply_INPLACE)" >$@
Ian Lynagh's avatar
Ian Lynagh committed
74 75


76
rts_H_FILES := $(wildcard rts/*.h rts/*/*.h)
Ian Lynagh's avatar
Ian Lynagh committed
77

78
ifeq "$(USE_DTRACE)" "YES"
79 80 81 82
DTRACEPROBES_H = rts/dist/build/RtsProbes.h
rts_H_FILES += $(DTRACEPROBES_H)
endif

83
# collect the -l and -L flags that we need to link the rts dyn lib.
ian@well-typed.com's avatar
ian@well-typed.com committed
84 85
# Note that, as sed on OS X doesn't handle \+, we use [^ ][^ ]* rather
# than [^ ]\+
86
rts/dist/libs.depend : $$(ghc-pkg_INPLACE) | $$(dir $$@)/.
87
	"$(ghc-pkg_INPLACE)" --simple-output field rts extra-libraries \
ian@well-typed.com's avatar
ian@well-typed.com committed
88
	  | sed -e 's/\([^ ][^ ]*\)/-l\1/g' > $@
89
	"$(ghc-pkg_INPLACE)" --simple-output field rts library-dirs \
ian@well-typed.com's avatar
ian@well-typed.com committed
90
	  | sed -e 's/\([^ ][^ ]*\)/-L\1/g' >> $@
91

92 93 94 95 96 97 98

# ----------------------------------------------------------------------------
# On Windows, as the RTS and base libraries have recursive imports,
# 	we have to break the loop with "import libraries".
# 	These are made from rts/win32/libHS*.def which contain lists of
# 	all the symbols in those libraries used by the RTS.
#
99
ifeq "$(TargetOS_CPP)" "mingw32"
100 101 102 103

ALL_RTS_DEF_LIBNAMES 	= base ghc-prim
ALL_RTS_DEF_LIBS	= \
	rts/dist/build/win32/libHSbase.dll.a \
104
	rts/dist/build/win32/libHSghc-prim.dll.a
105 106 107 108 109 110

# -- import libs for the regular Haskell libraries
define make-importlib-def # args $1 = lib name
rts/dist/build/win32/libHS$1.def : rts/win32/libHS$1.def
	cat rts/win32/libHS$1.def \
		| sed "s/@LibVersion@/$$(libraries/$1_dist-install_VERSION)/" \
111
		| sed "s/@ProjectVersion@/$$(ProjectVersion)/" \
112
		> rts/dist/build/win32/libHS$1.def
113

114 115 116 117 118 119 120
rts/dist/build/win32/libHS$1.dll.a : rts/dist/build/win32/libHS$1.def
	"$$(DLLTOOL)" 	-d rts/dist/build/win32/libHS$1.def \
			-l rts/dist/build/win32/libHS$1.dll.a
endef
$(foreach lib,$(ALL_RTS_DEF_LIBNAMES),$(eval $(call make-importlib-def,$(lib))))
endif

121
ifneq "$(BINDIST)" "YES"
122
ifneq "$(UseSystemLibFFI)" "YES"
123
ifeq "$(TargetOS_CPP)" "mingw32"
ian@well-typed.com's avatar
ian@well-typed.com committed
124
rts/dist/build/$(LIBFFI_DLL): libffi/build/inst/bin/$(LIBFFI_DLL)
125 126
	cp $< $@
else
127 128
# This is a little hacky. We don't know the SO version, so we only
# depend on libffi.so, but copy libffi.so*
ian@well-typed.com's avatar
ian@well-typed.com committed
129 130
rts/dist/build/lib$(LIBFFI_NAME)$(soext): libffi/build/inst/lib/lib$(LIBFFI_NAME)$(soext)
	cp libffi/build/inst/lib/lib$(LIBFFI_NAME)$(soext)* rts/dist/build
131
ifeq "$(TargetOS_CPP)" "darwin"
132
	install_name_tool -id @rpath/lib$(LIBFFI_NAME)$(soext) rts/dist/build/lib$(LIBFFI_NAME)$(soext)
133
endif
134
endif
135
endif
136
endif
137

Ben Gamari's avatar
Ben Gamari committed
138 139 140 141 142 143 144

ifeq "$(USE_DTRACE)" "YES"
ifneq "$(findstring $(TargetOS_CPP), linux solaris2 freebsd)" ""
NEED_DTRACE_PROBES_OBJ = YES
endif
endif

Ian Lynagh's avatar
Ian Lynagh committed
145 146 147 148
#-----------------------------------------------------------------------------
# Building one way
define build-rts-way # args: $1 = way

149 150
ifneq "$$(BINDIST)" "YES"

151 152 153
rts_dist_$1_HC_OPTS := $$(GhcRtsHcOpts)
rts_dist_$1_CC_OPTS := $$(GhcRtsCcOpts)

Ian Lynagh's avatar
Ian Lynagh committed
154 155
# The per-way CC_OPTS
ifneq "$$(findstring debug, $1)" ""
156
rts_dist_$1_HC_OPTS += -O0
157
rts_dist_$1_CC_OPTS += -fno-omit-frame-pointer -O0 -g3
158 159 160
# Useful to ensure that inline functions can be called within GDB but not
# supported by clang
#rts_dist_$1_CC_OPTS += -fkeep-inline-functions
Ian Lynagh's avatar
Ian Lynagh committed
161 162
endif

163
ifneq "$$(findstring dyn, $1)" ""
164
ifeq "$$(TargetOS_CPP)" "mingw32"
165 166
rts_dist_$1_CC_OPTS += -DCOMPILING_WINDOWS_DLL
endif
167
rts_dist_$1_CC_OPTS += -DDYNAMIC
168 169
endif

Ian Lynagh's avatar
Ian Lynagh committed
170

171
$(call distdir-way-opts,rts,dist,$1,1) # 1 because the rts is built with stage1
Ian Lynagh's avatar
Ian Lynagh committed
172 173 174
$(call c-suffix-rules,rts,dist,$1,YES)
$(call cmm-suffix-rules,rts,dist,$1)

175 176
rts_$1_LIB_FILE = libHSrts$$($1_libsuf)
rts_$1_LIB = rts/dist/build/$$(rts_$1_LIB_FILE)
Ian Lynagh's avatar
Ian Lynagh committed
177

178 179 180 181
rts_$1_C_OBJS      = $$(patsubst rts/%.c,rts/dist/build/%.$$($1_osuf),$$(rts_C_SRCS)) $$(patsubst %.c,%.$$($1_osuf),$$(rts_$1_EXTRA_C_SRCS))
rts_$1_C_HOOK_OBJS = $$(patsubst rts/hooks/%.c,rts/dist/build/hooks/%.$$($1_osuf),$$(rts_C_HOOK_SRCS))
rts_$1_S_OBJS      = $$(patsubst rts/%.S,rts/dist/build/%.$$($1_osuf),$$(rts_S_SRCS))
rts_$1_CMM_OBJS    = $$(patsubst rts/%.cmm,rts/dist/build/%.$$($1_osuf),$$(rts_CMM_SRCS)) $$(patsubst %.cmm,%.$$($1_osuf),$$(rts_AUTO_APPLY_CMM))
Ian Lynagh's avatar
Ian Lynagh committed
182 183 184

rts_$1_OBJS = $$(rts_$1_C_OBJS) $$(rts_$1_S_OBJS) $$(rts_$1_CMM_OBJS)

185
ifeq "$(USE_DTRACE)" "YES"
186
ifeq "$(NEED_DTRACE_PROBES_OBJ)" "YES"
187 188 189 190 191
# On Darwin we don't need to generate binary containing probes defined
# in DTrace script, but DTrace on Solaris expects generation of binary
# from the DTrace probes definitions
rts_$1_DTRACE_OBJS = rts/dist/build/RtsProbes.$$($1_osuf)

Ben Gamari's avatar
Ben Gamari committed
192
$$(rts_$1_DTRACE_OBJS) : $$(rts_$1_OBJS)
Ian Lynagh's avatar
Ian Lynagh committed
193
	$(DTRACE) -G -C $$(addprefix -I,$$(GHC_INCLUDE_DIRS)) -DDTRACE -s rts/RtsProbes.d -o \
194 195 196 197
		$$@ $$(rts_$1_OBJS)
endif
endif

198
rts_dist_$1_CC_OPTS += -DRtsWay=\"rts_$1\"
199

200 201 202 203
# If we're compiling on windows, enforce that we only support XP+
# Adding this here means it doesn't have to be done in individual .c files
# and also centralizes the versioning.
ifeq "$$(TargetOS_CPP)" "mingw32"
204
rts_dist_$1_CC_OPTS += -DWINVER=$(rts_WINVER)
205 206
endif

207
ifneq "$$(UseSystemLibFFI)" "YES"
ian@well-typed.com's avatar
ian@well-typed.com committed
208
rts_dist_FFI_SO = rts/dist/build/lib$$(LIBFFI_NAME)$$(soext)
209 210 211 212
else
rts_dist_FFI_SO =
endif

213
# Making a shared library for the RTS.
214
ifneq "$$(findstring dyn, $1)" ""
215
ifeq "$$(TargetOS_CPP)" "mingw32"
216
$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/dist/libs.depend rts/dist/build/$$(LIBFFI_DLL)
217
	"$$(RM)" $$(RM_OPTS) $$@
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
	# Call out to the shell script to decide how to build the dll.
	# Making a shared library for the RTS.
	# $$1  = dir
	# $$2  = distdir
	# $$3  = way
	# $$4  = extra flags
	# $$5  = extra libraries to link
	# $$6  = object files to link
	# $$7  = output filename
	# $$8  = link command
	# $$9  = create delay load import lib
	# $$10 = SxS Name
	# $$11 = SxS Version
	$$(gen-dll_INPLACE) link "rts/dist/build" "rts/dist/build" "" "" "$$(ALL_RTS_DEF_LIBS)" "$$(rts_$1_OBJS)" "$$@" "$$(rts_dist_HC) -this-unit-id rts -no-hs-main -shared -dynamic -dynload deploy \
         -no-auto-link-packages -Lrts/dist/build -l$$(LIBFFI_NAME) \
         `cat rts/dist/libs.depend | tr '\n' ' '` \
         $$(rts_dist_$1_GHC_LD_OPTS)" "NO" \
         "$(rts_INSTALL_INFO)-$(subst dyn,,$(subst _dyn,,$(subst v,,$1)))" "$(ProjectVersion)"

237
else
238
ifneq "$$(UseSystemLibFFI)" "YES"
ian@well-typed.com's avatar
ian@well-typed.com committed
239
LIBFFI_LIBS = -Lrts/dist/build -l$$(LIBFFI_NAME)
240
ifeq "$$(TargetElf)" "YES"
241
LIBFFI_LIBS += -optl-Wl,-rpath -optl-Wl,'$$$$ORIGIN' -optl-Wl,-zorigin
242
endif
243 244 245
ifeq "$(TargetOS_CPP)" "darwin"
LIBFFI_LIBS += -optl-Wl,-rpath -optl-Wl,@loader_path
endif
246

247
else
248
# flags will be taken care of in rts/dist/libs.depend
249 250
LIBFFI_LIBS =
endif
251
$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/dist/libs.depend $$(rts_dist_FFI_SO)
252
	"$$(RM)" $$(RM_OPTS) $$@
253
	"$$(rts_dist_HC)" -this-unit-id rts -shared -dynamic -dynload deploy \
254
	  -no-auto-link-packages $$(LIBFFI_LIBS) `cat rts/dist/libs.depend` $$(rts_$1_OBJS) \
255
          $$(rts_dist_$1_GHC_LD_OPTS) \
256
	  $$(rts_$1_DTRACE_OBJS) -o $$@
257
endif
258
else
Ben Gamari's avatar
Ben Gamari committed
259 260 261

ifeq "$(USE_DTRACE)" "YES"
ifeq "$(NEED_DTRACE_PROBES_OBJ)" "YES"
262 263 264 265 266 267 268 269 270 271 272 273
# A list of objects that do not get included in the RTS object that is created
# during the linking step. To prevent future linking errors, especially when
# using the compiler as a bootstrap compiler, we need to exclude the hook
# objects from being re-linked into the single LINKED_OBJS object file. When the
# hooks are being linked into the RTS object this will result in duplicated
# symbols causing the linker to fail (e.g. `StackOverflowHook` in RTS.o and
# hschooks.o). The excluded objects do not get relinked into the RTS object but
# get included separately so prevent linker errors.
# (see issue #15040)
rts_$1_EXCLUDED_OBJS = $$(rts_$1_C_HOOK_OBJS)
# The RTS object that gets generated to package up all of the runtime system
# with the dtrace probe code.
Ben Gamari's avatar
Ben Gamari committed
274 275
rts_$1_LINKED_OBJS = rts/dist/build/RTS.$$($1_osuf)

276
$$(rts_$1_LINKED_OBJS) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) $$(rts_$1_C_HOOK_OBJS)
Ben Gamari's avatar
Ben Gamari committed
277 278 279 280 281 282 283
	"$$(RM)" $$(RM_OPTS) $$@

	# When linking an archive the linker will only include the object files that
	# are actually needed during linking. It therefore does not include the dtrace
	# specific code for initializing the probes. By creating a single object that
	# also includes the probe object code we force the linker to include the
	# probes when linking the static runtime.
284 285 286 287 288
	#
	# The reason why we are re-linking all the objects into a single object file
	# is stated in this thread:
	# https://thr3ads.net/dtrace-discuss/2005/08/384778-Problem-with-probes-defined-in-static-libraries
	$(LD) -r -o $$(rts_$1_LINKED_OBJS) $$(rts_$1_DTRACE_OBJS) $$(filter-out $$(rts_$1_EXCLUDED_OBJS), $$(rts_$1_OBJS))
Ben Gamari's avatar
Ben Gamari committed
289
else
290
rts_$1_EXCLUDED_OBJS =
Ben Gamari's avatar
Ben Gamari committed
291 292 293
rts_$1_LINKED_OBJS = $$(rts_$1_OBJS)
endif
else
294
rts_$1_EXCLUDED_OBJS =
Ben Gamari's avatar
Ben Gamari committed
295 296 297 298 299
rts_$1_LINKED_OBJS = $$(rts_$1_OBJS)
endif


$$(rts_$1_LIB) : $$(rts_$1_LINKED_OBJS)
300
	"$$(RM)" $$(RM_OPTS) $$@
Ben Gamari's avatar
Ben Gamari committed
301

302
	echo $$(rts_$1_LINKED_OBJS) $$(rts_$1_EXCLUDED_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR_STAGE1)" \
303
		$$(AR_OPTS_STAGE1) $$(EXTRA_AR_ARGS_STAGE1) $$@
304 305

ifneq "$$(UseSystemLibFFI)" "YES"
ian@well-typed.com's avatar
ian@well-typed.com committed
306 307
$$(rts_$1_LIB) : rts/dist/build/libC$$(LIBFFI_NAME)$$($1_libsuf)
rts/dist/build/libC$$(LIBFFI_NAME)$$($1_libsuf): libffi/build/inst/lib/libffi.a
308 309 310
	cp $$< $$@
endif

311
endif
Ian Lynagh's avatar
Ian Lynagh committed
312

313 314
endif

Ian Lynagh's avatar
Ian Lynagh committed
315 316 317 318 319
endef

# And expand the above for each way:
$(foreach way,$(rts_WAYS),$(eval $(call build-rts-way,$(way))))

320
$(eval $(call distdir-opts,rts,dist,1))
321

Ian Lynagh's avatar
Ian Lynagh committed
322 323 324
#-----------------------------------------------------------------------------
# Flags for compiling every file

Simon Marlow's avatar
Simon Marlow committed
325
# We like plenty of warnings.
326 327
WARNING_OPTS += -Wall
WARNING_OPTS += -Wextra
Ian Lynagh's avatar
Ian Lynagh committed
328 329 330 331
WARNING_OPTS += -Wstrict-prototypes 
WARNING_OPTS += -Wmissing-prototypes 
WARNING_OPTS += -Wmissing-declarations
WARNING_OPTS += -Winline
Simon Marlow's avatar
Simon Marlow committed
332 333 334
WARNING_OPTS += -Wpointer-arith
WARNING_OPTS += -Wmissing-noreturn
WARNING_OPTS += -Wnested-externs
335
WARNING_OPTS += -Wredundant-decls
336
ifeq "$(GccLT46)" "NO"
337
WARNING_OPTS += -Wundef
338
endif
Simon Marlow's avatar
Simon Marlow committed
339 340 341

# These ones are hard to avoid:
#WARNING_OPTS += -Wconversion
Ian Lynagh's avatar
Ian Lynagh committed
342 343 344 345
#WARNING_OPTS += -Wbad-function-cast
#WARNING_OPTS += -Wshadow
#WARNING_OPTS += -Wcast-qual

346 347 348 349 350 351 352 353 354
# This one seems buggy on GCC 4.1.2, which is the only GCC version we 
# have that can bootstrap the SPARC build. We end up with lots of supurious
# warnings of the form "cast increases required alignment of target type".
# Some legitimate warnings can be fixed by adding an intermediate cast to
# (void*), but we get others in rts/sm/GCUtils.c concerning the gct var
# that look innocuous to me. We could enable this again once we deprecate
# support for registerised builds on this arch. -- BL 2010/02/03
# WARNING_OPTS += -Wcast-align

Ian Lynagh's avatar
Ian Lynagh committed
355
STANDARD_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS)) -Irts -Irts/dist/build
Ian Lynagh's avatar
Ian Lynagh committed
356
# COMPILING_RTS is only used when building Win32 DLL support.
357
STANDARD_OPTS += -DCOMPILING_RTS -DFS_NAMESPACE=rts
Ian Lynagh's avatar
Ian Lynagh committed
358 359 360 361 362 363 364 365

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

rts_CC_OPTS += $(WARNING_OPTS)
rts_CC_OPTS += $(STANDARD_OPTS)

366
rts_HC_OPTS += $(STANDARD_OPTS) -this-unit-id rts
Ian Lynagh's avatar
Ian Lynagh committed
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384

ifneq "$(GhcWithSMP)" "YES"
rts_CC_OPTS += -DNOSMP
rts_HC_OPTS += -optc-DNOSMP
endif

ifeq "$(UseLibFFIForAdjustors)" "YES"
rts_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
endif

# We *want* type-checking of hand-written cmm.
rts_HC_OPTS += -dcmm-lint 

# -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
# this flag we get problems in sm/Evac.c:copy() with gcc 3.4.3, the
Gabor Greif's avatar
Gabor Greif committed
385
# upd_evacuee() assignments get moved before the object copy.
Ian Lynagh's avatar
Ian Lynagh committed
386 387
rts_CC_OPTS += -fno-strict-aliasing

Simon Marlow's avatar
Simon Marlow committed
388 389
rts_CC_OPTS += -fno-common

Ian Lynagh's avatar
Ian Lynagh committed
390 391 392 393
ifeq "$(BeConservative)" "YES"
rts_CC_OPTS += -DBE_CONSERVATIVE
endif

394 395 396 397 398
# Set Windows version
ifeq "$$(TargetOS_CPP)" "mingw32"
rts_CC_OPTS += -DWINVER=$(rts_WINVER)
endif

Ian Lynagh's avatar
Ian Lynagh committed
399 400
#-----------------------------------------------------------------------------
# Flags for compiling specific files
401 402
rts/RtsMessages_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
rts/RtsUtils_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
403
rts/Trace_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
Ian Lynagh's avatar
Ian Lynagh committed
404
#
405 406 407 408
rts/RtsUtils_CC_OPTS += -DHostPlatform=\"$(HOSTPLATFORM)\"
rts/RtsUtils_CC_OPTS += -DHostArch=\"$(HostArch_CPP)\"
rts/RtsUtils_CC_OPTS += -DHostOS=\"$(HostOS_CPP)\"
rts/RtsUtils_CC_OPTS += -DHostVendor=\"$(HostVendor_CPP)\"
Ian Lynagh's avatar
Ian Lynagh committed
409
#
410 411 412 413
rts/RtsUtils_CC_OPTS += -DBuildPlatform=\"$(BUILDPLATFORM)\"
rts/RtsUtils_CC_OPTS += -DBuildArch=\"$(BuildArch_CPP)\"
rts/RtsUtils_CC_OPTS += -DBuildOS=\"$(BuildOS_CPP)\"
rts/RtsUtils_CC_OPTS += -DBuildVendor=\"$(BuildVendor_CPP)\"
Ian Lynagh's avatar
Ian Lynagh committed
414
#
415 416 417 418
rts/RtsUtils_CC_OPTS += -DTargetPlatform=\"$(TARGETPLATFORM)\"
rts/RtsUtils_CC_OPTS += -DTargetArch=\"$(TargetArch_CPP)\"
rts/RtsUtils_CC_OPTS += -DTargetOS=\"$(TargetOS_CPP)\"
rts/RtsUtils_CC_OPTS += -DTargetVendor=\"$(TargetVendor_CPP)\"
Ian Lynagh's avatar
Ian Lynagh committed
419
#
420
rts/RtsUtils_CC_OPTS += -DGhcUnregisterised=\"$(GhcUnregisterised)\"
421
rts/RtsUtils_CC_OPTS += -DTablesNextToCode=\"$(TablesNextToCode)\"
422 423
#
rts/xxhash_CC_OPTS += -O3 -ffast-math -ftree-vectorize
Ian Lynagh's avatar
Ian Lynagh committed
424

425 426 427 428 429 430 431 432 433 434
# Compile various performance-critical pieces *without* -fPIC -dynamic
# even when building a shared library.  If we don't do this, then the
# GC runs about 50% slower on x86 due to the overheads of PIC.  The
# cost of doing this is a little runtime linking and less sharing, but
# not much.
#
# On x86_64 this doesn't work, because all objects in a shared library
# must be compiled with -fPIC (since the 32-bit relocations generated
# by the default small memory can't be resolved at runtime).  So we
# only do this on i386.
435
#
436 437
# This apparently doesn't work on OS X (Darwin) nor on Solaris.
# On Darwin we get errors of the form
438 439 440 441 442 443 444
#
#  ld: absolute addressing (perhaps -mdynamic-no-pic) used in _stg_ap_0_fast from rts/dist/build/Apply.dyn_o not allowed in slidable image
#
# and lots of these warnings:
#
#  ld: warning codegen in _stg_ap_pppv_fast (offset 0x0000005E) prevents image from loading in dyld shared cache
#
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
# On Solaris we get errors like:
#
# Text relocation remains                         referenced
#     against symbol                  offset      in file
# .rodata (section)                   0x11        rts/dist/build/Apply.dyn_o
#   ...
# ld: fatal: relocations remain against allocatable but non-writable sections
# collect2: ld returned 1 exit status

ifeq "$(TargetArch_CPP)" "i386"
i386_SPEED_HACK := "YES"
ifeq "$(TargetOS_CPP)" "darwin"
i386_SPEED_HACK := "NO"
endif
ifeq "$(TargetOS_CPP)" "solaris2"
i386_SPEED_HACK := "NO"
endif
endif

464
ifeq "$(TargetArch_CPP)" "i386"
465
ifeq "$(i386_SPEED_HACK)" "YES"
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
rts/sm/Evac_HC_OPTS           += -fno-PIC
rts/sm/Evac_thr_HC_OPTS       += -fno-PIC
rts/sm/Scav_HC_OPTS           += -fno-PIC
rts/sm/Scav_thr_HC_OPTS       += -fno-PIC
rts/sm/Compact_HC_OPTS        += -fno-PIC
rts/sm/GC_HC_OPTS             += -fno-PIC

# -static is also necessary for these bits, otherwise the NCG
# -generates dynamic references:
rts/Updates_HC_OPTS += -fno-PIC -static
rts/StgMiscClosures_HC_OPTS += -fno-PIC -static
rts/PrimOps_HC_OPTS += -fno-PIC -static
rts/Apply_HC_OPTS += -fno-PIC -static
rts/dist/build/AutoApply_HC_OPTS += -fno-PIC -static
endif
481
endif
482

483 484 485 486 487 488
# add CFLAGS for libffi
ifeq "$(UseSystemLibFFI)" "YES"
LIBFFI_CFLAGS = $(addprefix -I,$(FFIIncludeDir))
else
LIBFFI_CFLAGS =
endif
489
# ffi.h triggers prototype warnings, so disable them here:
490 491 492
rts/Interpreter_CC_OPTS += -Wno-strict-prototypes $(LIBFFI_CFLAGS)
rts/Adjustor_CC_OPTS    += -Wno-strict-prototypes $(LIBFFI_CFLAGS)
rts/sm/Storage_CC_OPTS  += -Wno-strict-prototypes $(LIBFFI_CFLAGS)
493 494 495 496 497 498 499
# ffi.h triggers undefined macro warnings on PowerPC, disable those:
# this matches substrings of powerpc64le, including "powerpc" and "powerpc64"
ifneq "$(findstring $(TargetArch_CPP), powerpc64le)" ""
rts/Interpreter_CC_OPTS += -Wno-undef
rts/Adjustor_CC_OPTS    += -Wno-undef
rts/sm/Storage_CC_OPTS  += -Wno-undef
endif
Simon Marlow's avatar
Simon Marlow committed
500 501

# inlining warnings happen in Compact
502
rts/sm/Compact_CC_OPTS += -Wno-inline
Ian Lynagh's avatar
Ian Lynagh committed
503

Simon Marlow's avatar
Simon Marlow committed
504
# emits warnings about call-clobbered registers on x86_64
505
rts/StgCRun_CC_OPTS += -w
Simon Marlow's avatar
Simon Marlow committed
506

Ian Lynagh's avatar
Ian Lynagh committed
507
# On Windows:
508 509
rts/win32/ConsoleHandler_CC_OPTS += -w
rts/win32/ThrIOManager_CC_OPTS += -w
510
# The above warning suppression flags are a temporary kludge.
Ian Lynagh's avatar
Ian Lynagh committed
511 512
# While working on this module you are encouraged to remove it and fix
# any warnings in the module. See
513
#     https://gitlab.haskell.org/ghc/ghc/wikis/working-conventions#Warnings
Ian Lynagh's avatar
Ian Lynagh committed
514 515 516
# for details

# Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
517
ifneq "$(CC_CLANG_BACKEND)" "1"
518
rts/sm/Compact_CC_OPTS += -finline-limit=2500
519
endif
Ian Lynagh's avatar
Ian Lynagh committed
520 521

# -O3 helps unroll some loops (especially in copy() with a constant argument).
522
rts/sm/Evac_CC_OPTS += -funroll-loops
523
rts/sm/Evac_thr_HC_OPTS += -optc-funroll-loops
Ian Lynagh's avatar
Ian Lynagh committed
524 525


526 527 528 529 530
#-----------------------------------------------------------------------------
# Use system provided libffi

ifeq "$(UseSystemLibFFI)" "YES"

531 532 533
rts_PACKAGE_CPP_OPTS += -DFFI_INCLUDE_DIR=$(FFIIncludeDir)
rts_PACKAGE_CPP_OPTS += -DFFI_LIB_DIR=$(FFILibDir)
rts_PACKAGE_CPP_OPTS += '-DFFI_LIB='
534 535 536

else # UseSystemLibFFI==YES

537 538
rts_PACKAGE_CPP_OPTS += -DFFI_INCLUDE_DIR=
rts_PACKAGE_CPP_OPTS += -DFFI_LIB_DIR=
ian@well-typed.com's avatar
ian@well-typed.com committed
539
rts_PACKAGE_CPP_OPTS += '-DFFI_LIB="C$(LIBFFI_NAME)"'
540 541 542

endif

Ian Lynagh's avatar
Ian Lynagh committed
543 544 545 546
# -----------------------------------------------------------------------------
# dependencies

rts_WAYS_DASHED = $(subst $(space),,$(patsubst %,-%,$(strip $(rts_WAYS))))
Ian Lynagh's avatar
Ian Lynagh committed
547
rts_dist_depfile_base = rts/dist/build/.depend$(rts_WAYS_DASHED)
Ian Lynagh's avatar
Ian Lynagh committed
548

549 550 551 552 553 554
rts_dist_C_SRCS    = $(rts_C_SRCS) $(rts_thr_EXTRA_C_SRCS)
rts_dist_S_SRCS    = $(rts_S_SRCS)
rts_dist_CMM_SRCS  = $(rts_CMM_SRCS)
rts_dist_C_FILES   = $(rts_dist_C_SRCS)
rts_dist_S_FILES   = $(rts_dist_S_SRCS)
rts_dist_CMM_FILES = $(rts_dist_CMM_SRCS)
Ian Lynagh's avatar
Ian Lynagh committed
555

556 557 558 559 560 561 562
# 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 an

# TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
rts_dist_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG

563
ifeq "$(USE_DTRACE)" "YES"
564 565 566 567 568

rts_dist_MKDEPENDC_OPTS += -Irts/dist/build

endif

569
$(eval $(call dependencies,rts,dist,1))
Ian Lynagh's avatar
Ian Lynagh committed
570

571 572 573 574
$(rts_dist_depfile_c_asm) : $(DTRACEPROBES_H)
ifneq "$(UseSystemLibFFI)" "YES"
$(rts_dist_depfile_c_asm) : $(libffi_HEADERS)
endif
Ian Lynagh's avatar
Ian Lynagh committed
575

576 577 578
# -----------------------------------------------------------------------------
# compile dtrace probes if dtrace is supported

579
ifeq "$(USE_DTRACE)" "YES"
580 581 582 583

rts_CC_OPTS		+= -DDTRACE
rts_HC_OPTS		+= -DDTRACE

584 585 586 587 588
# Apple's dtrace (the only one supported by ghc at the moment) uses
# gcc as its preprocessor. If gcc isn't at /usr/bin/gcc, or we need
# to force it to use a different gcc, we need to give the path in
# the option cpppath.

589 590 591 592
ifeq "$(TargetOS_CPP)" "darwin"
# Darwin has a flag to tell dtrace which cpp to use.
# Unfortunately, this isn't supported on Solaris (See Solaris Dynamic Tracing
# Guide, Chapter 16, for the configuration variables available on Solaris)
593
DTRACE_FLAGS = -x cpppath=$(CC)
594
endif
595

596 597 598
DTRACEPROBES_SRC = rts/RtsProbes.d
$(DTRACEPROBES_H): $(DTRACEPROBES_SRC) includes/ghcplatform.h | $$(dir $$@)/.
	"$(DTRACE)" $(filter -I%,$(rts_CC_OPTS)) -C $(DTRACE_FLAGS) -h -o $@ -s $<
599 600
endif

Ian Lynagh's avatar
Ian Lynagh committed
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
# -----------------------------------------------------------------------------
# The RTS package config

# If -DDEBUG is in effect, adjust package conf accordingly..
ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
rts_PACKAGE_CPP_OPTS += -DDEBUG
endif

ifeq "$(HaveLibMingwEx)" "YES"
rts_PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
endif

$(eval $(call manual-package-config,rts))

rts/package.conf.inplace : $(includes_H_CONFIG) $(includes_H_PLATFORM)

# -----------------------------------------------------------------------------
# installing

620
RTS_INSTALL_LIBS += $(ALL_RTS_LIBS)
621
ifneq "$(UseSystemLibFFI)" "YES"
ian@well-typed.com's avatar
ian@well-typed.com committed
622 623
RTS_INSTALL_LIBS += $(wildcard rts/dist/build/lib$(LIBFFI_NAME)*$(soext)*)
RTS_INSTALL_LIBS += $(foreach w,$(filter-out %dyn,$(rts_WAYS)),rts/dist/build/libC$(LIBFFI_NAME)$($w_libsuf))
624
endif
Ian Lynagh's avatar
Ian Lynagh committed
625

626
ifneq "$(UseSystemLibFFI)" "YES"
627
install: install_libffi_headers
628
endif
629 630 631

.PHONY: install_libffi_headers
install_libffi_headers :
632 633
	$(INSTALL_DIR) "$(DESTDIR)$(ghcheaderdir)"
	$(INSTALL_HEADER) $(INSTALL_OPTS) $(libffi_HEADERS) "$(DESTDIR)$(ghcheaderdir)/"
634

Ian Lynagh's avatar
Ian Lynagh committed
635 636 637 638 639 640 641
# -----------------------------------------------------------------------------
# cleaning

$(eval $(call clean-target,rts,dist,rts/dist))

BINDIST_EXTRAS += rts/package.conf.in