Skip to content

Commit

Permalink
Joystick mapping support for MacOS using SDL2
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrelliCopter committed Dec 20, 2023
1 parent 590f0ab commit fe01b98
Show file tree
Hide file tree
Showing 8 changed files with 685 additions and 87 deletions.
2 changes: 2 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
SDL2_CFLAGS = @SDL2_CFLAGS@
SDL2_LIBS = @SDL2_LIBS@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
Expand Down
80 changes: 6 additions & 74 deletions aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ If you have problems, you may need to regenerate the build system entirely.
To do so, use the procedure documented by the package, typically 'autoreconf'.])])

# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
# serial 11 (pkg-config-0.29.1)
# serial 12 (pkg-config-0.29.2)

dnl Copyright © 2004 Scott James Remnant <[email protected]>.
dnl Copyright © 2012-2015 Dan Nicholson <[email protected]>
Expand Down Expand Up @@ -63,7 +63,7 @@ dnl
dnl See the "Since" comment for each macro you use to see what version
dnl of the macros you require.
m4_defun([PKG_PREREQ],
[m4_define([PKG_MACROS_VERSION], [0.29.1])
[m4_define([PKG_MACROS_VERSION], [0.29.2])
m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
[m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
])dnl PKG_PREREQ
Expand Down Expand Up @@ -164,7 +164,7 @@ AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
pkg_failed=no
AC_MSG_CHECKING([for $1])
AC_MSG_CHECKING([for $2])
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
_PKG_CONFIG([$1][_LIBS], [libs], [$2])
Expand All @@ -174,11 +174,11 @@ and $1[]_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.])
if test $pkg_failed = yes; then
AC_MSG_RESULT([no])
AC_MSG_RESULT([no])
_PKG_SHORT_ERRORS_SUPPORTED
if test $_pkg_short_errors_supported = yes; then
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
else
else
$1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
Expand All @@ -195,7 +195,7 @@ installed software in a non-standard prefix.
_PKG_TEXT])[]dnl
])
elif test $pkg_failed = untried; then
AC_MSG_RESULT([no])
AC_MSG_RESULT([no])
m4_default([$4], [AC_MSG_FAILURE(
[The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
Expand Down Expand Up @@ -296,74 +296,6 @@ AS_VAR_COPY([$1], [pkg_cv_][$1])
AS_VAR_IF([$1], [""], [$5], [$4])dnl
])dnl PKG_CHECK_VAR

dnl PKG_WITH_MODULES(VARIABLE-PREFIX, MODULES,
dnl [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND],
dnl [DESCRIPTION], [DEFAULT])
dnl ------------------------------------------
dnl
dnl Prepare a "--with-" configure option using the lowercase
dnl [VARIABLE-PREFIX] name, merging the behaviour of AC_ARG_WITH and
dnl PKG_CHECK_MODULES in a single macro.
AC_DEFUN([PKG_WITH_MODULES],
[
m4_pushdef([with_arg], m4_tolower([$1]))
m4_pushdef([description],
[m4_default([$5], [build with ]with_arg[ support])])
m4_pushdef([def_arg], [m4_default([$6], [auto])])
m4_pushdef([def_action_if_found], [AS_TR_SH([with_]with_arg)=yes])
m4_pushdef([def_action_if_not_found], [AS_TR_SH([with_]with_arg)=no])
m4_case(def_arg,
[yes],[m4_pushdef([with_without], [--without-]with_arg)],
[m4_pushdef([with_without],[--with-]with_arg)])
AC_ARG_WITH(with_arg,
AS_HELP_STRING(with_without, description[ @<:@default=]def_arg[@:>@]),,
[AS_TR_SH([with_]with_arg)=def_arg])
AS_CASE([$AS_TR_SH([with_]with_arg)],
[yes],[PKG_CHECK_MODULES([$1],[$2],$3,$4)],
[auto],[PKG_CHECK_MODULES([$1],[$2],
[m4_n([def_action_if_found]) $3],
[m4_n([def_action_if_not_found]) $4])])
m4_popdef([with_arg])
m4_popdef([description])
m4_popdef([def_arg])
])dnl PKG_WITH_MODULES

dnl PKG_HAVE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
dnl [DESCRIPTION], [DEFAULT])
dnl -----------------------------------------------
dnl
dnl Convenience macro to trigger AM_CONDITIONAL after PKG_WITH_MODULES
dnl check._[VARIABLE-PREFIX] is exported as make variable.
AC_DEFUN([PKG_HAVE_WITH_MODULES],
[
PKG_WITH_MODULES([$1],[$2],,,[$3],[$4])
AM_CONDITIONAL([HAVE_][$1],
[test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"])
])dnl PKG_HAVE_WITH_MODULES

dnl PKG_HAVE_DEFINE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
dnl [DESCRIPTION], [DEFAULT])
dnl ------------------------------------------------------
dnl
dnl Convenience macro to run AM_CONDITIONAL and AC_DEFINE after
dnl PKG_WITH_MODULES check. HAVE_[VARIABLE-PREFIX] is exported as make
dnl and preprocessor variable.
AC_DEFUN([PKG_HAVE_DEFINE_WITH_MODULES],
[
PKG_HAVE_WITH_MODULES([$1],[$2],[$3],[$4])
AS_IF([test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"],
[AC_DEFINE([HAVE_][$1], 1, [Enable ]m4_tolower([$1])[ support])])
])dnl PKG_HAVE_DEFINE_WITH_MODULES

# Copyright (C) 2002-2021 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
Expand Down
92 changes: 87 additions & 5 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ am__EXEEXT_TRUE
LTLIBOBJS
LIBOBJS
DEFINES
SDL2_LIBS
SDL2_CFLAGS
GTK_LIBS
GTK_CFLAGS
PKG_CONFIG_LIBDIR
Expand Down Expand Up @@ -774,7 +776,9 @@ PKG_CONFIG
PKG_CONFIG_PATH
PKG_CONFIG_LIBDIR
GTK_CFLAGS
GTK_LIBS'
GTK_LIBS
SDL2_CFLAGS
SDL2_LIBS'


# Initialize some variables set by options.
Expand Down Expand Up @@ -1424,6 +1428,8 @@ Some influential environment variables:
path overriding pkg-config's built-in search path
GTK_CFLAGS C compiler flags for GTK, overriding pkg-config
GTK_LIBS linker flags for GTK, overriding pkg-config
SDL2_CFLAGS C compiler flags for SDL2, overriding pkg-config
SDL2_LIBS linker flags for SDL2, overriding pkg-config
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
Expand Down Expand Up @@ -4886,8 +4892,8 @@ fi


pkg_failed=no
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GTK" >&5
printf %s "checking for GTK... " >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for gtk+-3.0 >= 3.16 glib-2.0 >= 2.42" >&5
printf %s "checking for gtk+-3.0 >= 3.16 glib-2.0 >= 2.42... " >&6; }

if test -n "$GTK_CFLAGS"; then
pkg_cv_GTK_CFLAGS="$GTK_CFLAGS"
Expand Down Expand Up @@ -4927,7 +4933,7 @@ fi


if test $pkg_failed = yes; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }

if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
Expand All @@ -4945,7 +4951,7 @@ fi

as_fn_error $? "Mednaffe needs GTK+ >= 3.16 development libraries" "$LINENO" 5
elif test $pkg_failed = untried; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
as_fn_error $? "Mednaffe needs GTK+ >= 3.16 development libraries" "$LINENO" 5
else
Expand All @@ -4956,6 +4962,82 @@ printf "%s\n" "yes" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: Checking for GTK+ 3 development libraries" >&5
printf "%s\n" "$as_me: Checking for GTK+ 3 development libraries" >&6;}
fi
case $host_os in
darwin*)

