jdk

Форк
0
/
lib-ffi.m4 
217 строк · 8.2 Кб
1
#
2
# Copyright (c) 2015, 2023, 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
################################################################################
29
AC_DEFUN_ONCE([LIB_SETUP_LIBFFI],
30
[
31
  UTIL_ARG_ENABLE(NAME: libffi-bundling, DEFAULT: false,
32
      RESULT: ENABLE_LIBFFI_BUNDLING,
33
      DESC: [enable bundling of libffi.so to make the built JDK runnable on more systems])
34

35
  AC_ARG_WITH(libffi, [AS_HELP_STRING([--with-libffi],
36
      [specify prefix directory for the libffi package
37
      (expecting the libraries under PATH/lib and the headers under PATH/include)])])
38
  AC_ARG_WITH(libffi-include, [AS_HELP_STRING([--with-libffi-include],
39
      [specify directory for the libffi include files])])
40
  AC_ARG_WITH(libffi-lib, [AS_HELP_STRING([--with-libffi-lib],
41
      [specify directory for the libffi library])])
42

43
  if test "x$NEEDS_LIB_FFI" = xfalse; then
44
    if (test "x${with_libffi}" != x && test "x${with_libffi}" != xno) || \
45
        (test "x${with_libffi_include}" != x && test "x${with_libffi_include}" != xno) || \
46
        (test "x${with_libffi_lib}" != x && test "x${with_libffi_lib}" != xno); then
47
      AC_MSG_WARN([[libffi not used, so --with-libffi[-*] is ignored]])
48
    fi
49
    LIBFFI_CFLAGS=
50
    LIBFFI_LIBS=
51
  else
52
    LIBFFI_FOUND=no
53

54
    if test "x${with_libffi}" = xno || test "x${with_libffi_include}" = xno || test "x${with_libffi_lib}" = xno; then
55
      AC_MSG_ERROR([It is not possible to disable the use of libffi. Remove the --without-libffi option.])
56
    fi
57

58
    if test "x${with_libffi}" != x; then
59
      LIBFFI_LIB_PATH="${with_libffi}/lib"
60
      if test "x${OPENJDK_TARGET_OS}" != "xwindows"; then
61
        LIBFFI_LIBS="-L${with_libffi}/lib -lffi"
62
      else
63
        LIBFFI_LIBS="${with_libffi}/lib/libffi.lib"
64
      fi
65
      LIBFFI_CFLAGS="-I${with_libffi}/include"
66
      LIBFFI_FOUND=yes
67
    fi
68
    if test "x${with_libffi_include}" != x; then
69
      LIBFFI_CFLAGS="-I${with_libffi_include}"
70
      LIBFFI_FOUND=yes
71
    fi
72
    if test "x${with_libffi_lib}" != x; then
73
      LIBFFI_LIB_PATH="${with_libffi_lib}"
74
      if test "x${OPENJDK_TARGET_OS}" != "xwindows"; then
75
        LIBFFI_LIBS="-L${with_libffi_lib} -lffi"
76
      else
77
        LIBFFI_LIBS="${with_libffi_lib}/libffi.lib"
78
      fi
79
      LIBFFI_FOUND=yes
80
    fi
81
    # Do not try pkg-config if we have a sysroot set.
82
    if test "x$SYSROOT" = x; then
83
      if test "x$LIBFFI_FOUND" = xno; then
84
        # Figure out LIBFFI_CFLAGS and LIBFFI_LIBS
85
        PKG_CHECK_MODULES([LIBFFI], [libffi], [LIBFFI_FOUND=yes], [LIBFFI_FOUND=no])
86
      fi
87
    fi
88
    if test "x$LIBFFI_FOUND" = xno; then
89
      AC_CHECK_HEADERS([ffi.h],
90
          [
91
            LIBFFI_FOUND=yes
92
            LIBFFI_CFLAGS=
93
            LIBFFI_LIBS=-lffi
94
          ],
95
          [LIBFFI_FOUND=no]
96
      )
97
    fi
98
    # on macos we need a special case for system's libffi as
99
    # headers are located only in sdk in $SYSROOT and in ffi subfolder
100
    if test "x$LIBFFI_FOUND" = xno; then
101
      if test "x$SYSROOT" != "x"; then
102
        AC_CHECK_HEADER([$SYSROOT/usr/include/ffi/ffi.h],
103
            [
104
              LIBFFI_FOUND=yes
105
              LIBFFI_CFLAGS="-I${SYSROOT}/usr/include/ffi"
106
              LIBFFI_LIBS=-lffi
107
            ],
108
            [LIBFFI_FOUND=no]
109
        )
110
      fi
111
    fi
112
    if test "x$LIBFFI_FOUND" = xno; then
113
      HELP_MSG_MISSING_DEPENDENCY([ffi])
114
      AC_MSG_ERROR([Could not find libffi! $HELP_MSG])
115
    fi
116

117
    AC_LANG_PUSH(C)
118
    OLD_CFLAGS="$CFLAGS"
119
    CFLAGS="$CFLAGS $LIBFFI_CFLAGS"
120
    OLD_LIBS="$LIBS"
121
    LIBS="$LIBS $LIBFFI_LIBS"
122

123
    AC_MSG_CHECKING([if libffi works])
124
    AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <ffi.h>],
125
        [
126
          ffi_call(NULL, NULL, NULL, NULL);
127
          return 0;
128
        ])],
129
        [LIBFFI_WORKS=yes],
130
        [LIBFFI_WORKS=no]
