lib-ffi.m4 revision 1670:ee11e7837c17
1# 2# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4# 5# This code is free software; you can redistribute it and/or modify it 6# under the terms of the GNU General Public License version 2 only, as 7# published by the Free Software Foundation. Oracle designates this 8# particular file as subject to the "Classpath" exception as provided 9# by Oracle in the LICENSE file that accompanied this code. 10# 11# This code is distributed in the hope that it will be useful, but WITHOUT 12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14# version 2 for more details (a copy is included in the LICENSE file that 15# accompanied this code). 16# 17# You should have received a copy of the GNU General Public License version 18# 2 along with this work; if not, write to the Free Software Foundation, 19# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20# 21# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22# or visit www.oracle.com if you need additional information or have any 23# questions. 24# 25 26################################################################################ 27# Setup libffi (Foreign Function Interface) 28################################################################################ 29AC_DEFUN_ONCE([LIB_SETUP_LIBFFI], 30[ 31 AC_ARG_WITH(libffi, [AS_HELP_STRING([--with-libffi], 32 [specify prefix directory for the libffi package 33 (expecting the libraries under PATH/lib and the headers under PATH/include)])]) 34 AC_ARG_WITH(libffi-include, [AS_HELP_STRING([--with-libffi-include], 35 [specify directory for the libffi include files])]) 36 AC_ARG_WITH(libffi-lib, [AS_HELP_STRING([--with-libffi-lib], 37 [specify directory for the libffi library])]) 38 39 if test "x$NEEDS_LIB_FFI" = xfalse; then 40 if test "x${with_libffi}" != x || test "x${with_libffi_include}" != x || test "x${with_libffi_lib}" != x; then 41 AC_MSG_WARN([libffi not used, so --with-libffi is ignored]) 42 fi 43 LIBFFI_CFLAGS= 44 LIBFFI_LIBS= 45 else 46 LIBFFI_FOUND=no 47 48 if test "x${with_libffi}" = xno || test "x${with_libffi_include}" = xno || test "x${with_libffi_lib}" = xno; then 49 AC_MSG_ERROR([It is not possible to disable the use of libffi. Remove the --without-libffi option.]) 50 fi 51 52 if test "x${with_libffi}" != x; then 53 LIBFFI_LIBS="-L${with_libffi}/lib -lffi" 54 LIBFFI_CFLAGS="-I${with_libffi}/include" 55 LIBFFI_FOUND=yes 56 fi 57 if test "x${with_libffi_include}" != x; then 58 LIBFFI_CFLAGS="-I${with_libffi_include}" 59 LIBFFI_FOUND=yes 60 fi 61 if test "x${with_libffi_lib}" != x; then 62 LIBFFI_LIBS="-L${with_libffi_lib} -lffi" 63 LIBFFI_FOUND=yes 64 fi 65 # Do not try pkg-config if we have a sysroot set. 66 if test "x$SYSROOT" = x; then 67 if test "x$LIBFFI_FOUND" = xno; then 68 # Figure out LIBFFI_CFLAGS and LIBFFI_LIBS 69 PKG_CHECK_MODULES([LIBFFI], [libffi], [LIBFFI_FOUND=yes], [LIBFFI_FOUND=no]) 70 fi 71 fi 72 if test "x$LIBFFI_FOUND" = xno; then 73 AC_CHECK_HEADERS([ffi.h], 74 [ 75 LIBFFI_FOUND=yes 76 LIBFFI_CFLAGS= 77 LIBFFI_LIBS=-lffi 78 ], 79 [LIBFFI_FOUND=no] 80 ) 81 fi 82 if test "x$LIBFFI_FOUND" = xno; then 83 HELP_MSG_MISSING_DEPENDENCY([ffi]) 84 AC_MSG_ERROR([Could not find libffi! $HELP_MSG]) 85 fi 86 87 AC_MSG_CHECKING([if libffi works]) 88 AC_LANG_PUSH(C) 89 OLD_CFLAGS="$CFLAGS" 90 CFLAGS="$CFLAGS $LIBFFI_CFLAGS" 91 OLD_LIBS="$LIBS" 92 LIBS="$LIBS $LIBFFI_LIBS" 93 AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <ffi.h>], 94 [ 95 ffi_call(NULL, NULL, NULL, NULL); 96 return 0; 97 ])], 98 [LIBFFI_WORKS=yes], 99 [LIBFFI_WORKS=no] 100 ) 101 CFLAGS="$OLD_CFLAGS" 102 LIBS="$OLD_LIBS" 103 AC_LANG_POP(C) 104 AC_MSG_RESULT([$LIBFFI_WORKS]) 105 106 if test "x$LIBFFI_WORKS" = xno; then 107 HELP_MSG_MISSING_DEPENDENCY([ffi]) 108 AC_MSG_ERROR([Found libffi but could not link and compile with it. $HELP_MSG]) 109 fi 110 fi 111 112 AC_SUBST(LIBFFI_CFLAGS) 113 AC_SUBST(LIBFFI_LIBS) 114]) 115