SDL_rtf: autotools build system updates:

From 04d163ee5f3152e952cb04ed727f6d8671e2ba79 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Wed, 26 Jan 2022 17:55:50 +0300
Subject: [PATCH] autotools build system updates:

- Add -Wall to CFLAGS, when available.
- Use visibility attribs if available.
---
 configure        | 98 +++++++++++++++++++++++++++++++++++++++++++++++-
 configure.ac     | 66 +++++++++++++++++++++++++++++++-
 touch-autofoo.sh |  7 ++++
 3 files changed, 168 insertions(+), 3 deletions(-)
 create mode 100755 touch-autofoo.sh

diff --git a/configure b/configure
index 62aaa87..8d47bc9 100755
--- a/configure
+++ b/configure
@@ -11374,6 +11374,96 @@ 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
+            *-*-beos* | *-*-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
+$as_echo_n "checking for GCC -fvisibility=hidden option... " >&6; }
+    have_gcc_fvisibility=no
+    case "$host" in
+    *-*-cygwin* | *-*-mingw* | *-*-os2*)
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: ignored for $host_os" >&5
+$as_echo "ignored for $host_os" >&6; }
+        return
+        ;;
+    esac
+
+    visibility_CFLAGS="-fvisibility=hidden"
+    save_CFLAGS="$CFLAGS"
+    CFLAGS="$save_CFLAGS $visibility_CFLAGS -Werror"
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+    #if !defined(__GNUC__) || __GNUC__ < 4
+    #error SDL only uses visibility attributes in GCC 4 or newer
+    #endif
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  have_gcc_fvisibility=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_gcc_fvisibility" >&5
+$as_echo "$have_gcc_fvisibility" >&6; }
+    CFLAGS="$save_CFLAGS"
+
+    if test x$have_gcc_fvisibility = xyes; then
+        CFLAGS="$CFLAGS $visibility_CFLAGS"
+    fi
+}
+
 SDL_VERSION=1.2.4
 
 
@@ -11978,11 +12068,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 SDL_ttf library - not building showrtf
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** Can't find the SDL_ttf library - not building showrtf.
 The SDL_ttf library can be found at:
 http://www.libsdl.org/projects/SDL_ttf/
 " >&5
-$as_echo "$as_me: WARNING: *** Can't find the SDL_ttf library - not building showrtf
+$as_echo "$as_me: WARNING: *** Can't find the SDL_ttf library - not building showrtf.
 The SDL_ttf library can be found at:
 http://www.libsdl.org/projects/SDL_ttf/
 " >&2;}
@@ -11997,6 +12087,10 @@ else
 fi
 
 
+CheckWarnAll
+
+CheckVisibilityHidden
+
 
 
 # Finally create all the generated files
diff --git a/configure.ac b/configure.ac
index bc3e507..70a5d16 100644
--- a/configure.ac
+++ b/configure.ac
@@ -78,6 +78,64 @@ 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_TRY_COMPILE([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
+            *-*-beos* | *-*-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()
+{
+    AC_MSG_CHECKING(for GCC -fvisibility=hidden option)
+    have_gcc_fvisibility=no
+    case "$host" in
+    *-*-cygwin* | *-*-mingw* | *-*-os2*)
+        AC_MSG_RESULT([ignored for $host_os])
+        return
+        ;;
+    esac
+
+    visibility_CFLAGS="-fvisibility=hidden"
+    save_CFLAGS="$CFLAGS"
+    CFLAGS="$save_CFLAGS $visibility_CFLAGS -Werror"
+    AC_TRY_COMPILE([
+    #if !defined(__GNUC__) || __GNUC__ < 4
+    #error SDL only uses visibility attributes in GCC 4 or newer
+    #endif
+    ],, [have_gcc_fvisibility=yes])
+    AC_MSG_RESULT($have_gcc_fvisibility)
+    CFLAGS="$save_CFLAGS"
+
+    if test x$have_gcc_fvisibility = xyes; then
+        CFLAGS="$CFLAGS $visibility_CFLAGS"
+    fi
+}
+
 dnl Check for SDL
 SDL_VERSION=1.2.4
 AM_PATH_SDL($SDL_VERSION,
@@ -96,7 +154,7 @@ if test x$enable_SDL_ttf = xyes; then
         AC_CHECK_LIB([SDL_ttf],[TTF_Init],[have_SDL_ttf=yes; SDLTTF_LIBS="-lSDL_ttf"],[],[])
     ])
     if test x$have_SDL_ttf != xyes; then
-        AC_MSG_WARN([*** Can't find the SDL_ttf library - not building showrtf
+        AC_MSG_WARN([*** Can't find the SDL_ttf library - not building showrtf.
 The SDL_ttf library can be found at:
 http://www.libsdl.org/projects/SDL_ttf/
 ])
@@ -104,6 +162,12 @@ 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
+
 AC_SUBST([WINDRES])
 
 # Finally create all the generated files
diff --git a/touch-autofoo.sh b/touch-autofoo.sh
new file mode 100755
index 0000000..edd5db3
--- /dev/null
+++ b/touch-autofoo.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+# Run this script from the root of $srcdir to touch the
+# autotools generated files, so that the build procedure
+# doesn't attempt to regenerate them.
+
+touch aclocal.m4 configure Makefile.in