SDL_rtf: autotools: support for visibility attributes for relevant targets.

From 934b5267416e3295891d9977b836b011ac84a2e2 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Tue, 14 Dec 2021 23:01:02 +0300
Subject: [PATCH] autotools: support for visibility attributes for relevant
 targets.

---
 configure    | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 configure.ac | 31 +++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+)

diff --git a/configure b/configure
index 6a1941d..12325d9 100755
--- a/configure
+++ b/configure
@@ -11705,6 +11705,50 @@ else
 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=2.0.0
 
 
@@ -12328,6 +12372,8 @@ else
 fi
 
 
+CheckVisibilityHidden
+
 
 
 # Finally create all the generated files
diff --git a/configure.ac b/configure.ac
index 02e987c..dcdd88c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,6 +88,34 @@ case "$host" in
 esac
 AM_CONDITIONAL(USE_VERSION_RC, test x$use_version_rc = xtrue)
 
+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_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+    #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=2.0.0
 AM_PATH_SDL2($SDL_VERSION,
@@ -114,6 +142,9 @@ http://www.libsdl.org/projects/SDL_ttf/
 fi
 AM_CONDITIONAL(HAVE_SDL_TTF, test x$have_SDL_ttf = xyes)
 
+dnl check for GCC visibility attributes
+CheckVisibilityHidden
+
 AC_SUBST([WINDRES])
 
 # Finally create all the generated files