Commit 9f8b68a2785563031473011379878bb63ed5d3a3

Sam Lantinga 2022-11-11T10:24:17

Fixed building without linux/input.h https://github.com/libsdl-org/SDL/issues/6169

diff --git a/CMakeLists.txt b/CMakeLists.txt
index bbb2002..d27141d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1010,6 +1010,7 @@ if(SDL_LIBC)
       string(REPLACE "." "_" _HAVE_H ${_UPPER})
       check_include_file("${_HEADER}" ${_HAVE_H})
     endforeach()
+    check_include_file(linux/input.h HAVE_LINUX_INPUT_H)
 
     set(STDC_HEADER_NAMES "stddef.h;stdarg.h;stdlib.h;string.h;stdio.h;wchar.h;float.h")
     check_include_files("${STDC_HEADER_NAMES}" STDC_HEADERS)
@@ -1579,7 +1580,7 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
     if(FREEBSD OR NETBSD OR OPENBSD OR BSDI)
       CheckUSBHID()
     endif()
-    if(LINUX AND NOT ANDROID)
+    if(LINUX AND HAVE_LINUX_INPUT_H AND NOT ANDROID)
       set(SDL_JOYSTICK_LINUX 1)
       file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
       list(APPEND SOURCE_FILES ${JOYSTICK_SOURCES})
diff --git a/configure b/configure
index 0f8806c..4f4253c 100755
--- a/configure
+++ b/configure
@@ -18817,6 +18817,12 @@ then :
   printf "%s\n" "#define HAVE_SIGNAL_H 1" >>confdefs.h
 
 fi
+ac_fn_c_check_header_compile "$LINENO" "linux/input.h" "ac_cv_header_linux_input_h" "$ac_includes_default"
+if test "x$ac_cv_header_linux_input_h" = xyes
+then :
+  printf "%s\n" "#define HAVE_LINUX_INPUT_H 1" >>confdefs.h
+
+fi
 
 
     ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default"
@@ -28492,15 +28498,17 @@ printf "%s\n" "#define SDL_AUDIO_DRIVER_AAUDIO 1" >>confdefs.h
         if test x$enable_joystick = xyes; then
           case $ARCH in
             linux)
+                if test "x$ac_cv_header_linux_input_h" = xyes; then
 
 printf "%s\n" "#define SDL_JOYSTICK_LINUX 1" >>confdefs.h
 
-                SOURCES="$SOURCES $srcdir/src/joystick/linux/*.c"
-                SOURCES="$SOURCES $srcdir/src/joystick/steam/*.c"
-                have_joystick=yes
+                    SOURCES="$SOURCES $srcdir/src/joystick/linux/*.c"
+                    SOURCES="$SOURCES $srcdir/src/joystick/steam/*.c"
+                    have_joystick=yes
+                fi
             ;;
             freebsd)
-                if test x$use_input_events = xyes; then
+                if test x$use_input_events = xyes -a x$ac_cv_header_linux_input_h = xyes; then
 
 printf "%s\n" "#define SDL_JOYSTICK_LINUX 1" >>confdefs.h
 
diff --git a/configure.ac b/configure.ac
index b520d21..60ab5b6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -329,7 +329,7 @@ if test x$enable_libc = xyes; then
 dnl Check for C library headers
 dnl AC_CHECK_INCLUDES_DEFAULT is an autoconf-2.7x thing where AC_HEADER_STDC is deprecated.
     m4_ifdef([AC_CHECK_INCLUDES_DEFAULT], [AC_CHECK_INCLUDES_DEFAULT], [AC_HEADER_STDC])