pkg_failed=no
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for SDL2 >= 2.0.6" >&5
printf %s "checking for SDL2 >= 2.0.6... " >&6; }

if test -n "$SDL2_CFLAGS"; then
pkg_cv_SDL2_CFLAGS="$SDL2_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"SDL2 >= 2.0.6\""; } >&5
($PKG_CONFIG --exists --print-errors "SDL2 >= 2.0.6") 2>&5
ac_status=$?
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
pkg_cv_SDL2_CFLAGS=`$PKG_CONFIG --cflags "SDL2 >= 2.0.6" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
fi
else
pkg_failed=untried
fi
if test -n "$SDL2_LIBS"; then
pkg_cv_SDL2_LIBS="$SDL2_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"SDL2 >= 2.0.6\""; } >&5
($PKG_CONFIG --exists --print-errors "SDL2 >= 2.0.6") 2>&5
ac_status=$?
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
pkg_cv_SDL2_LIBS=`$PKG_CONFIG --libs "SDL2 >= 2.0.6" 2>/dev/null`
test "x$?" != "x0" && pkg_failed=yes
else
pkg_failed=yes
fi
else
pkg_failed=untried
fi



if test $pkg_failed = yes; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }

if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
_pkg_short_errors_supported=yes
else
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
SDL2_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "SDL2 >= 2.0.6" 2>&1`
else
SDL2_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "SDL2 >= 2.0.6" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
echo "$SDL2_PKG_ERRORS" >&5

