@@ -57,7 +57,11 @@ AC_DEFUN_ONCE([LIB_SETUP_LIBFFI],
5757
5858 if test "x${with_libffi}" != x; then
5959 LIBFFI_LIB_PATH="${with_libffi}/lib"
60- LIBFFI_LIBS="-L${with_libffi}/lib -lffi"
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
6165 LIBFFI_CFLAGS="-I${with_libffi}/include"
6266 LIBFFI_FOUND=yes
6367 fi
@@ -67,7 +71,11 @@ AC_DEFUN_ONCE([LIB_SETUP_LIBFFI],
6771 fi
6872 if test "x${with_libffi_lib}" != x; then
6973 LIBFFI_LIB_PATH="${with_libffi_lib}"
70- LIBFFI_LIBS="-L${with_libffi_lib} -lffi"
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
7179 LIBFFI_FOUND=yes
7280 fi
7381 # Do not try pkg-config if we have a sysroot set.
@@ -106,12 +114,13 @@ AC_DEFUN_ONCE([LIB_SETUP_LIBFFI],
106114 AC_MSG_ERROR ( [ Could not find libffi! $HELP_MSG] )
107115 fi
108116
109- AC_MSG_CHECKING ( [ if libffi works] )
110117 AC_LANG_PUSH ( C )
111118 OLD_CFLAGS="$CFLAGS"
112119 CFLAGS="$CFLAGS $LIBFFI_CFLAGS"
113120 OLD_LIBS="$LIBS"
114121 LIBS="$LIBS $LIBFFI_LIBS"
122+
123+ AC_MSG_CHECKING ( [ if libffi works] )
115124 AC_LINK_IFELSE ( [ AC_LANG_PROGRAM ( [ #include <ffi.h>] ,
116125 [
117126 ffi_call(NULL, NULL, NULL, NULL);
@@ -120,49 +129,78 @@ AC_DEFUN_ONCE([LIB_SETUP_LIBFFI],
120129 [ LIBFFI_WORKS=yes] ,
121130 [ LIBFFI_WORKS=no]
122131 )
123- CFLAGS="$OLD_CFLAGS"
124- LIBS="$OLD_LIBS"
125- AC_LANG_POP ( C )
126132 AC_MSG_RESULT ( [ $LIBFFI_WORKS] )
127133
128134 if test "x$LIBFFI_WORKS" = xno; then
129135 HELP_MSG_MISSING_DEPENDENCY([ ffi] )
130136 AC_MSG_ERROR ( [ Found libffi but could not link and compile with it. $HELP_MSG] )
131137 fi
132138
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+
133163 # Find the libffi.so.X to bundle
134164 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+
135173 AC_MSG_CHECKING ( [ for libffi lib file location] )
136174 if test "x${LIBFFI_LIB_PATH}" != x; then
137- if test -e ${LIBFFI_LIB_PATH}/libffi.so.? ; then
138- LIBFFI_LIB_FILE="${LIBFFI_LIB_PATH}/libffi.so.? "
175+ if test -e ${LIBFFI_LIB_PATH}/${LIBFFI_LIB_FILE_NAME} ; then
176+ LIBFFI_LIB_FILE="${LIBFFI_LIB_PATH}/${LIBFFI_LIB_FILE_NAME} "
139177 else
140- AC_MSG_ERROR ( [ Could not locate libffi.so.? for bundling in ${LIBFFI_LIB_PATH}] )
178+ AC_MSG_ERROR ( [ Could not locate ${LIBFFI_LIB_FILE_NAME} for bundling in ${LIBFFI_LIB_PATH}] )
141179 fi
142180 else
143181 # If we don't have an explicit path, look in a few obvious places
144182 if test "x${OPENJDK_TARGET_CPU}" = "xx86"; then
145- if test -e ${SYSROOT}/usr/lib/libffi.so.? ; then
146- LIBFFI_LIB_FILE="${SYSROOT}/usr/lib/libffi.so.? "
147- elif test -e ${SYSROOT}/usr/lib/i386-linux-gnu/libffi.so.? ; then
148- LIBFFI_LIB_FILE="${SYSROOT}/usr/lib/i386-linux-gnu/libffi.so.? "
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} "
149187 else
150- AC_MSG_ERROR ( [ Could not locate libffi.so.? for bundling] )
188+ AC_MSG_ERROR ( [ Could not locate ${LIBFFI_LIB_FILE_NAME} for bundling] )
151189 fi
152190 elif test "x${OPENJDK_TARGET_CPU}" = "xx86_64" || test "x${OPENJDK_TARGET_CPU}" = "xaarch64"; then
153- if test -e ${SYSROOT}/usr/lib64/libffi.so.? ; then
154- LIBFFI_LIB_FILE="${SYSROOT}/usr/lib64/libffi.so.? "
155- elif test -e ${SYSROOT}/usr/lib/x86_64-linux-gnu/libffi.so.? ; then
156- LIBFFI_LIB_FILE="${SYSROOT}/usr/lib/x86_64-linux-gnu/libffi.so.? "
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} "
157195 else
158- AC_MSG_ERROR ( [ Could not locate libffi.so.? for bundling] )
196+ AC_MSG_ERROR ( [ Could not locate ${LIBFFI_LIB_FILE_NAME} for bundling] )
159197 fi
160198 else
161199 # Fallback on the default /usr/lib dir
162- if test -e ${SYSROOT}/usr/lib/libffi.so.? ; then
163- LIBFFI_LIB_FILE="${SYSROOT}/usr/lib/libffi.so.? "
200+ if test -e ${SYSROOT}/usr/lib/${LIBFFI_LIB_FILE_NAME} ; then
201+ LIBFFI_LIB_FILE="${SYSROOT}/usr/lib/${LIBFFI_LIB_FILE_NAME} "
164202 else
165- AC_MSG_ERROR ( [ Could not locate libffi.so.? for bundling] )
203+ AC_MSG_ERROR ( [ Could not locate ${LIBFFI_LIB_FILE_NAME} for bundling] )
166204 fi
167205 fi
168206 fi
0 commit comments