Bug 551138 - Allow to build against system libffi. r=ted
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 22 Jul 2011 08:47:57 +0200
changeset 73217 aad6deb0dd020e92b30e52a81fd52ebd86ce6c26
parent 73216 a9e310db3ac071fb5db8c1a7b4f1c1a9efab846f
child 73218 631c9b13ec1dfb2d09a23594f9de13a484ed96a4
push idunknown
push userunknown
push dateunknown
reviewersted
bugs551138
milestone8.0a1
Bug 551138 - Allow to build against system libffi. r=ted
js/src/Makefile.in
js/src/config/autoconf.mk.in
js/src/configure.in
js/src/shell/Makefile.in
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -480,30 +480,40 @@ endif
 ifdef JS_HAS_CTYPES
 VPATH += $(srcdir)/ctypes
 
 CPPSRCS += \
     CTypes.cpp \
     Library.cpp \
     $(NULL)
 
-LOCAL_INCLUDES = \
-    -Ictypes/libffi/include \
+ifdef MOZ_NATIVE_FFI
+LOCAL_INCLUDES = $(MOZ_FFI_CFLAGS)
+else
+LOCAL_INCLUDES = -Ictypes/libffi/include
+endif
+
+LOCAL_INCLUDES += \
     -I. \
     $(NULL)
 
+
+ifdef MOZ_NATIVE_FFI
+EXTRA_DSO_LDOPTS += $(MOZ_FFI_LIBS)
+else
 ifeq ($(OS_ARCH),OS2)
 SHARED_LIBRARY_LIBS += \
     ctypes/libffi/.libs/ffi.a \
     $(NULL)
 else
 SHARED_LIBRARY_LIBS += \
     ctypes/libffi/.libs/libffi.$(LIB_SUFFIX) \
     $(NULL)
 endif
+endif
 
 endif # JS_HAS_CTYPES
 
 ifdef HAVE_DTRACE
 INSTALLED_HEADERS += \
 		$(CURDIR)/javascript-trace.h \
 		$(NULL)
 endif
@@ -582,24 +592,26 @@ export:: config/nsinstall$(HOST_BIN_SUFF
 config/nsinstall$(HOST_BIN_SUFFIX): $(srcdir)/config/nsinstall.c $(srcdir)/config/pathsub.c
 	$(MAKE) -C config/ nsinstall$(HOST_BIN_SUFFIX)
 endif
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef JS_HAS_CTYPES
+ifndef MOZ_NATIVE_FFI
 # Build libffi proper as part of the 'exports' target, so things get built
 # in the right order.
 export::
 		$(call SUBMAKE,,ctypes/libffi)
 
 distclean clean::
 		$(call SUBMAKE,$@,ctypes/libffi)
 endif
+endif
 
 # Because the SpiderMonkey can be distributed and built independently
 # of the Mozilla source tree, it contains its own copies of many of
 # the files used by the top-level Mozilla build process, from the
 # 'config' and 'build' subtrees.
 #
 # To make it simpler to keep the copies in sync, we follow the policy
 # that the SpiderMonkey copies must always be exact copies of those in
--- a/js/src/config/autoconf.mk.in
+++ b/js/src/config/autoconf.mk.in
@@ -242,16 +242,20 @@ DOXYGEN		= @DOXYGEN@
 PBBUILD_BIN	= @PBBUILD@
 SDP		= @SDP@
 NSINSTALL_BIN	= @NSINSTALL_BIN@
 
 NSPR_CONFIG	= @NSPR_CONFIG@
 NSPR_CFLAGS	= @NSPR_CFLAGS@
 NSPR_LIBS	= @NSPR_LIBS@
 
+MOZ_NATIVE_FFI	= @MOZ_NATIVE_FFI@
+MOZ_FFI_LIBS	= @MOZ_FFI_LIBS@
+MOZ_FFI_CFLAGS	= @MOZ_FFI_CFLAGS@
+
 USE_DEPENDENT_LIBS = @USE_DEPENDENT_LIBS@
 
 JS_NATIVE_EDITLINE = @JS_NATIVE_EDITLINE@
 JS_DISABLE_SHELL   = @JS_DISABLE_SHELL@
 EDITLINE_LIBS      = @EDITLINE_LIBS@
 
 # MKSHLIB_FORCE_ALL is used to force the linker to include all object
 # files present in an archive. MKSHLIB_UNFORCE_ALL reverts the linker
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -4386,16 +4386,35 @@ if test -n "$MOZ_NATIVE_NSPR"; then
                  #error PR_STATIC_ASSERT not defined
                  #endif],
                 [MOZ_NATIVE_NSPR=1],
                 AC_MSG_ERROR([system NSPR does not support PR_STATIC_ASSERT]))
     CFLAGS=$_SAVE_CFLAGS
 fi
 
 dnl ========================================================
+dnl system libffi Support
+dnl ========================================================
+MOZ_ARG_ENABLE_BOOL(system-ffi,
+[  --enable-system-ffi       Use system libffi (located with pkgconfig)],
+    MOZ_NATIVE_FFI=1 )
+
+if test -n "$MOZ_NATIVE_FFI"; then
+    # Vanilla libffi 3.0.9 needs a few patches from upcoming version 3.0.10
+    # for non-GCC compilers.
+    if test -z "$GNU_CC"; then
+        PKG_CHECK_MODULES(MOZ_FFI, libffi > 3.0.9)
+    else
+        PKG_CHECK_MODULES(MOZ_FFI, libffi >= 3.0.9)
+    fi
+fi
+
+AC_SUBST(MOZ_NATIVE_FFI)
+
+dnl ========================================================
 dnl =
 dnl = Application
 dnl =
 dnl ========================================================
 
 MOZ_ARG_HEADER(Application)
 
 ENABLE_TESTS=1
@@ -5973,17 +5992,17 @@ else
 fi
 
 # Produce the js-config script at configure time; see the comments for
 # 'js-config' in Makefile.in.
 AC_MSG_RESULT(invoking make to create js-config script)
 $GMAKE js-config
 
 # Build jsctypes if it's enabled.
-if test "$JS_HAS_CTYPES"; then
+if test "$JS_HAS_CTYPES" -a -z "$MOZ_NATIVE_FFI"; then
   # Run the libffi 'configure' script.
   ac_configure_args="--disable-shared --enable-static --disable-raw-api"
   if test "$MOZ_DEBUG"; then
     ac_configure_args="$ac_configure_args --enable-debug"
   fi
   if test "$DSO_PIC_CFLAGS"; then
     ac_configure_args="$ac_configure_args --with-pic"
   fi
--- a/js/src/shell/Makefile.in
+++ b/js/src/shell/Makefile.in
@@ -49,16 +49,19 @@ CPPSRCS		= \
   js.cpp \
   jsworkers.cpp \
   jsoptparse.cpp \
   $(NULL)
 
 DEFINES         += -DEXPORT_JS_API
 
 LIBS      = $(NSPR_LIBS) $(EDITLINE_LIBS) $(DEPTH)/$(LIB_PREFIX)js_static.$(LIB_SUFFIX)
+ifdef MOZ_NATIVE_FFI
+EXTRA_LIBS += $(MOZ_FFI_LIBS)
+endif
 
 LOCAL_INCLUDES += -I$(topsrcdir) -I..
 
 ifeq ($(OS_ARCH),Darwin)
 ifeq ($(TARGET_CPU),x86_64)
 DARWIN_EXE_LDFLAGS += -pagezero_size 10000 -image_base 100000000
 endif
 endif