SDL_image: autotools build system updates:

From 2dab1ee4f754642ba59f78ae4cac62136a3fd113 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 468043c..5f8c40e 100755
--- a/configure
+++ b/configure
@@ -12162,6 +12162,96 @@ find_lib()
     done
 }
 
+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
+}
+
 # Check whether --enable-bmp was given.
 if test "${enable_bmp+set}" = set; then :
   enableval=$enable_bmp;
@@ -13688,6 +13778,10 @@ LIBS="$LIBS $SDL_LIBS"
 
 
 
+CheckWarnAll
+
+CheckVisibilityHidden
+
 OBJCFLAGS=$CFLAGS
 
 # Finally create all the generated files
diff --git a/configure.ac b/configure.ac
index d27ca4e..772c900 100644
--- a/configure.ac
+++ b/configure.ac
@@ -119,6 +119,64 @@ find_lib()
     done
 }
 
+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 command-line options
 AC_ARG_ENABLE([bmp], [AS_HELP_STRING([--enable-bmp], [support loading BMP/ICO/CUR images [default=yes]])],
  [], [enable_bmp=yes])
@@ -429,6 +487,12 @@ AC_SUBST([IMG_LIBS])
 AC_SUBST([PC_LIBS])
 AC_SUBST([PC_REQUIRES])
 
+dnl check for GCC warning options
+CheckWarnAll
+
+dnl check for GCC visibility attributes
+CheckVisibilityHidden
+
 OBJCFLAGS=$CFLAGS
 
 # 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