From 23ad4f4b8c7841d9eb1b19032a6eea613e579a08 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Tue, 24 Nov 2020 14:10:30 +0300 Subject: [PATCH] configure.ac: check GameController framework support when targeting Darwin disables SDL_JOYSTICK_MFI for i386 or if MAC_OS_X_VERSION_MIN_REQUIRED < 1090 --disable-joystick-mfi disables it unconditionally. --- configure | 64 ++++++++++++++++++++++++++++++++++++++++++++++++---- configure.ac | 40 ++++++++++++++++++++++++++++++-- 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/configure b/configure index 47e701c95..e6ff5fe0c 100755 --- a/configure +++ b/configure @@ -887,6 +887,7 @@ enable_dbus enable_ime enable_ibus enable_fcitx +enable_joystick_mfi enable_pthreads enable_pthread_sem enable_directx @@ -1670,6 +1671,7 @@ Optional Features: --enable-ime enable IME support [[default=yes]] --enable-ibus enable IBus support [[default=yes]] --enable-fcitx enable fcitx support [[default=yes]] + --enable-joystick-mfi include macOS MFI joystick support [[default=yes]] --enable-pthreads use POSIX threads for multi-threading [[default=yes]] --enable-pthread-sem use pthread semaphores [[default=yes]] @@ -23145,6 +23147,63 @@ $as_echo "$have_fcitx" >&6; } fi } +CheckJoystickMFI() +{ + # Check whether --enable-joystick-mfi was given. +if test "${enable_joystick_mfi+set}" = set; then : + enableval=$enable_joystick_mfi; +else + enable_joystick_mfi=yes +fi + + + if test x$enable_joystick_mfi = xyes; then + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -x objective-c" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GameController framework" >&5 +$as_echo_n "checking for GameController framework... " >&6; } + enable_joystick_mfi=no + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + #include + #include + #import + + #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090 + #error GameController framework doesn't work on this configuration + #endif + #if TARGET_CPU_X86 + #error GameController framework doesn't work on this configuration + #endif + +int +main () +{ + + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + enable_joystick_mfi=yes + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CFLAGS="$save_CFLAGS" + { $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 + +$as_echo "#define SDL_JOYSTICK_MFI 1" >>confdefs.h + + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-weak_framework,CoreHaptics -Wl,-weak_framework,GameController" + fi + fi +} + CheckPTHREAD() { # Check whether --enable-pthreads was given. @@ -25355,12 +25414,9 @@ $as_echo "#define SDL_AUDIO_DRIVER_COREAUDIO 1" >>confdefs.h $as_echo "#define SDL_JOYSTICK_IOKIT 1" >>confdefs.h - -$as_echo "#define SDL_JOYSTICK_MFI 1" >>confdefs.h - SOURCES="$SOURCES $srcdir/src/joystick/darwin/*.c" SOURCES="$SOURCES $srcdir/src/joystick/iphoneos/*.m" - EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-weak_framework,CoreHaptics -Wl,-weak_framework,GameController" + CheckJoystickMFI have_joystick=yes fi # Set up files for the haptic library diff --git a/configure.ac b/configure.ac index af0c71a02..5432bd598 100644 --- a/configure.ac +++ b/configure.ac @@ -2791,6 +2791,43 @@ AS_HELP_STRING([--enable-fcitx], [enable fcitx support [[default=yes]]]), fi } +dnl Check to see if GameController framework support is desired +CheckJoystickMFI() +{ + AC_ARG_ENABLE(joystick-mfi, +AS_HELP_STRING([--enable-joystick-mfi], [include macOS MFI joystick support [[default=yes]]]), + , enable_joystick_mfi=yes) + + if test x$enable_joystick_mfi = xyes; then + save_CFLAGS="$CFLAGS" + dnl Work around that we don't have Objective-C support in autoconf + CFLAGS="$CFLAGS -x objective-c" + AC_MSG_CHECKING(for GameController framework) + enable_joystick_mfi=no + AC_TRY_COMPILE([ + #include + #include + #import + + #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090 + #error GameController framework doesn't work on this configuration + #endif + #if TARGET_CPU_X86 + #error GameController framework doesn't work on this configuration + #endif + ],[ + ],[ + enable_joystick_mfi=yes + ]) + CFLAGS="$save_CFLAGS" + AC_MSG_RESULT($enable_joystick_mfi) + if test x$enable_joystick_mfi = xyes; then + AC_DEFINE(SDL_JOYSTICK_MFI, 1, [ ]) + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-weak_framework,CoreHaptics -Wl,-weak_framework,GameController" + fi + fi +} + dnl See what type of thread model to use on Linux and Solaris CheckPTHREAD() { @@ -4047,10 +4084,9 @@ AS_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau # Set up files for the joystick library if test x$enable_joystick = xyes; then AC_DEFINE(SDL_JOYSTICK_IOKIT, 1, [ ]) - AC_DEFINE(SDL_JOYSTICK_MFI, 1, [ ]) SOURCES="$SOURCES $srcdir/src/joystick/darwin/*.c" SOURCES="$SOURCES $srcdir/src/joystick/iphoneos/*.m" - EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-weak_framework,CoreHaptics -Wl,-weak_framework,GameController" + CheckJoystickMFI have_joystick=yes fi # Set up files for the haptic library