From f3c3bb4441c53fb2ca4e5431e5e3dce518cf519a Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 10 Apr 2011 19:24:54 -0600 Subject: [PATCH] Use installed libffi, if any, instead of building own and add --disable-libffi to get old, always-build behavior --- src/README | 9 +++- src/configure | 84 ++++++++++++++++++++++++++++++++++++-- src/foreign/Makefile.in | 12 +++++- src/racket/Makefile.in | 8 +++- src/racket/configure.ac | 30 +++++++++++++- src/racket/gc2/Makefile.in | 13 ++++-- 6 files changed, 144 insertions(+), 12 deletions(-) diff --git a/src/README b/src/README index 6d64faec5d..cdd2855084 100644 --- a/src/README +++ b/src/README @@ -53,9 +53,9 @@ the Unix instructions below, but note the following: * To build an X11- and Gtk-based GRacket, run `configure' with the `--enable-xonx' flag. Frameworks are not used for such builds, so - --enable-shared is allowed. The `--enable-xonx' flag also affects + `--enable-shared' is allowed. The `--enable-xonx' flag also affects the Racket build, so that `system-type' reports 'unix. Pre-built - libraries are not downloaded in this more; you must have Cairo, + libraries are not downloaded in this mode; you must have Cairo, Pango, and GTk installed. * To use `--prefix' without `--enable-xonx', you must also supply @@ -171,6 +171,11 @@ Detailed instructions: env CC=cc CXX=CC [here]configure + To add an include path, be sure to use CPPFLAGS="-I..." instead + of CFLAGS="-I...". The CPPFLAGS variable controls C pre-processing, + which includes C compilation, and the Racket build normally uses + the C pre-processor directly for some parts of the build. + For cross compilation, set the compiler variables to a compiler for the target platform compiler, but also set CC_FOR_BUILD to a compiler for the host platform (for building binaries to execute diff --git a/src/configure b/src/configure index 3581163825..4cd6061670 100755 --- a/src/configure +++ b/src/configure @@ -705,6 +705,7 @@ EXE_SUFFIX SO_SUFFIX MZRT_CGC_FLAGS LIBATOM +OWN_LIBFFI LIBSFX WXLIBS WXVARIANT @@ -1331,6 +1332,7 @@ Optional Features: --enable-origtree install with original directory structure --enable-jit compile JIT support (enabled by default) --enable-foreign compile foreign support (enabled by default) + --enable-libffi use installed libffi (enabled by default) --enable-places compile places support --enable-futures compile futures support (usually enabled by default) --enable-cgcdefault use CGC (Boehm or Senora) as default build @@ -1865,6 +1867,13 @@ else enable_foreign=yes fi +# Check whether --enable-libffi was given. +if test "${enable_libffi+set}" = set; then + enableval=$enable_libffi; +else + enable_libffi=yes +fi + # Check whether --enable-places was given. if test "${enable_places+set}" = set; then @@ -2216,6 +2225,7 @@ show_explicitly_enabled "${enable_orig}" "Original install tree" show_explicitly_disabled "${enable_jit}" JIT show_explicitly_disabled "${enable_foreign}" Foreign +show_explicitly_disabled "${enable_libffi}" "Installed libffi" show_explicitly_enabled "${enable_places}" Places show_explicitly_enabled "${enable_gc2_places_testing}" "GC2 Places Testing" @@ -2273,6 +2283,8 @@ PREFLAGS="$CPPFLAGS" MZRT_CGC_FLAGS="" LIBATOM="LIBATOM_NONE" +OWN_LIBFFI="ON" + ar_libtool_no_undefined="" LIBRACKET_DEP="" @@ -6435,6 +6447,68 @@ fi { echo "$as_me:$LINENO: result: $mbsrtowcs" >&5 echo "${ECHO_T}$mbsrtowcs" >&6; } +if test "${enable_libffi}" = "yes" ; then + if test "${enable_foreign}" = "yes" ; then + { echo "$as_me:$LINENO: checking for libffi" >&5 +echo $ECHO_N "checking for libffi... $ECHO_C" >&6; } + OLD_LD_FLAGS="${LDFLAGS}" + LDFLAGS="${LDFLAGS} -lffi" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +int +main () +{ +ffi_cif cif; + ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, &ffi_type_void, NULL); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + have_libffi=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + have_libffi=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext + { echo "$as_me:$LINENO: result: $have_libffi" >&5 +echo "${ECHO_T}$have_libffi" >&6; } + if test "${have_libffi}" = "no" ; then + LDFLAGS="${OLD_LDFLAGS}" + echo "Building own libffi" + else + echo "Using installed libffi" + OWN_LIBFFI="OFF" + fi + fi +fi + if test "${enable_backtrace}" = "yes" ; then GC2OPTIONS="$GC2OPTIONS -DMZ_GC_BACKTRACE" fi @@ -9856,6 +9930,7 @@ LIBS="$LIBS $EXTRALIBS" + mk_needed_dir() @@ -9915,8 +9990,10 @@ fi FOREIGNTARGET= FOREIGN_IF_USED="FOREIGN_NOT_USED" if test -d "${srcdir}/foreign" && test "${enable_foreign}" = "yes" ; then - subdirs="$subdirs foreign/libffi" + if test "${have_libffi}" != "yes" ; then + subdirs="$subdirs foreign/libffi" + fi FOREIGNTARGET="foreign-stuff" FOREIGN_IF_USED="FOREIGN_USED" else @@ -10648,12 +10725,12 @@ EXE_SUFFIX!$EXE_SUFFIX$ac_delim SO_SUFFIX!$SO_SUFFIX$ac_delim MZRT_CGC_FLAGS!$MZRT_CGC_FLAGS$ac_delim LIBATOM!$LIBATOM$ac_delim +OWN_LIBFFI!$OWN_LIBFFI$ac_delim LIBSFX!$LIBSFX$ac_delim WXLIBS!$WXLIBS$ac_delim WXVARIANT!$WXVARIANT$ac_delim ICP!$ICP$ac_delim MRLIBINSTALL!$MRLIBINSTALL$ac_delim -LIBFINISH!$LIBFINISH$ac_delim _ACEOF if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then @@ -10695,6 +10772,7 @@ _ACEOF ac_delim='%!_!# ' for ac_last_try in false false false false false :; do cat >conf$$subs.sed <<_ACEOF +LIBFINISH!$LIBFINISH$ac_delim MAKE_GRACKET!$MAKE_GRACKET$ac_delim MAKE_PLOT!$MAKE_PLOT$ac_delim MAKE_COPYTREE!$MAKE_COPYTREE$ac_delim @@ -10730,7 +10808,7 @@ LIBOBJS!$LIBOBJS$ac_delim LTLIBOBJS!$LTLIBOBJS$ac_delim _ACEOF - if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 33; then + if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 34; then break elif $ac_last_try; then { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 diff --git a/src/foreign/Makefile.in b/src/foreign/Makefile.in index 2dab0a7fac..b252f9bb40 100644 --- a/src/foreign/Makefile.in +++ b/src/foreign/Makefile.in @@ -3,17 +3,27 @@ srcdir = @srcdir@ builddir = @builddir@ CC = @CC@ + +LIBFFI_LOCAL_INCLUDE_ON = -Ilibffi/include +LIBFFI_LOCAL_INCLUDE_OFF = CFLAGS = @CFLAGS@ @COMPFLAGS@ @PREFLAGS@ @PROFFLAGS@ @OPTIONS@ @MZOPTIONS@ \ -I$(builddir)/../racket \ -I$(srcdir)/../racket/include -I$(srcdir)/../racket/src \ - -Ilibffi/include + $(LIBFFI_LOCAL_INCLUDE_@OWN_LIBFFI@) ARFLAGS = @ARFLAGS@ +NOOP = : # compile sub-libraries & foreign.c all: $(MAKE) foreign.@LTO@ + $(MAKE) libffi_@OWN_LIBFFI@ + +libffi_ON: $(MAKE) libffi/libffi@FOREIGN_CONVENIENCE@.la +libffi_OFF: + $(NOOP) + # just foreign.c, which will generate a stub module: stub: $(MAKE) foreign.@LTO@ diff --git a/src/racket/Makefile.in b/src/racket/Makefile.in index b9b194c715..057798e714 100644 --- a/src/racket/Makefile.in +++ b/src/racket/Makefile.in @@ -34,8 +34,12 @@ MZSRC = $(srcdir)/src FOREIGN_DIR = ../foreign FOREIGN_OBJ = $(FOREIGN_DIR)/foreign.@LTO@ -FOREIGN_OBJS = $(FOREIGN_OBJ) $(FOREIGN_DIR)/libffi/src/*.@LTO@ $(FOREIGN_DIR)/libffi/src/*/*.@LTO@ -FOREIGN_LIB = $(FOREIGN_OBJ) ../foreign/libffi/libffi@FOREIGN_CONVENIENCE@.la +LIBFFI_OBJ_ON = $(FOREIGN_DIR)/libffi/src/*.@LTO@ $(FOREIGN_DIR)/libffi/src/*/*.@LTO@ +LIBFFI_OBJ_OFF = +FOREIGN_OBJS = $(FOREIGN_OBJ) $(LIBFFI_OBJ_@OWN_LIBFFI@) +LIBFFI_LIB_ON = ../foreign/libffi/libffi@FOREIGN_CONVENIENCE@.la +LIBFFI_LIB_OFF = +FOREIGN_LIB = $(FOREIGN_OBJ) $(LIBFFI_LIB_@OWN_LIBFFI@) FOREIGN_STUB_LIB = $(FOREIGN_OBJ) FOREIGN_OBJSLIB = @FOREIGN_OBJSLIB@ # Dependency always uses FOREIGN_LIB, but linker uses FOREIGN_OBJSLIB. The diff --git a/src/racket/configure.ac b/src/racket/configure.ac index 3dc0ecd959..461fe1f024 100644 --- a/src/racket/configure.ac +++ b/src/racket/configure.ac @@ -36,6 +36,7 @@ AC_ARG_ENABLE(origtree,[ --enable-origtree install with original director AC_ARG_ENABLE(jit, [ --enable-jit compile JIT support (enabled by default)], , enable_jit=yes) AC_ARG_ENABLE(foreign, [ --enable-foreign compile foreign support (enabled by default)], , enable_foreign=yes) +AC_ARG_ENABLE(libffi, [ --enable-libffi use installed libffi (enabled by default)], , enable_libffi=yes) AC_ARG_ENABLE(places, [ --enable-places compile places support]) AC_ARG_ENABLE(futures, [ --enable-futures compile futures support (usually enabled by default)]) @@ -279,6 +280,7 @@ show_explicitly_enabled "${enable_orig}" "Original install tree" show_explicitly_disabled "${enable_jit}" JIT show_explicitly_disabled "${enable_foreign}" Foreign +show_explicitly_disabled "${enable_libffi}" "Installed libffi" show_explicitly_enabled "${enable_places}" Places show_explicitly_enabled "${enable_gc2_places_testing}" "GC2 Places Testing" @@ -336,6 +338,8 @@ PREFLAGS="$CPPFLAGS" MZRT_CGC_FLAGS="" LIBATOM="LIBATOM_NONE" +OWN_LIBFFI="ON" + ar_libtool_no_undefined="" LIBRACKET_DEP="" @@ -854,6 +858,27 @@ if test "$mbsrtowcs" = "no" ; then fi AC_MSG_RESULT($mbsrtowcs) +if test "${enable_libffi}" = "yes" ; then + if test "${enable_foreign}" = "yes" ; then + AC_MSG_CHECKING([for libffi]) + OLD_LD_FLAGS="${LDFLAGS}" + LDFLAGS="${LDFLAGS} -lffi" + AC_TRY_LINK([#include ], + [ffi_cif cif; ] + [ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, &ffi_type_void, NULL);], + have_libffi=yes, + have_libffi=no) + AC_MSG_RESULT($have_libffi) + if test "${have_libffi}" = "no" ; then + LDFLAGS="${OLD_LDFLAGS}" + echo "Building own libffi" + else + echo "Using installed libffi" + OWN_LIBFFI="OFF" + fi + fi +fi + if test "${enable_backtrace}" = "yes" ; then GC2OPTIONS="$GC2OPTIONS -DMZ_GC_BACKTRACE" fi @@ -1181,6 +1206,7 @@ AC_SUBST(EXE_SUFFIX) AC_SUBST(SO_SUFFIX) AC_SUBST(MZRT_CGC_FLAGS) AC_SUBST(LIBATOM) +AC_SUBST(OWN_LIBFFI) AC_SUBST(LIBSFX) AC_SUBST(WXLIBS) @@ -1255,7 +1281,9 @@ fi FOREIGNTARGET= FOREIGN_IF_USED="FOREIGN_NOT_USED" if test -d "${srcdir}/foreign" && test "${enable_foreign}" = "yes" ; then - AC_CONFIG_SUBDIRS( foreign/libffi ) + if test "${have_libffi}" != "yes" ; then + AC_CONFIG_SUBDIRS( foreign/libffi ) + fi FOREIGNTARGET="foreign-stuff" FOREIGN_IF_USED="FOREIGN_USED" else diff --git a/src/racket/gc2/Makefile.in b/src/racket/gc2/Makefile.in index e2931b7d83..5be5eec302 100644 --- a/src/racket/gc2/Makefile.in +++ b/src/racket/gc2/Makefile.in @@ -24,6 +24,9 @@ CPPFLAGS = -I$(builddir)/.. -I$(srcdir)/../include $(MOST_CPPFLAGS) CFLAGS = -I$(builddir)/.. -I$(srcdir)/../include @CFLAGS@ $(MOST_CPPFLAGS) @COMPFLAGS@ @PROFFLAGS@ LIBS = @LIBS@ +LIBFFI_INCLUDE_ON = -I../../foreign/libffi/include +LIBFFI_INCLUDE_OFF = + ARLIBFLAGS = @LDFLAGS@ $(LIBS) DEF_COLLECTS_DIR = +D INITIAL_COLLECTS_DIRECTORY='"'"`cd $(srcdir)/../../../collects; pwd`"'"' @@ -260,7 +263,7 @@ $(XSRCDIR)/type.c: ../src/type.@LTO@ $(XFORMDEP) $(XSRCDIR)/vector.c: ../src/vector.@LTO@ $(XFORMDEP) $(XFORM) $(XSRCDIR)/vector.c $(SRCDIR)/vector.c $(XSRCDIR)/foreign.c: ../../foreign/foreign.@LTO@ $(XFORMDEP) - $(XFORM_SETUP) --cpp "$(CPP) $(CPPFLAGS) -I../../foreign/libffi/include -I${SRCDIR}/../../racket/src" -o $(XSRCDIR)/foreign.c $(SRCDIR)/../../foreign/foreign.c + $(XFORM_SETUP) --cpp "$(CPP) $(CPPFLAGS) $(LIBFFI_INCLUDE_@OWN_LIBFFI@) -I${SRCDIR}/../../racket/src" -o $(XSRCDIR)/foreign.c $(SRCDIR)/../../foreign/foreign.c $(XSRCDIR)/main.c: ../main.@LTO@ $(XFORMDEP) $(XFORM_NOPRECOMP) $(XSRCDIR)/main.c $(DEF_COLLECTS_DIR) $(srcdir)/../main.c @@ -407,8 +410,12 @@ gc2.@LTO@: \ $(srcdir)/weak.c $(CC) $(CFLAGS) -I$(builddir)/.. -c $(srcdir)/gc2.c -o gc2.@LTO@ -FOREIGN_OBJS = ../../foreign/libffi/src/*.@LTO@ ../../foreign/libffi/src/*/*.@LTO@ -FOREIGN_LIB = ../../foreign/libffi/libffi@FOREIGN_CONVENIENCE@.la +FOREIGN_OBJS_ON = ../../foreign/libffi/src/*.@LTO@ ../../foreign/libffi/src/*/*.@LTO@ +FOREIGN_LIB_ON = ../../foreign/libffi/libffi@FOREIGN_CONVENIENCE@.la +FOREIGN_OBJS_OFF = +FOREIGN_LIB_OFF = +FOREIGN_OBJS = $(FOREIGN_OBJS_@OWN_LIBFFI@) +FOREIGN_LIB = $(FOREIGN_LIB_@OWN_LIBFFI@) FOREIGN_OBJSLIB = @FOREIGN_OBJSLIB@ FOREIGN_USED_LIB = $(FOREIGN_OBJ) $(FOREIGN_LIB)