-    AC_CHECK_HEADERS(sys/types.h stdio.h stdlib.h stddef.h stdarg.h malloc.h memory.h string.h strings.h wchar.h inttypes.h stdint.h limits.h ctype.h math.h float.h iconv.h signal.h)
+    AC_CHECK_HEADERS(sys/types.h stdio.h stdlib.h stddef.h stdarg.h malloc.h memory.h string.h strings.h wchar.h inttypes.h stdint.h limits.h ctype.h math.h float.h iconv.h signal.h linux/input.h)
 
 dnl Check for typedefs, structures, etc.
     AC_TYPE_SIZE_T
@@ -3900,13 +3900,15 @@ case "$host" in
         if test x$enable_joystick = xyes; then
           case $ARCH in
             linux)
-                AC_DEFINE(SDL_JOYSTICK_LINUX, 1, [ ])
-                SOURCES="$SOURCES $srcdir/src/joystick/linux/*.c"
-                SOURCES="$SOURCES $srcdir/src/joystick/steam/*.c"
-                have_joystick=yes
+                if test "x$ac_cv_header_linux_input_h" = xyes; then
+                    AC_DEFINE(SDL_JOYSTICK_LINUX, 1, [ ])
+                    SOURCES="$SOURCES $srcdir/src/joystick/linux/*.c"
+                    SOURCES="$SOURCES $srcdir/src/joystick/steam/*.c"
+                    have_joystick=yes
+                fi
             ;;
             freebsd)
-                if test x$use_input_events = xyes; then
+                if test x$use_input_events = xyes -a x$ac_cv_header_linux_input_h = xyes; then
                     AC_DEFINE(SDL_JOYSTICK_LINUX, 1, [ ])
                     SOURCES="$SOURCES $srcdir/src/joystick/linux/*.c"
                     SOURCES="$SOURCES $srcdir/src/joystick/steam/*.c"
diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake
index c9ee9df..b85c567 100644
--- a/include/SDL_config.h.cmake
+++ b/include/SDL_config.h.cmake
@@ -72,6 +72,7 @@
 #cmakedefine HAVE_STRING_H 1
 #cmakedefine HAVE_SYS_TYPES_H 1
 #cmakedefine HAVE_WCHAR_H 1
+#cmakedefine HAVE_LINUX_INPUT_H 1
 #cmakedefine HAVE_PTHREAD_NP_H 1
 #cmakedefine HAVE_LIBUNWIND_H 1
 
diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in
index f6f2171..67e5074 100644
--- a/include/SDL_config.h.in
+++ b/include/SDL_config.h.in
@@ -75,6 +75,7 @@
 #undef HAVE_STRING_H
 #undef HAVE_SYS_TYPES_H
 #undef HAVE_WCHAR_H
+#undef HAVE_LINUX_INPUT_H
 #undef HAVE_PTHREAD_NP_H
 #undef HAVE_LIBUNWIND_H
 
diff --git a/src/core/linux/SDL_evdev_capabilities.c b/src/core/linux/SDL_evdev_capabilities.c
index 976f629..e23d499 100644
--- a/src/core/linux/SDL_evdev_capabilities.c
+++ b/src/core/linux/SDL_evdev_capabilities.c
@@ -19,10 +19,12 @@
      misrepresented as being the original software.
   3. This notice may not be removed or altered from any source distribution.
 */
+#include "../../SDL_internal.h"
 
 #include "SDL_evdev_capabilities.h"
 
-#if HAVE_LIBUDEV_H || defined(SDL_JOYSTICK_LINUX)
+
+#if HAVE_LINUX_INPUT_H
 
 /* missing defines in older Linux kernel headers */
 #ifndef BTN_TRIGGER_HAPPY
@@ -142,4 +144,6 @@ SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
     return devclass;
 }
 
-#endif
+#endif /* HAVE_LINUX_INPUT_H */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/core/linux/SDL_evdev_capabilities.h b/src/core/linux/SDL_evdev_capabilities.h
index 990ebe0..67b7075 100644
--- a/src/core/linux/SDL_evdev_capabilities.h
+++ b/src/core/linux/SDL_evdev_capabilities.h
@@ -19,12 +19,13 @@
      misrepresented as being the original software.
   3. This notice may not be removed or altered from any source distribution.
 */
