lib-ffi.m4 revision 1712:c8470ff83abe
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}" != xno) || \ 41 (test "x${with_libffi_include}" != x && test "x${with_libffi_include}" != xno) || \ 42 (test "x${with_libffi_lib}" != x && test "x${with_libffi_lib}" != xno); then 43 AC_MSG_WARN([[libffi not used, so --with-libffi[-*] is ignored]]) 44 fi 45 LIBFFI_CFLAGS= 46 LIBFFI_LIBS= 47 else 48 LIBFFI_FOUND=no 49 50 if test "x${with_libffi}" = xno || test "x${with_libffi_include}" = xno || test "x${with_libffi_lib}" = xno; then 51 AC_MSG_ERROR([It is not possible to disable the use of libffi. Remove the --without-libffi option.]) 52 fi 53 54 if test "x${with_libffi}" != x; then 55 LIBFFI_LIBS="-L${with_libffi}/lib -lffi" 56 LIBFFI_CFLAGS="-I${with_libffi}/include" 57 LIBFFI_FOUND=yes 58 fi 59 if test "x${with_libffi_include}" != x; then 60 LIBFFI_CFLAGS="-I${with_libffi_include}" 61 LIBFFI_FOUND=yes 62 fi 63 if test "x${with_libffi_lib}" != x; then 64 LIBFFI_LIBS="-L${with_libffi_lib} -lffi" 65 LIBFFI_FOUND=yes 66 fi 67 # Do not try pkg-config if we have a sysroot set. 68 if test "x$SYSROOT" = x; then 69 if test "x$LIBFFI_FOUND" = xno; then 70 # Figure out LIBFFI_CFLAGS and LIBFFI_LIBS 71 PKG_CHECK_MODULES([LIBFFI], [libffi], [LIBFFI_FOUND=yes], [LIBFFI_FOUND=no]) 72 fi 73 fi 74 if test "x$LIBFFI_FOUND" = xno; then 75 AC_CHECK_HEADERS([ffi.h], 76 [ 77 LIBFFI_FOUND=yes 78 LIBFFI_CFLAGS= 79 LIBFFI_LIBS=-lffi 80 ], 81 [LIBFFI_FOUND=no] 82 ) 83 fi 84 if test "x$LIBFFI_FOUND" = xno; then 85 HELP_MSG_MISSING_DEPENDENCY([ffi]) 86 AC_MSG_ERROR([Could not find libffi! $HELP_MSG]) 87 fi 88 89 AC_MSG_CHECKING([if libffi works]) 90 AC_LANG_PUSH(C) 91 OLD_CFLAGS="$CFLAGS" 92 CFLAGS="$CFLAGS $LIBFFI_CFLAGS" 93 OLD_LIBS="$LIBS" 94 LIBS="$LIBS $LIBFFI_LIBS" 95 AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <ffi.h>], 96 [ 97 ffi_call(NULL, NULL, NULL, NULL); 98 return 0; 99 ])], 100 [LIBFFI_WORKS=yes], 101 [LIBFFI_WORKS=no] 102 ) 103 CFLAGS="$OLD_CFLAGS" 104 LIBS="$OLD_LIBS" 105 AC_LANG_POP(C) 106 AC_MSG_RESULT([$LIBFFI_WORKS]) 107 108 if test "x$LIBFFI_WORKS" = xno; then 109 HELP_MSG_MISSING_DEPENDENCY([ffi]) 110 AC_MSG_ERROR([Found libffi but could not link and compile with it. $HELP_MSG]) 111 fi 112 fi 113 114 AC_SUBST(LIBFFI_CFLAGS) 115 AC_SUBST(LIBFFI_LIBS) 116]) 117