# We build the RTS with stage 1
rts_dist_HC = $(GHC_STAGE1)
+rts_INSTALL_INFO = rts
+rts_VERSION = 1.0
+
# merge GhcLibWays and GhcRTSWays but strip out duplicates
rts_WAYS = $(GhcLibWays) $(filter-out $(GhcLibWays),$(GhcRTSWays))
rts_dist_WAYS = $(rts_WAYS)
-ALL_RTS_LIBS = rts/dist/build/libHSrtsmain.a \
- $(foreach way,$(rts_WAYS),rts/dist/build/libHSrts$($(way)_libsuf))
+ALL_RTS_LIBS = $(foreach way,$(rts_WAYS),rts/dist/build/libHSrts$($(way)_libsuf))
all_rts : $(ALL_RTS_LIBS)
# -----------------------------------------------------------------------------
ALL_DIRS = hooks parallel sm eventlog
-ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
+ifeq "$(HostOS_CPP)" "mingw32"
ALL_DIRS += win32
else
ALL_DIRS += posix
endif
EXCLUDED_SRCS :=
-EXCLUDED_SRCS += rts/Main.c
EXCLUDED_SRCS += rts/parallel/SysMan.c
EXCLUDED_SRCS += $(wildcard rts/Vis*.c)
# Don't compile .S files when bootstrapping a new arch
ifneq "$(PORTING_HOST)" "YES"
-ifneq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
-rts_S_SRCS += rts/AdjustorAsm.S
-else
-ifneq "$(findstring $(TargetOS_CPP), darwin)" ""
+ifneq "$(findstring $(TargetArch_CPP), i386 powerpc powerpc64)" ""
rts_S_SRCS += rts/AdjustorAsm.S
endif
endif
-endif
ifeq "$(GhcUnregisterised)" "YES"
GENAPPLY_OPTS = -u
rts_AUTO_APPLY_CMM = rts/dist/build/AutoApply.cmm
-$(rts_AUTO_APPLY_CMM): $(GENAPPLY_INPLACE)
- "$(GENAPPLY_INPLACE)" >$@
+$(rts_AUTO_APPLY_CMM): $$(genapply_INPLACE)
+ "$(genapply_INPLACE)" >$@
rts/dist/build/sm/Evac_thr.c : rts/sm/Evac.c | $$(dir $$@)/.
cp $< $@
rts/dist/build/sm/Scav_thr.c : rts/sm/Scav.c | $$(dir $$@)/.
cp $< $@
-rts_H_FILES := $(wildcard rts/*.h)
+rts_H_FILES := $(wildcard rts/*.h rts/*/*.h)
ifeq "$(USE_DTRACE)" "YES"
DTRACEPROBES_H = rts/dist/build/RtsProbes.h
endif
# collect the -l flags that we need to link the rts dyn lib.
-rts/libs.depend : $(GHC_PKG_INPLACE)
- "$(GHC_PKG_INPLACE)" field rts extra-libraries \
+rts/libs.depend : $$(ghc-pkg_INPLACE)
+ "$(ghc-pkg_INPLACE)" field rts extra-libraries \
| sed -e 's/^extra-libraries: //' -e 's/\([a-z0-9]*\)[ ]*/-l\1 /g' > $@
# These are made from rts/win32/libHS*.def which contain lists of
# all the symbols in those libraries used by the RTS.
#
-ifneq "$$(findstring dyn, $1)" ""
-ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
+ifeq "$(HostOS_CPP)" "mingw32"
ALL_RTS_DEF_LIBNAMES = base ghc-prim
ALL_RTS_DEF_LIBS = \
rts/dist/build/win32/libHSbase.dll.a \
- rts/dist/build/win32/libHSghc-prim.dll.a \
- rts/dist/build/win32/libHSffi.dll.a
+ rts/dist/build/win32/libHSghc-prim.dll.a
# -- 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)/" \
- | sed "s/@ProjectVersion@/$(ProjectVersion)/" \
+ | sed "s/@ProjectVersion@/$$(ProjectVersion)/" \
> rts/dist/build/win32/libHS$1.def
rts/dist/build/win32/libHS$1.dll.a : 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
+ifneq "$(BINDIST)" "YES"
+ifneq "$(UseSystemLibFFI)" "YES"
+rts_ffi_objs_stamp = rts/dist/ffi/stamp
+rts_ffi_objs = rts/dist/ffi/*.o
-# -- import libs for libffi
-rts/dist/build/win32/libHSffi.def : rts/win32/libHSffi.def
- cat rts/win32/libHSffi.def \
- | sed "s/@ProjectVersion@/$(ProjectVersion)/" \
- > rts/dist/build/win32/libHSffi.def
+$(rts_ffi_objs_stamp): $(libffi_STATIC_LIB) $(TOUCH_DEP) | $$(dir $$@)/.
+ cd rts/dist/ffi && $(AR) x ../../../$(libffi_STATIC_LIB)
+ "$(TOUCH_CMD)" $@
-rts/dist/build/win32/libHSffi.dll.a : rts/dist/build/win32/libHSffi.def
- "$(DLLTOOL)" -d rts/dist/build/win32/libHSffi.def \
- -l rts/dist/build/win32/libHSffi.dll.a
+# This is a little hacky. We don't know the SO version, so we only
+# depend on libffi.so, but copy libffi.so*
+rts/dist/build/libffi$(soext): libffi/build/inst/lib/libffi$(soext)
+ cp libffi/build/inst/lib/libffi$(soext)* rts/dist/build
+
+rts/dist/build/$(LIBFFI_DLL): libffi/build/inst/bin/$(LIBFFI_DLL)
+ cp $< $@
endif
endif
-
#-----------------------------------------------------------------------------
# Building one way
define build-rts-way # args: $1 = way
ifneq "$$(BINDIST)" "YES"
+rts_dist_$1_HC_OPTS := $$(GhcRtsHcOpts)
+rts_dist_$1_CC_OPTS := $$(GhcRtsCcOpts)
+
# The per-way CC_OPTS
ifneq "$$(findstring debug, $1)" ""
-rts_dist_$1_HC_OPTS =
-rts_dist_$1_CC_OPTS = -g -O0
-else
-rts_dist_$1_HC_OPTS = $$(GhcRtsHcOpts)
-rts_dist_$1_CC_OPTS = $$(GhcRtsCcOpts)
+rts_dist_$1_HC_OPTS += -O0
+rts_dist_$1_CC_OPTS += -fno-omit-frame-pointer -g -O0
+endif
+
+ifneq "$$(findstring dyn, $1)" ""
+ifeq "$$(HostOS_CPP)" "mingw32"
+rts_dist_$1_CC_OPTS += -DCOMPILING_WINDOWS_DLL
+endif
endif
ifneq "$$(findstring thr, $1)" ""
$(call distdir-way-opts,rts,dist,$1)
$(call c-suffix-rules,rts,dist,$1,YES)
$(call cmm-suffix-rules,rts,dist,$1)
-$(call hs-suffix-rules-srcdir,rts,dist,$1,.)
-# hs-suffix-rules-srcdir is needed when BootingFromHc to get the .hc rules
rts_$1_LIB_NAME = libHSrts$$($1_libsuf)
rts_$1_LIB = rts/dist/build/$$(rts_$1_LIB_NAME)
rts_$1_DTRACE_OBJS = rts/dist/build/RtsProbes.$$($1_osuf)
rts/dist/build/RtsProbes.$$($1_osuf) : $$(rts_$1_OBJS)
- $(DTRACE) -G -C -Iincludes -DDTRACE -s rts/RtsProbes.d -o \
+ $(DTRACE) -G -C $$(addprefix -I,$$(GHC_INCLUDE_DIRS)) -DDTRACE -s rts/RtsProbes.d -o \
$$@ $$(rts_$1_OBJS)
endif
endif
rts_dist_$1_CC_OPTS += -DRtsWay=\"rts_$1\"
+ifneq "$(UseSystemLibFFI)" "YES"
+rts_dist_FFI_SO = rts/dist/build/libffi$(soext)
+else
+rts_dist_FFI_SO =
+endif
+
# Making a shared library for the RTS.
ifneq "$$(findstring dyn, $1)" ""
-ifeq "$$(HOSTPLATFORM)" "i386-unknown-mingw32"
-$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/libs.depend
+ifeq "$$(HostOS_CPP)" "mingw32"
+$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/libs.depend rts/dist/build/$$(LIBFFI_DLL)
"$$(RM)" $$(RM_OPTS) $$@
"$$(rts_dist_HC)" -package-name rts -shared -dynamic -dynload deploy \
- -no-auto-link-packages `cat rts/libs.depend` $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) -o $$@
+ -no-auto-link-packages -Lrts/dist/build -l$(LIBFFI_WINDOWS_LIB) `cat rts/libs.depend` $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) -o $$@
else
-$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/libs.depend
+ifneq "$(UseSystemLibFFI)" "YES"
+LIBFFI_LIBS = -Lrts/dist/build -lffi
+ifeq "$$(TargetOS_CPP)" "linux"
+LIBFFI_LIBS += -optl-Wl,-rpath -optl-Wl,'$$$$ORIGIN'
+endif
+
+else
+# flags will be taken care of in rts/libs.depend
+LIBFFI_LIBS =
+endif
+$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/libs.depend $$(rts_dist_FFI_SO)
"$$(RM)" $$(RM_OPTS) $$@
"$$(rts_dist_HC)" -package-name rts -shared -dynamic -dynload deploy \
- -no-auto-link-packages `cat rts/libs.depend` $$(rts_$1_OBJS) \
+ -no-auto-link-packages $$(LIBFFI_LIBS) `cat rts/libs.depend` $$(rts_$1_OBJS) \
$$(rts_$1_DTRACE_OBJS) -o $$@
-ifeq "$$(darwin_HOST_OS)" "1"
- # Ensure library's install name is correct before anyone links with it.
- install_name_tool -id $(ghclibdir)/$$(rts_$1_LIB_NAME) $$@
-endif
endif
else
-$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS)
+$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) $$(rts_ffi_objs_stamp)
"$$(RM)" $$(RM_OPTS) $$@
- echo $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR_STAGE1)" \
+ echo $$(rts_ffi_objs) $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) | "$$(XARGS)" $$(XARGS_OPTS) "$$(AR_STAGE1)" \
$$(AR_OPTS_STAGE1) $$(EXTRA_AR_ARGS_STAGE1) $$@
endif
# And expand the above for each way:
$(foreach way,$(rts_WAYS),$(eval $(call build-rts-way,$(way))))
+$(eval $(call distdir-opts,rts,dist))
+
#-----------------------------------------------------------------------------
# Flags for compiling every file
# support for registerised builds on this arch. -- BL 2010/02/03
# WARNING_OPTS += -Wcast-align
-STANDARD_OPTS += -Iincludes -Irts
+STANDARD_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS)) -Irts -Irts/dist/build
# COMPILING_RTS is only used when building Win32 DLL support.
STANDARD_OPTS += -DCOMPILING_RTS
rts_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
endif
-# Mac OS X: make sure we compile for the right OS version
-rts_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
-rts_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
-rts_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
-
# We *want* type-checking of hand-written cmm.
rts_HC_OPTS += -dcmm-lint
rts/RtsMessages_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
rts/RtsUtils_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
+rts/Trace_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
#
rts/RtsUtils_CC_OPTS += -DHostPlatform=\"$(HOSTPLATFORM)\"
rts/RtsUtils_CC_OPTS += -DHostArch=\"$(HostArch_CPP)\"
rts/RtsUtils_CC_OPTS += -DGhcUnregisterised=\"$(GhcUnregisterised)\"
rts/RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=\"$(GhcEnableTablesNextToCode)\"
+ifeq "$(DYNAMIC_BY_DEFAULT)" "YES"
+rts/Linker_CC_OPTS += -DDYNAMIC_BY_DEFAULT
+endif
+
# 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
endif
endif
+# add CFLAGS for libffi
# ffi.h triggers prototype warnings, so disable them here:
-rts/Interpreter_CC_OPTS += -Wno-strict-prototypes
-rts/Adjustor_CC_OPTS += -Wno-strict-prototypes
-rts/sm/Storage_CC_OPTS += -Wno-strict-prototypes
+ifeq "$(UseSystemLibFFI)" "YES"
+LIBFFI_CFLAGS = $(addprefix -I,$(FFIIncludeDir))
+else
+LIBFFI_CFLAGS =
+endif
+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)
# inlining warnings happen in Compact
rts/sm/Compact_CC_OPTS += -Wno-inline
endif
+#-----------------------------------------------------------------------------
+# Use system provided libffi
+
+ifeq "$(UseSystemLibFFI)" "YES"
+
+rts_PACKAGE_CPP_OPTS += -DFFI_INCLUDE_DIR=$(FFIIncludeDir)
+rts_PACKAGE_CPP_OPTS += -DFFI_LIB_DIR=$(FFILibDir)
+
+else # UseSystemLibFFI==YES
+
+rts_PACKAGE_CPP_OPTS += -DFFI_INCLUDE_DIR=""
+rts_PACKAGE_CPP_OPTS += -DFFI_LIB_DIR=""
+
+endif
+
# -----------------------------------------------------------------------------
# dependencies
$(eval $(call dependencies,rts,dist,1))
-$(rts_dist_depfile_c_asm) : libffi/dist-install/build/ffi.h $(DTRACEPROBES_H)
-
-#-----------------------------------------------------------------------------
-# libffi stuff
-
-rts_CC_OPTS += -Ilibffi/build/include
-rts_HC_OPTS += -Ilibffi/build/include
-rts_HSC2HS_OPTS += -Ilibffi/build/include
-rts_LD_OPTS += -Llibffi/build/include
+$(rts_dist_depfile_c_asm) : $(DTRACEPROBES_H)
+ifneq "$(UseSystemLibFFI)" "YES"
+$(rts_dist_depfile_c_asm) : $(libffi_HEADERS)
+endif
# -----------------------------------------------------------------------------
# compile dtrace probes if dtrace is supported
endif
# -----------------------------------------------------------------------------
-# build the static lib containing the C main symbol
-
-ifneq "$(BINDIST)" "YES"
-rts/dist/build/libHSrtsmain.a : rts/dist/build/Main.o
- "$(RM)" $(RM_OPTS) $@
- "$(AR_STAGE1)" $(AR_OPTS_STAGE1) $(EXTRA_AR_ARGS_STAGE1) $@ $<
-endif
-
-# -----------------------------------------------------------------------------
# The RTS package config
# If -DDEBUG is in effect, adjust package conf accordingly..
$(eval $(call manual-package-config,rts))
-ifneq "$(BootingFromHc)" "YES"
rts/package.conf.inplace : $(includes_H_CONFIG) $(includes_H_PLATFORM)
-endif
# -----------------------------------------------------------------------------
# installing
-INSTALL_LIBS += $(ALL_RTS_LIBS)
+RTS_INSTALL_LIBS += $(ALL_RTS_LIBS)
+RTS_INSTALL_LIBS += $(wildcard rts/dist/build/libffi$(soext)*)
+RTS_INSTALL_LIBS += $(wildcard rts/dist/build/$(LIBFFI_DLL))
+
+ifneq "$(UseSystemLibFFI)" "YES"
+install: install_libffi_headers
+endif
+
+.PHONY: install_libffi_headers
+install_libffi_headers :
+ $(call INSTALL_DIR,"$(DESTDIR)$(ghcheaderdir)")
+ $(call INSTALL_HEADER,$(INSTALL_OPTS),$(libffi_HEADERS),"$(DESTDIR)$(ghcheaderdir)/")
# -----------------------------------------------------------------------------
# cleaning