Commit 3005e909 authored by ian@well-typed.com's avatar ian@well-typed.com

Add configure option to use system provided libffi; fixes #5743

Based on patch from Peter Trommler:

    From 293495d40f62e691520331a41c6d85d82e120169 Mon Sep 17 00:00:00 2001
    From: Peter Trommler <ptrommler@acm.org>
    Date: Sun, 21 Oct 2012 18:47:01 +0200
    Subject: [PATCH] Add configure option to use system provided libffi This
     fixes track # 5743 and #4496.
parent bd9e0299
...@@ -86,6 +86,61 @@ AC_ARG_WITH([ghc], ...@@ -86,6 +86,61 @@ AC_ARG_WITH([ghc],
fi fi
WithGhc="$GHC"]) WithGhc="$GHC"])
# system libffi
AC_ARG_WITH([system-libffi],
[AC_HELP_STRING([--with-system-libffi],
[Use system provided libffi for RTS [default=no]])
])
AS_IF([test "x$with_system_libffi" = "xyes"],
[UseSystemLibFFI="YES"], [UseSystemLibFFI="NO"]
)
AC_SUBST(UseSystemLibFFI)
AC_ARG_WITH([ffi-includes],
[AC_HELP_STRING([--with-ffi-includes=ARG]
[Find includes for libffi in ARG [default=system default]])
],
[
if test "x$UseSystemLibFFI" != "xYES"; then
AC_MSG_WARN([--with-ffi-includes will be ignored, --with-system-libffi not set])
else
FFIIncludeDir="$withval"
LIBFFI_CFLAGS="-I $withval"
fi
])
AC_SUBST(FFIIncludeDir)
AC_ARG_WITH([ffi-libraries],
[AC_HELP_STRING([--with-ffi-libraries=ARG]
[Find libffi in ARG [default=system default]])
],
[
if test "x$UseSystemLibFFI" != "xYES"; then
AC_MSG_WARN([--with-ffi-libraries will be ignored, --with-system-libffi not set])
else
FFILibDir="$withval" LIBFFI_LDFLAGS="-L$withval"
fi
])
AC_SUBST(FFILibDir)
AS_IF([test "$UseSystemLibFFI" = "YES"], [
CFLAGS2="$CFLAGS"
CFLAGS="$LIBFFI_CFLAGS $CFLAGS"
LDFLAGS2="$LDFLAGS"
LDFLAGS="$LIBFFI_LDFLAGS $LDFLAGS"
AC_CHECK_LIB(ffi, ffi_call,
[AC_CHECK_HEADERS([ffi.h], [break], [])
AC_DEFINE([HAVE_LIBFFI], [1], [Define to 1 if you have libffi.])],
[UseSystemLibFFI="NO"])
CFLAGS="$CFLAGS2"
LDFLAGS="$LDFLAGS2"
])
dnl ** Tell the make system which OS we are using dnl ** Tell the make system which OS we are using
dnl $OSTYPE is set by the operating system to "msys" or "cygwin" or something dnl $OSTYPE is set by the operating system to "msys" or "cygwin" or something
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
# * For each package: # * For each package:
# o configure, generate package-data.mk and inplace-pkg-info # o configure, generate package-data.mk and inplace-pkg-info
# o register each package into inplace/lib/package.conf # o register each package into inplace/lib/package.conf
# * build libffi # * build libffi (if not disabled by --with-system-libffi)
# * With bootstrapping compiler: # * With bootstrapping compiler:
# o Build libraries/{filepath,hpc,Cabal} # o Build libraries/{filepath,hpc,Cabal}
# o Build compiler (stage 1) # o Build compiler (stage 1)
...@@ -618,12 +618,18 @@ else ...@@ -618,12 +618,18 @@ else
MAYBE_GHCI=driver/ghci MAYBE_GHCI=driver/ghci
endif endif
ifeq "$(UseSystemLibFFI)" "YES"
MAYBE_LIBFFI=
else
MAYBE_LIBFFI=libffi
endif
BUILD_DIRS += \ BUILD_DIRS += \
driver \ driver \
$(MAYBE_GHCI) \ $(MAYBE_GHCI) \
driver/ghc \ driver/ghc \
driver/haddock \ driver/haddock \
libffi \ $(MAYBE_LIBFFI) \
includes \ includes \
rts rts
...@@ -1044,6 +1050,7 @@ unix-binary-dist-prep: ...@@ -1044,6 +1050,7 @@ unix-binary-dist-prep:
echo "BUILD_DOCBOOK_PDF = $(BUILD_DOCBOOK_PDF)" >> $(BIN_DIST_MK) echo "BUILD_DOCBOOK_PDF = $(BUILD_DOCBOOK_PDF)" >> $(BIN_DIST_MK)
echo "BUILD_MAN = $(BUILD_MAN)" >> $(BIN_DIST_MK) echo "BUILD_MAN = $(BUILD_MAN)" >> $(BIN_DIST_MK)
echo "GHC_CABAL_INPLACE = utils/ghc-cabal/dist-install/build/tmp/ghc-cabal-bindist" >> $(BIN_DIST_MK) echo "GHC_CABAL_INPLACE = utils/ghc-cabal/dist-install/build/tmp/ghc-cabal-bindist" >> $(BIN_DIST_MK)
echo "UseSystemLibFFI = $(UseSystemLibFFI)" >> $(BIN_DIST_MK)
cd $(BIN_DIST_PREP_DIR) && autoreconf cd $(BIN_DIST_PREP_DIR) && autoreconf
$(call removeFiles,$(BIN_DIST_PREP_TAR)) $(call removeFiles,$(BIN_DIST_PREP_TAR))
# h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source # h means "follow symlinks", e.g. if aclocal.m4 is a symlink to a source
......
...@@ -380,6 +380,13 @@ GhcRtsWithPapi = NO ...@@ -380,6 +380,13 @@ GhcRtsWithPapi = NO
PapiLibDir= PapiLibDir=
PapiIncludeDir= PapiIncludeDir=
# Configuration for libffi
UseSystemLibFFI=@UseSystemLibFFI@
# Flags to go into package.conf for rts
FFILibDir=@FFILibDir@
FFIIncludeDir=@FFIIncludeDir@
################################################################################ ################################################################################
# #
# Paths (see paths.mk) # Paths (see paths.mk)
......
...@@ -107,8 +107,10 @@ $(foreach lib,$(ALL_RTS_DEF_LIBNAMES),$(eval $(call make-importlib-def,$(lib)))) ...@@ -107,8 +107,10 @@ $(foreach lib,$(ALL_RTS_DEF_LIBNAMES),$(eval $(call make-importlib-def,$(lib))))
endif endif
ifneq "$(BINDIST)" "YES" ifneq "$(BINDIST)" "YES"
ifneq "$(UseSystemLibFFI)" "YES"
rts_ffi_objs_stamp = rts/dist/ffi/stamp rts_ffi_objs_stamp = rts/dist/ffi/stamp
rts_ffi_objs = rts/dist/ffi/*.o rts_ffi_objs = rts/dist/ffi/*.o
$(rts_ffi_objs_stamp): $(libffi_STATIC_LIB) $(TOUCH_DEP) | $$(dir $$@)/. $(rts_ffi_objs_stamp): $(libffi_STATIC_LIB) $(TOUCH_DEP) | $$(dir $$@)/.
cd rts/dist/ffi && $(AR) x ../../../$(libffi_STATIC_LIB) cd rts/dist/ffi && $(AR) x ../../../$(libffi_STATIC_LIB)
"$(TOUCH_CMD)" $@ "$(TOUCH_CMD)" $@
...@@ -121,6 +123,7 @@ rts/dist/build/libffi$(soext): libffi/build/inst/lib/libffi$(soext) ...@@ -121,6 +123,7 @@ rts/dist/build/libffi$(soext): libffi/build/inst/lib/libffi$(soext)
rts/dist/build/$(LIBFFI_DLL): libffi/build/inst/bin/$(LIBFFI_DLL) rts/dist/build/$(LIBFFI_DLL): libffi/build/inst/bin/$(LIBFFI_DLL)
cp $< $@ cp $< $@
endif endif
endif
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Building one way # Building one way
...@@ -177,6 +180,12 @@ endif ...@@ -177,6 +180,12 @@ endif
rts_dist_$1_CC_OPTS += -DRtsWay=\"rts_$1\" 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. # Making a shared library for the RTS.
ifneq "$$(findstring dyn, $1)" "" ifneq "$$(findstring dyn, $1)" ""
ifeq "$$(HostOS_CPP)" "mingw32" ifeq "$$(HostOS_CPP)" "mingw32"
...@@ -185,10 +194,10 @@ $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/libs.depend rts/dist/b ...@@ -185,10 +194,10 @@ $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/libs.depend rts/dist/b
"$$(rts_dist_HC)" -package-name rts -shared -dynamic -dynload deploy \ "$$(rts_dist_HC)" -package-name rts -shared -dynamic -dynload deploy \
-no-auto-link-packages -Lrts/dist/build -l$(LIBFFI_WINDOWS_LIB) `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 else
$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/libs.depend rts/dist/build/libffi$$(soext) $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/libs.depend $$(rts_dist_FFI_SO)
"$$(RM)" $$(RM_OPTS) $$@ "$$(RM)" $$(RM_OPTS) $$@
"$$(rts_dist_HC)" -package-name rts -shared -dynamic -dynload deploy \ "$$(rts_dist_HC)" -package-name rts -shared -dynamic -dynload deploy \
-no-auto-link-packages -Lrts/dist/build -lffi `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 $$@ $$(rts_$1_DTRACE_OBJS) -o $$@
endif endif
else else
...@@ -377,10 +386,16 @@ rts/dist/build/AutoApply_HC_OPTS += -fno-PIC -static ...@@ -377,10 +386,16 @@ rts/dist/build/AutoApply_HC_OPTS += -fno-PIC -static
endif endif
endif endif
# add CFLAGS for libffi
# ffi.h triggers prototype warnings, so disable them here: # ffi.h triggers prototype warnings, so disable them here:
rts/Interpreter_CC_OPTS += -Wno-strict-prototypes ifeq "$(UseSystemLibFFI)" "YES"
rts/Adjustor_CC_OPTS += -Wno-strict-prototypes LIBFFI_CFLAGS = $(addprefix -I,$(FFIIncludeDir))
rts/sm/Storage_CC_OPTS += -Wno-strict-prototypes 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 # inlining warnings happen in Compact
rts/sm/Compact_CC_OPTS += -Wno-inline rts/sm/Compact_CC_OPTS += -Wno-inline
...@@ -438,6 +453,21 @@ rts_PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR="" ...@@ -438,6 +453,21 @@ rts_PACKAGE_CPP_OPTS += -DPAPI_LIB_DIR=""
endif 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 # dependencies
...@@ -515,7 +545,9 @@ RTS_INSTALL_LIBS += $(ALL_RTS_LIBS) ...@@ -515,7 +545,9 @@ RTS_INSTALL_LIBS += $(ALL_RTS_LIBS)
RTS_INSTALL_LIBS += $(wildcard rts/dist/build/libffi$(soext)*) RTS_INSTALL_LIBS += $(wildcard rts/dist/build/libffi$(soext)*)
RTS_INSTALL_LIBS += $(wildcard rts/dist/build/$(LIBFFI_DLL)) RTS_INSTALL_LIBS += $(wildcard rts/dist/build/$(LIBFFI_DLL))
ifneq "$(UseSystemLibFFI)" "YES"
install: install_libffi_headers install: install_libffi_headers
endif
.PHONY: install_libffi_headers .PHONY: install_libffi_headers
install_libffi_headers : install_libffi_headers :
......
...@@ -33,6 +33,9 @@ extra-libraries: ...@@ -33,6 +33,9 @@ extra-libraries:
#ifdef HAVE_LIBDL #ifdef HAVE_LIBDL
, "dl" , "dl"
#endif #endif
#ifdef HAVE_LIBFFI
, "ffi"
#endif
#ifdef mingw32_HOST_OS #ifdef mingw32_HOST_OS
,"wsock32" /* for the linker */ ,"wsock32" /* for the linker */
,"gdi32" /* for the linker */ ,"gdi32" /* for the linker */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment