From 6ba18a4639041f66160c0dff9778094a1e47ce3e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 4 Jul 2017 20:06:36 -0700 Subject: configure: deal with non-standard libffi installations. This addresses a failure to build with libffi on Arch Linux, reported by Joe Eib. * Makefile (opt/ffi.o, dbg/ffi.o): Pull LIBFFI_CFLAGS into TXR_CFLAGS for just these object files. * configure (have_pkgconfig, libffi_cflags): New variables. (gen_config_make): Create new Makefile variable, LIBFFI_CFLAGS, from libffi_cflags. New configure test to detect pkg-config. Libffi test falls back on using pkg-config to test for existence of the library and to get the cflags and ldflags. Any needed cflags end up in LIBFFI_CFLAGS and are used only when compiling ffi.c. --- Makefile | 4 ++++ configure | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Makefile b/Makefile index ae3c7fd3..50ee7cdb 100644 --- a/Makefile +++ b/Makefile @@ -257,6 +257,10 @@ y.tab.c: $(top_srcdir)parser.y # Bison-generated parser also tests for this lint define. $(call EACH_CONF,y.tab.o): TXR_CFLAGS += -Dlint +opt/ffi.o: TXR_CFLAGS += $(LIBFFI_CFLAGS) + +dbg/ffi.o: TXR_CFLAGS += $(LIBFFI_CFLAGS) + # txr.c needs to know the relative datadir path to do some sysroot # calculations. diff --git a/configure b/configure index c372c80e..235cd819 100755 --- a/configure +++ b/configure @@ -143,6 +143,8 @@ have_alloca= have_termios= have_winsize= termios_define= +have_pkgconfig= +libffi_cflags= # # Parse configuration variables @@ -710,6 +712,8 @@ CONF_LDFLAGS := $conf_ldflags REMOVE_FLAGS := $remove_flags LEX_DBG_FLAGS := $lex_dbg_flags TXR_DBG_OPTS := $txr_dbg_opts + +LIBFFI_CFLAGS := $libffi_cflags ! } @@ -2828,6 +2832,15 @@ else printf "no\n" fi +printf "Checking for pkg-config ... " + +if pkg-config --version > /dev/null 2>&1 ; then + printf "present\n" + have_pkgconfig=y +else + printf "absent\n" +fi + printf "Checking for libffi ... " cat > conftest.c <> config.h conf_ldflags="${conf_ldflags:+"$conf_ldflags "}-lffi" +elif [ -n "$have_pkgconfig" ] && pkg-config --exists libffi ; then + libffi_cflags=$(pkg-config --cflags libffi) + libffi_ldflags=$(pkg-config --libs libffi) + if conftest EXTRA_CFLAGS="$libffi_cflags" EXTRA_LDFLAGS="$libffi_ldflags" ; then + set -x + printf "yes\n" + printf "#define HAVE_LIBFFI 1\n" >> config.h + conf_ldflags="${conf_ldflags:+"$conf_ldflags "}$libffi_ldflags" + else + printf "no\n" + libffi_cflags= + fi else printf "no\n" fi -- cgit v1.2.3