-
 #include "../../SDL_internal.h"
 
 #ifndef SDL_evdev_capabilities_h_
 #define SDL_evdev_capabilities_h_
 
+#if HAVE_LINUX_INPUT_H
+
 #include <linux/input.h>
 
 /* A device can be any combination of these classes */
@@ -51,6 +52,8 @@ extern int SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
                                       unsigned long bitmask_key[NBITS(KEY_MAX)],
                                       unsigned long bitmask_rel[NBITS(REL_MAX)]);
 
+#endif /* HAVE_LINUX_INPUT_H */
+
 #endif /* SDL_evdev_capabilities_h_ */
 
 /* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/core/linux/SDL_ime.c b/src/core/linux/SDL_ime.c
index 50b5ebf..3ad4dbf 100644
--- a/src/core/linux/SDL_ime.c
+++ b/src/core/linux/SDL_ime.c
@@ -18,6 +18,7 @@
      misrepresented as being the original software.
   3. This notice may not be removed or altered from any source distribution.
 */
+#include "../../SDL_internal.h"
 
 #include "SDL_ime.h"
 #include "SDL_ibus.h"
diff --git a/src/core/linux/SDL_sandbox.c b/src/core/linux/SDL_sandbox.c
index e266e5e..3987890 100644
--- a/src/core/linux/SDL_sandbox.c
+++ b/src/core/linux/SDL_sandbox.c
@@ -19,9 +19,8 @@
      misrepresented as being the original software.
   3. This notice may not be removed or altered from any source distribution.
 */
-
-
 #include "../../SDL_internal.h"
+
 #include "SDL_sandbox.h"
 
 #include <unistd.h>
diff --git a/src/core/linux/SDL_udev.c b/src/core/linux/SDL_udev.c
index fa775bc..311cdd1 100644
--- a/src/core/linux/SDL_udev.c
+++ b/src/core/linux/SDL_udev.c
@@ -18,6 +18,7 @@
      misrepresented as being the original software.
   3. This notice may not be removed or altered from any source distribution.
 */
+#include "../../SDL_internal.h"
 
 /*
  * To list the properties of a device, try something like:
diff --git a/src/core/linux/SDL_udev.h b/src/core/linux/SDL_udev.h
index 9af4c3f..8ac6cbe 100644
--- a/src/core/linux/SDL_udev.h
+++ b/src/core/linux/SDL_udev.h
@@ -24,7 +24,7 @@
 #ifndef SDL_udev_h_
 #define SDL_udev_h_
 
-#if HAVE_LIBUDEV_H
+#if HAVE_LIBUDEV_H && HAVE_LINUX_INPUT_H
 
 #ifndef SDL_USE_LIBUDEV
 #define SDL_USE_LIBUDEV 1
@@ -108,7 +108,7 @@ extern const SDL_UDEV_Symbols *SDL_UDEV_GetUdevSyms(void);
 extern void SDL_UDEV_ReleaseUdevSyms(void);
 
 
-#endif /* HAVE_LIBUDEV_H */
+#endif /* HAVE_LIBUDEV_H && HAVE_LINUX_INPUT_H */
 
 #endif /* SDL_udev_h_ */
 
diff --git a/src/hidapi/SDL_hidapi.c b/src/hidapi/SDL_hidapi.c
index 07f8c1e..52ee670 100644
--- a/src/hidapi/SDL_hidapi.c
+++ b/src/hidapi/SDL_hidapi.c
@@ -551,7 +551,6 @@ HIDAPI_ShutdownDiscovery()
 #undef HIDAPI_H__
 #if __LINUX__
 
-#include "../core/linux/SDL_udev.h"
 #if SDL_USE_LIBUDEV
 static const SDL_UDEV_Symbols *udev_ctx = NULL;