SDL_mixer: autotools: check and use LD --no-undefined option.

From 8bdfdc3a88cf72151ae4639098ab30dc0ddba8ae Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Wed, 25 May 2022 14:00:02 +0300
Subject: [PATCH] autotools: check and use LD --no-undefined option.

---
 configure    | 37 +++++++++++++++++++++++++++++++++++++
 configure.ac | 22 ++++++++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git a/configure b/configure
index ca3d8fa2..13a8adb4 100755
--- a/configure
+++ b/configure
@@ -15210,6 +15210,41 @@ SOURCES=`ls $srcdir/src/*.c $srcdir/src/codecs/*.c | fgrep -v playwave.c | fgrep
 base_bindir=`echo \${bindir} | sed 's/.*\/\(.*\)/\1/; q'`
 base_libdir=`echo \${libdir} | sed 's/.*\/\(.*\)/\1/; q'`
 
+CheckNoUndef()
+{
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker option --no-undefined" >&5
+$as_echo_n "checking for linker option --no-undefined... " >&6; }
+    have_no_undefined=no
+    case "${host_os}" in
+    openbsd*) ;;
+    darwin*) have_no_undefined="-Wl,-undefined,error"
+       BUILD_LDFLAGS="$BUILD_LDFLAGS -Wl,-undefined,error" ;;
+    *) save_LDFLAGS="$LDFLAGS"
+       LDFLAGS="$LDFLAGS -Wl,--no-undefined"
+       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  have_no_undefined=yes
+          BUILD_LDFLAGS="$BUILD_LDFLAGS -Wl,--no-undefined"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+       LDFLAGS="$save_LDFLAGS"
+       ;;
+    esac
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_no_undefined" >&5
+$as_echo "$have_no_undefined" >&6; }
+}
+
 CheckWarnAll()
 {
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GCC -Wall option" >&5
@@ -17884,6 +17919,8 @@ $as_echo "$as_me: WARNING: Opus support disabled" >&2;}
     fi
 fi
 
+CheckNoUndef
+
 EXTRA_LDFLAGS="$EXTRA_LDFLAGS $LIBM"
 
 OBJECTS=`echo $SOURCES`
diff --git a/configure.ac b/configure.ac
index 6ed61d91..852b5e5a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -172,6 +172,25 @@ dnl set this to use on systems that use lib64 instead of lib
 base_bindir=`echo \${bindir} | sed 's/.*\/\(.*\)/\1/; q'`
 base_libdir=`echo \${libdir} | sed 's/.*\/\(.*\)/\1/; q'`
 
+CheckNoUndef()
+{
+AC_MSG_CHECKING(for linker option --no-undefined)
+    have_no_undefined=no
+    case "${host_os}" in
+dnl Skip this on platforms where it is just simply busted
+    openbsd*) ;;
+    darwin*) have_no_undefined="-Wl,-undefined,error"
+       BUILD_LDFLAGS="$BUILD_LDFLAGS -Wl,-undefined,error" ;;
+    *) save_LDFLAGS="$LDFLAGS"
+       LDFLAGS="$LDFLAGS -Wl,--no-undefined"
+       AC_LINK_IFELSE([AC_LANG_PROGRAM],[have_no_undefined=yes
+          BUILD_LDFLAGS="$BUILD_LDFLAGS -Wl,--no-undefined"])
+       LDFLAGS="$save_LDFLAGS"
+       ;;
+    esac
+    AC_MSG_RESULT($have_no_undefined)
+}
+
 dnl See if GCC's -Wall is supported.
 CheckWarnAll()
 {
@@ -923,6 +942,9 @@ if test x$enable_music_opus = xyes; then
     fi
 fi
 
+dnl check for LD --no-undefined option
+CheckNoUndef
+
 EXTRA_LDFLAGS="$EXTRA_LDFLAGS $LIBM"
 
 OBJECTS=`echo $SOURCES`