Rework the SDL detection in configure.ac, otherwise Fuse links with both
SDL and SDL2 at the same time.

Upstream commit 2236600112f97ddd2fa637b6efe5ae206416e25b.

Index: configure.ac
--- configure.ac.orig
+++ configure.ac
@@ -272,18 +272,8 @@ if test -z "$UI"; then
   fi
 fi
 
-dnl Check if the user wants the SDL 2 UI
+dnl Check if the user wants the SDL UI
 if test -z "$UI"; then
-  AC_MSG_CHECKING(whether SDL 2 UI requested)
-  AC_ARG_WITH(sdl2,
-  [  --with-sdl2             use SDL 2 for user interface],
-  if test "$withval" = no; then sdl2_ui=no; else sdl2_ui=yes; fi,
-  sdl2_ui=no)
-  AC_MSG_RESULT($sdl2_ui)
-fi
-
-dnl Check if the user wants the SDL 1 UI
-if test -z "$UI"; then
   AC_MSG_CHECKING(whether SDL UI requested)
   AC_ARG_WITH(sdl,
   [  --with-sdl              use SDL for user interface],
@@ -295,54 +285,44 @@ fi
 dnl Check if the user prefers SDL 1 over SDL 2
 AC_ARG_ENABLE(sdl2,
   AS_HELP_STRING([--disable-sdl2],[disable SDL 2 support]),
-  if test "$enableval" = yes; then sdl2=yes; else sdl2=no; fi,
-  sdl2=yes
+  if test "$enableval" = yes; then enable_sdl2=yes; else enable_sdl2=no; fi,
+  enable_sdl2=yes
 )
 
-if test "$sdl_ui" = yes -a "$sdl2_ui" = yes; then
-  AC_MSG_ERROR([please choose either --with-sdl or --with-sdl2, not both])
+dnl Look for SDL 2
+sdl_available=no
+if test "$enable_sdl2" = yes; then
+  PKG_CHECK_MODULES([SDL2], [sdl2], [sdl_available=2],
+                    [AC_MSG_WARN([SDL 2 not found, looking for SDL 1])])
 fi
 
-dnl Look for SDL 1
-SDL1_VERSION=1.2.4
-sdl1_available=no
-AM_PATH_SDL($SDL1_VERSION, sdl1_available=yes, sdl1_available=no)
-SDL1_CFLAGS="$SDL_CFLAGS"
-SDL1_LIBS="$SDL_LIBS"
-AC_SUBST(SDL1_CFLAGS)
-AC_SUBST(SDL1_LIBS)
-
-dnl Look for SDL 2
-sdl2_available=no
-if test "$sdl2" = yes; then
-  PKG_CHECK_MODULES([SDL2], [sdl2], [sdl2_available=yes], [
-                     AC_MSG_WARN([SDL 2 not found, looking for SDL 1])
-                     sdl2=no])
+dnl Look for SDL 1 if SDL 2 was not found or not requested
+if test "$sdl_available" = no; then
+  SDL1_VERSION=1.2.4
+  AM_PATH_SDL($SDL1_VERSION, sdl_available=1, sdl_available=no)
+  SDL1_CFLAGS="$SDL_CFLAGS"
+  SDL1_LIBS="$SDL_LIBS"
+  AC_SUBST(SDL1_CFLAGS)
+  AC_SUBST(SDL1_LIBS)
 fi
 
-dnl Enable the SDL 2 UI if all conditions are met
-if test "$sdl2_ui" = yes; then
-  if test "$sdl2_available" = yes; then
+dnl Enable the SDL UI if all conditions are met.
+use_sdl=no
+if test "$sdl_ui" = yes; then
+  if test "$sdl_available" = 2; then
     AC_DEFINE([UI_SDL2], 1, [Defined if the SDL 2 UI is in use])
     AC_DEFINE([USE_WIDGET], 1, [Defined if we're using a widget-based UI])
     UI=sdl2
     WIDGET=widget
-    use_sdl2=yes
-  else
-    AC_MSG_ERROR([SDL 2 support requested for the UI, but SDL 2 was not found])
-  fi
-fi
-
-dnl Enable the SDL 1 UI if all conditions are met
-if test "$sdl_ui" = yes; then
-  if test "$sdl1_available" = yes; then
+    use_sdl=2
+  elif test "$sdl_available" = 1; then
     AC_DEFINE([UI_SDL], 1, [Defined if the SDL UI in use])
     AC_DEFINE([USE_WIDGET], 1, [Defined if we're using a widget-based UI])
     UI=sdl
     WIDGET=widget
-    use_sdl1=yes
+    use_sdl=1
   else
-    AC_MSG_ERROR([SDL version $SDL1_VERSION not found])
+    AC_MSG_ERROR([SDL support requested for the UI, but SDL was not found])
   fi
 fi
 
@@ -564,20 +544,9 @@ AC_CHECK_HEADER(
 )
 
 dnl SDL audio
-if test "$sdl2_available" = "yes"; then
-  dnl Default to SDL2 audio if we're using the SDL2 UI
-  if test "$UI" = sdl2; then
-    audio_driver_list="sdl2 $audio_driver_list"
-  else
-    audio_driver_list="$audio_driver_list sdl2"
-  fi
-fi
-
-if test "$sdl1_available" = "yes"; then
-  dnl Default to SDL audio if we're using the SDL 1 UI
-  if test "$UI" = sdl2; then
-    :
-  elif test "$UI" = sdl; then
+if test "$sdl_available" != "no"; then
+  dnl Default to SDL audio if we're using the SDL UI
+  if test "$UI" = sdl || test "$UI" = sdl2; then
     audio_driver_list="sdl $audio_driver_list"
   else
     audio_driver_list="$audio_driver_list sdl"
@@ -672,13 +641,13 @@ dnl
 dnl Add the necessary options for the selected audio driver
 dnl
 case $audio_driver in
-  sdl2)
-    SOUND_LIBADD='sound/sdl2sound.$(OBJEXT)' SOUND_LIBS='' sound_fifo=yes
-    use_sdl2=yes
-    ;;
   sdl)
-    SOUND_LIBADD='sound/sdlsound.$(OBJEXT)' SOUND_LIBS='' sound_fifo=yes
-    use_sdl1=yes
+    if test "$sdl_available" = 2; then
+       SOUND_LIBADD='sound/sdl2sound.$(OBJEXT)' SOUND_LIBS='' sound_fifo=yes
+    else
+       SOUND_LIBADD='sound/sdlsound.$(OBJEXT)' SOUND_LIBS='' sound_fifo=yes
+    fi
+    use_sdl=$sdl_available
     ;;
   directsound)
     SOUND_LIBADD='sound/dxsound.$(OBJEXT)' SOUND_LIBS='-ldsound -lole32 -ldxguid'
@@ -774,12 +743,12 @@ if test "$stick" = yes; then
       if test "$libjsw" = yes; then
         AC_MSG_RESULT([no, use libjsw])
       else
-        if test "$sdl1_available" = yes; then
+        if test "$sdl_available" != no; then
           AC_MSG_RESULT(yes)
           AC_DEFINE([USE_JOYSTICK], 1, [Defined if we're using hardware joysticks])
-          use_sdl1=yes
+          use_sdl=$sdl_available
         else
-          AC_MSG_WARN([SDL version $SDL1_VERSION not found - joystick support disabled])
+          AC_MSG_WARN([No suitable SDL version found - joystick support disabled])
           stick=no
         fi
       fi
@@ -966,8 +935,8 @@ AM_CONDITIONAL(COMPAT_WII, test "$COMPAT_OSNAME" = 'wi
 AM_CONDITIONAL(COMPAT_WIN32, test "$COMPAT_OSNAME" = 'win32')
 
 dnl These tell the Makefile to use SDL 1 and SDL 2 flags during the build
-AM_CONDITIONAL(USE_SDL1, test "$use_sdl1" = "yes")
-AM_CONDITIONAL(USE_SDL2, test "$use_sdl2" = "yes")
+AM_CONDITIONAL(USE_SDL1, test "$use_sdl" = "1")
+AM_CONDITIONAL(USE_SDL2, test "$use_sdl" = "2")
 
 dnl Decide whether to install desktop and mime files
 AC_ARG_ENABLE(desktop-integration,
@@ -1073,12 +1042,7 @@ echo "User interface: ${UI}"
 if test "${UI}" = "gtk3"; then
    echo "Using GTK 3: ${gtk}"
 fi
-if test "${use_sdl1}" = "yes"; then
-   echo "Using SDL 1: yes"
-fi
-if test "${use_sdl2}" = "yes"; then
-   echo "Using SDL 2: yes"
-fi
+echo "Using SDL: ${use_sdl}"
 if test x"${gpm}" != "x"; then
    echo "libgpm support: ${gpm}"
 fi
