Skip to content

Commit

Permalink
Fixed building without linux/input.h
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Nov 11, 2022
1 parent b7e65a8 commit 9f8b68a
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 19 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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})
Expand Down
16 changes: 12 additions & 4 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -18816,6 +18816,12 @@ if test "x$ac_cv_header_signal_h" = xyes
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


Expand Down Expand Up @@ -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

Expand Down
14 changes: 8 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions include/SDL_config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions include/SDL_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions src/core/linux/SDL_evdev_capabilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: */
5 changes: 4 additions & 1 deletion src/core/linux/SDL_evdev_capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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: */
1 change: 1 addition & 0 deletions src/core/linux/SDL_ime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions src/core/linux/SDL_sandbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions src/core/linux/SDL_udev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/core/linux/SDL_udev.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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_ */

Expand Down
1 change: 0 additions & 1 deletion src/hidapi/SDL_hidapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 9f8b68a

Please sign in to comment.