SDL_net: autotools build system updates:

From 87cf58228daa81208ab15c12cc44922dff90260d 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        | 94 ++++++++++++++++++++++++++++++++++++++++++++++++
 configure.ac     | 64 +++++++++++++++++++++++++++++++++
 touch-autofoo.sh |  7 ++++
 3 files changed, 165 insertions(+)
 create mode 100755 touch-autofoo.sh

diff --git a/configure b/configure
index c3ba0b0..a1cf32f 100755
--- a/configure
+++ b/configure
@@ -15280,6 +15280,96 @@ case "$host" in
 esac
 
 
+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.14
 
 
@@ -15805,6 +15895,10 @@ else
 fi
 
 
+CheckWarnAll
+
+CheckVisibilityHidden
+
 CXXFLAGS="$CXXFLAGS $CFLAGS"
 
 if test x$enable_shared = xyes; then
diff --git a/configure.ac b/configure.ac
index 34decb3..79a259c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -105,6 +105,64 @@ case "$host" in
 esac
 AC_SUBST(INETLIB)
 
+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.14
 AC_SUBST(SDL_VERSION)
@@ -133,6 +191,12 @@ http://www.libsdl.org/projects/GUIlib/
 fi
 AM_CONDITIONAL(HAVE_GUI_LIB, test x$have_GUI = xyes)
 
+dnl check for GCC warning options
+CheckWarnAll
+
+dnl check for GCC visibility attributes
+CheckVisibilityHidden
+
 dnl C++ flags are the same as the C flags
 CXXFLAGS="$CXXFLAGS $CFLAGS"
 
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