as_fn_error $? "Mednaffe darwin needs SDL2 >= 2.0.6 development libraries" "$LINENO" 5
elif test $pkg_failed = untried; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
as_fn_error $? "Mednaffe darwin needs SDL2 >= 2.0.6 development libraries" "$LINENO" 5
else
SDL2_CFLAGS=$pkg_cv_SDL2_CFLAGS
SDL2_LIBS=$pkg_cv_SDL2_LIBS
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: Checking for SDL2 development libraries" >&5
printf "%s\n" "$as_me: Checking for SDL2 development libraries" >&6;}
fi
;;
esac



Expand Down
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ else
fi

PKG_CHECK_MODULES([GTK],[gtk+-3.0 >= 3.16 glib-2.0 >= 2.42], AC_MSG_NOTICE([Checking for GTK+ 3 development libraries]), AC_MSG_ERROR(Mednaffe needs GTK+ >= 3.16 development libraries))
case $host_os in
darwin*)
PKG_CHECK_MODULES([SDL2],[SDL2 >= 2.0.6], AC_MSG_NOTICE([Checking for SDL2 development libraries]), AC_MSG_ERROR(Mednaffe darwin needs SDL2 >= 2.0.6 development libraries))
;;
esac

AC_SUBST(DEFINES)

Expand Down
2 changes: 2 additions & 0 deletions share/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
SDL2_CFLAGS = @SDL2_CFLAGS@
SDL2_LIBS = @SDL2_LIBS@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
Expand Down
11 changes: 8 additions & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if WINDOWS
LIBS +=../share/win/mednaffe.res -ldxguid -ldinput
else
if MAC
mednaffe_SOURCES+= widgets/joystick_dummy.c
mednaffe_SOURCES+= widgets/joystick_sdl.c
else
mednaffe_SOURCES+= widgets/joystick_dummy.c
override CFLAGS +=-Wl,-export-dynamic
Expand All @@ -54,7 +54,12 @@ endif
endif


AM_CPPFLAGS = @GTK_CFLAGS@
LDADD = @GTK_LIBS@
if MAC
AM_CPPFLAGS = @GTK_CFLAGS@ @SDL2_CFLAGS@
LDADD = @GTK_LIBS@ @SDL2_LIBS@
else
AM_CPPFLAGS = @GTK_CFLAGS@
LDADD = @GTK_LIBS@
endif
CLEANFILES = *~
DISTCLEANFILES = .deps/*.P
Loading

0 comments on commit fe01b98

Please sign in to comment.