131
    )
132
    AC_MSG_RESULT([$LIBFFI_WORKS])
133

134
    if test "x$LIBFFI_WORKS" = xno; then
135
      HELP_MSG_MISSING_DEPENDENCY([ffi])
136
      AC_MSG_ERROR([Found libffi but could not link and compile with it. $HELP_MSG])
137
    fi
138

139
    # Check if FFI_GO_CLOSURES is properly defined. On some distributions, notably MacOS AArch64,
140
    # ffitarget.h (included from ffi.h) does not explicitly define FFI_GO_CLOSURES. This makes the
141
    # further include of ffi.h trigger the "FFI_GO_CLOSURES is undefined" warning, which fails
142
    # the build when warnings are fatal.
143
    AC_MSG_CHECKING([for FFI_GO_CLOSURES definition])
144
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
145
      #include <ffi.h>
146
      #ifndef FFI_GO_CLOSURES
147
      #error "FFI_GO_CLOSURES is not defined"
148
      #endif
149
      ][])],
150
      [
151
        AC_MSG_RESULT([yes])
152
      ],
153
      [
154
        AC_MSG_RESULT([no, defining])
155
        LIBFFI_CFLAGS="$LIBFFI_CFLAGS -DFFI_GO_CLOSURES=0"
156
      ]
157
    )
158

159
    CFLAGS="$OLD_CFLAGS"
160
    LIBS="$OLD_LIBS"
161
    AC_LANG_POP(C)
162

163
    # Find the libffi.so.X to bundle
164
    if test "x${ENABLE_LIBFFI_BUNDLING}" = "xtrue"; then
165
      if test "x${OPENJDK_TARGET_OS}" = "xmacosx"; then
166
        LIBFFI_LIB_FILE_NAME=libffi.?.dylib
167
      elif test "x${OPENJDK_TARGET_OS}" = "xwindows"; then
168
        LIBFFI_LIB_FILE_NAME=libffi.dll
169
      else
170
        LIBFFI_LIB_FILE_NAME=libffi.so.?
171
      fi
172

173
      AC_MSG_CHECKING([for libffi lib file location])
174
      if test "x${LIBFFI_LIB_PATH}" != x; then
175
        if test -e ${LIBFFI_LIB_PATH}/${LIBFFI_LIB_FILE_NAME}; then
176
          LIBFFI_LIB_FILE="${LIBFFI_LIB_PATH}/${LIBFFI_LIB_FILE_NAME}"
177
        else
178
          AC_MSG_ERROR([Could not locate ${LIBFFI_LIB_FILE_NAME} for bundling in ${LIBFFI_LIB_PATH}])
179
        fi
180
      else
181
        # If we don't have an explicit path, look in a few obvious places
182
        if test "x${OPENJDK_TARGET_CPU}" = "xx86"; then
183
          if test -e ${SYSROOT}/usr/lib/${LIBFFI_LIB_FILE_NAME} ; then
184
            LIBFFI_LIB_FILE="${SYSROOT}/usr/lib/${LIBFFI_LIB_FILE_NAME}"
185
          elif test -e ${SYSROOT}/usr/lib/i386-linux-gnu/${LIBFFI_LIB_FILE_NAME} ; then
186
            LIBFFI_LIB_FILE="${SYSROOT}/usr/lib/i386-linux-gnu/${LIBFFI_LIB_FILE_NAME}"
187
          else
188
            AC_MSG_ERROR([Could not locate ${LIBFFI_LIB_FILE_NAME} for bundling])
189
          fi
190
        elif test "x${OPENJDK_TARGET_CPU}" = "xx86_64" || test "x${OPENJDK_TARGET_CPU}" = "xaarch64"; then
191
          if test -e ${SYSROOT}/usr/lib64/${LIBFFI_LIB_FILE_NAME} ; then
192
            LIBFFI_LIB_FILE="${SYSROOT}/usr/lib64/${LIBFFI_LIB_FILE_NAME}"
193
          elif test -e ${SYSROOT}/usr/lib/x86_64-linux-gnu/${LIBFFI_LIB_FILE_NAME} ; then
194
            LIBFFI_LIB_FILE="${SYSROOT}/usr/lib/x86_64-linux-gnu/${LIBFFI_LIB_FILE_NAME}"
195
          else
196
            AC_MSG_ERROR([Could not locate ${LIBFFI_LIB_FILE_NAME} for bundling])
197
          fi
198
        else
199
          # Fallback on the default /usr/lib dir
200
          if test -e ${SYSROOT}/usr/lib/${LIBFFI_LIB_FILE_NAME} ; then
201
            LIBFFI_LIB_FILE="${SYSROOT}/usr/lib/${LIBFFI_LIB_FILE_NAME}"
202
          else
203
            AC_MSG_ERROR([Could not locate ${LIBFFI_LIB_FILE_NAME} for bundling])
204
          fi
205
        fi
206
      fi
207
      # Make sure the wildcard is evaluated
208
      LIBFFI_LIB_FILE="$(ls ${LIBFFI_LIB_FILE})"
209
      AC_MSG_RESULT([${LIBFFI_LIB_FILE}])
210
    fi
211
  fi
212

213
  AC_SUBST(LIBFFI_CFLAGS)
214
  AC_SUBST(LIBFFI_LIBS)
215
  AC_SUBST(ENABLE_LIBFFI_BUNDLING)
216
  AC_SUBST(LIBFFI_LIB_FILE)
217
])
218

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.