Commit eec73dfd20667426312f8fa63ccbf08f49048a37

Sam Lantinga 2020-12-09T20:31:00

configure.ac (CheckJoystickMFI): changed AC_TRY_COMPILE to AC_TRY_LINK so as to discover GameController and CoreHaptics frameworks at compile time.

diff --git a/configure b/configure
index d453c5f..71403d4 100755
--- a/configure
+++ b/configure
@@ -23159,7 +23159,9 @@ fi
 
     if test x$enable_joystick_mfi = xyes; then
         save_CFLAGS="$CFLAGS"
+        save_LDFLAGS="$LDFLAGS"
                 CFLAGS="$CFLAGS -x objective-c -fobjc-weak"
+        LDFLAGS="$LDFLAGS -Wl,-weak_framework,CoreHaptics -Wl,-weak_framework,GameController"
         { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GameController framework" >&5
 $as_echo_n "checking for GameController framework... " >&6; }
         enable_joystick_mfi=no
@@ -23170,6 +23172,10 @@ $as_echo_n "checking for GameController framework... " >&6; }
           #include <TargetConditionals.h>
           #import <GameController/GameController.h>
 
+int
+main ()
+{
+
           #if MAC_OS_X_VERSION_MIN_REQUIRED < 1080
           #error GameController framework doesn't work on this configuration
           #endif
@@ -23177,22 +23183,20 @@ $as_echo_n "checking for GameController framework... " >&6; }
           #error GameController framework doesn't work on this configuration
           #endif
 
-int
-main ()
-{
-
-
   ;
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
+if ac_fn_c_try_link "$LINENO"; then :
 
         enable_joystick_mfi=yes
 
 fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
         CFLAGS="$save_CFLAGS"
+        LDFLAGS="$save_LDFLAGS"
+
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_joystick_mfi" >&5
 $as_echo "$enable_joystick_mfi" >&6; }
         if test x$enable_joystick_mfi = xyes; then
diff --git a/configure.ac b/configure.ac
index 11bbc5c..c3327c3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2800,15 +2800,17 @@ AS_HELP_STRING([--enable-joystick-mfi], [include macOS MFI joystick support [[de
 
     if test x$enable_joystick_mfi = xyes; then
         save_CFLAGS="$CFLAGS"
+        save_LDFLAGS="$LDFLAGS"
         dnl Work around that we don't have Objective-C support in autoconf
         CFLAGS="$CFLAGS -x objective-c -fobjc-weak"
+        LDFLAGS="$LDFLAGS -Wl,-weak_framework,CoreHaptics -Wl,-weak_framework,GameController"
         AC_MSG_CHECKING(for GameController framework)
         enable_joystick_mfi=no
-        AC_TRY_COMPILE([
+        AC_TRY_LINK([
           #include <AvailabilityMacros.h>
           #include <TargetConditionals.h>
           #import <GameController/GameController.h>
-
+        ],[
           #if MAC_OS_X_VERSION_MIN_REQUIRED < 1080
           #error GameController framework doesn't work on this configuration
           #endif
@@ -2816,10 +2818,11 @@ AS_HELP_STRING([--enable-joystick-mfi], [include macOS MFI joystick support [[de
           #error GameController framework doesn't work on this configuration
           #endif
         ],[
-        ],[
         enable_joystick_mfi=yes
         ])
         CFLAGS="$save_CFLAGS"
+        LDFLAGS="$save_LDFLAGS"
+
         AC_MSG_RESULT($enable_joystick_mfi)
         if test x$enable_joystick_mfi = xyes; then
             AC_DEFINE(SDL_JOYSTICK_MFI, 1, [ ])