lib-ffi.m4 revision 1670:ee11e7837c17
1178476Sjb# 2178476Sjb# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3178476Sjb# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4178476Sjb# 5178476Sjb# This code is free software; you can redistribute it and/or modify it 6178476Sjb# under the terms of the GNU General Public License version 2 only, as 7178476Sjb# published by the Free Software Foundation. Oracle designates this 8178476Sjb# particular file as subject to the "Classpath" exception as provided 9178476Sjb# by Oracle in the LICENSE file that accompanied this code. 10178476Sjb# 11178476Sjb# This code is distributed in the hope that it will be useful, but WITHOUT 12178476Sjb# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13178476Sjb# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14178476Sjb# version 2 for more details (a copy is included in the LICENSE file that 15178476Sjb# accompanied this code). 16178476Sjb# 17178476Sjb# You should have received a copy of the GNU General Public License version 18178476Sjb# 2 along with this work; if not, write to the Free Software Foundation, 19178476Sjb# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20178476Sjb# 21178476Sjb# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22178476Sjb# or visit www.oracle.com if you need additional information or have any 23178476Sjb# questions. 24178476Sjb# 25178476Sjb 26178476Sjb################################################################################ 27178476Sjb# Setup libffi (Foreign Function Interface) 28178476Sjb################################################################################ 29178476SjbAC_DEFUN_ONCE([LIB_SETUP_LIBFFI], 30178476Sjb[ 31178476Sjb AC_ARG_WITH(libffi, [AS_HELP_STRING([--with-libffi], 32178476Sjb [specify prefix directory for the libffi package 33178476Sjb (expecting the libraries under PATH/lib and the headers under PATH/include)])]) 34178476Sjb AC_ARG_WITH(libffi-include, [AS_HELP_STRING([--with-libffi-include], 35178476Sjb [specify directory for the libffi include files])]) 36178476Sjb AC_ARG_WITH(libffi-lib, [AS_HELP_STRING([--with-libffi-lib], 37178476Sjb [specify directory for the libffi library])]) 38178476Sjb 39178476Sjb if test "x$NEEDS_LIB_FFI" = xfalse; then 40178476Sjb if test "x${with_libffi}" != x || test "x${with_libffi_include}" != x || test "x${with_libffi_lib}" != x; then 41178476Sjb AC_MSG_WARN([libffi not used, so --with-libffi is ignored]) 42178476Sjb fi 43178476Sjb LIBFFI_CFLAGS= 44178476Sjb LIBFFI_LIBS= 45178476Sjb else 46178476Sjb LIBFFI_FOUND=no 47178476Sjb 48178476Sjb if test "x${with_libffi}" = xno || test "x${with_libffi_include}" = xno || test "x${with_libffi_lib}" = xno; then 49178476Sjb AC_MSG_ERROR([It is not possible to disable the use of libffi. Remove the --without-libffi option.]) 50178476Sjb fi 51178476Sjb 52178476Sjb if test "x${with_libffi}" != x; then 53178476Sjb LIBFFI_LIBS="-L${with_libffi}/lib -lffi" 54178476Sjb LIBFFI_CFLAGS="-I${with_libffi}/include" 55178476Sjb LIBFFI_FOUND=yes 56178476Sjb fi 57178476Sjb if test "x${with_libffi_include}" != x; then 58178476Sjb LIBFFI_CFLAGS="-I${with_libffi_include}" 59178476Sjb 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