SDL_rtf: Add -Wall to CFLAGS if available.

From c6c4c8c0a4d688683b83b52f158a76b2d8997984 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Wed, 26 Jan 2022 17:56:10 +0300
Subject: [PATCH] Add -Wall to CFLAGS if available.

---
 configure    | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 configure.ac | 35 ++++++++++++++++++++++++++++++++++-
 2 files changed, 84 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 00d6dc8..e0fbbc9 100755
--- a/configure
+++ b/configure
@@ -11705,6 +11705,52 @@ else
 fi
 
 
+CheckWarnAll()
+{
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GCC -Wall option" >&5
+$as_echo_n "checking for GCC -Wall option... " >&6; }
+    have_gcc_Wall=no
+
+    save_CFLAGS="$CFLAGS"
+    CFLAGS="$save_CFLAGS -Wall"
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int x = 0;
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  have_gcc_Wall=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_gcc_Wall" >&5
+$as_echo "$have_gcc_Wall" >&6; }
+    CFLAGS="$save_CFLAGS"
+
+    if test x$have_gcc_Wall = xyes; then
+        CFLAGS="$CFLAGS -Wall"
+
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for necessary GCC -Wno-multichar option" >&5
+$as_echo_n "checking for necessary GCC -Wno-multichar option... " >&6; }
+        need_gcc_Wno_multichar=no
+        case "$host" in
+            *-*-haiku*)
+                need_gcc_Wno_multichar=yes
+                ;;
+        esac
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: $need_gcc_Wno_multichar" >&5
+$as_echo "$need_gcc_Wno_multichar" >&6; }
+        if test x$need_gcc_Wno_multichar = xyes; then
+            CFLAGS="$CFLAGS -Wno-multichar"
+        fi
+    fi
+}
+
 CheckVisibilityHidden()
 {
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GCC -fvisibility=hidden option" >&5
@@ -12353,11 +12399,11 @@ $as_echo "yes" >&6; }
 	have_SDL_ttf=yes
 fi
     if test x$have_SDL_ttf != xyes; then
-        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** Can't find the SDL2_ttf library - not building showrtf
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** Can't find the SDL2_ttf library - not building showrtf.
 The SDL2_ttf library can be found at:
 http://www.libsdl.org/projects/SDL_ttf/
 " >&5
-$as_echo "$as_me: WARNING: *** Can't find the SDL2_ttf library - not building showrtf
+$as_echo "$as_me: WARNING: *** Can't find the SDL2_ttf library - not building showrtf.
 The SDL2_ttf library can be found at:
 http://www.libsdl.org/projects/SDL_ttf/
 " >&2;}
@@ -12372,6 +12418,8 @@ else
 fi
 
 
+CheckWarnAll
+
 CheckVisibilityHidden
 
 
diff --git a/configure.ac b/configure.ac
index b9bb187..a29f278 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,6 +88,36 @@ case "$host" in
 esac
 AM_CONDITIONAL(USE_VERSION_RC, test x$use_version_rc = xtrue)
 
+dnl See if GCC's -Wall is supported.
+CheckWarnAll()
+{
+    AC_MSG_CHECKING(for GCC -Wall option)
+    have_gcc_Wall=no
+
+    save_CFLAGS="$CFLAGS"
+    CFLAGS="$save_CFLAGS -Wall"
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int x = 0;])], [have_gcc_Wall=yes])
+    AC_MSG_RESULT($have_gcc_Wall)
+    CFLAGS="$save_CFLAGS"
+
+    if test x$have_gcc_Wall = xyes; then
+        CFLAGS="$CFLAGS -Wall"
+
+dnl Haiku headers use multicharacter constants all over the place. Ignore these warnings when using -Wall.
+        AC_MSG_CHECKING(for necessary GCC -Wno-multichar option)
+        need_gcc_Wno_multichar=no
+        case "$host" in
+            *-*-haiku*)
+                need_gcc_Wno_multichar=yes
+                ;;
+        esac
+        AC_MSG_RESULT($need_gcc_Wno_multichar)
+        if test x$need_gcc_Wno_multichar = xyes; then
+            CFLAGS="$CFLAGS -Wno-multichar"
+        fi
+    fi
+}
+
 dnl See if GCC's -fvisibility=hidden is supported (gcc4 and later, usually).
 CheckVisibilityHidden()
 {
@@ -134,7 +164,7 @@ if test x$enable_SDL_ttf = xyes; then
         AC_CHECK_LIB([SDL2_ttf],[TTF_Init],[have_SDL_ttf=yes; SDLTTF_LIBS="-lSDL2_ttf"],[],[])
     ])
     if test x$have_SDL_ttf != xyes; then
-        AC_MSG_WARN([*** Can't find the SDL2_ttf library - not building showrtf
+        AC_MSG_WARN([*** Can't find the SDL2_ttf library - not building showrtf.
 The SDL2_ttf library can be found at:
 http://www.libsdl.org/projects/SDL_ttf/
 ])
@@ -142,6 +172,9 @@ http://www.libsdl.org/projects/SDL_ttf/
 fi
 AM_CONDITIONAL(HAVE_SDL_TTF, test x$have_SDL_ttf = xyes)
 
+dnl check for GCC warning options
+CheckWarnAll
+
 dnl check for GCC visibility attributes
 CheckVisibilityHidden