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

From 274ad17e98d07dc6b4ba5ddb7bcb782767832297 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.

---
 Makefile.in  |  2 +-
 configure    | 37 +++++++++++++++++++++++++++++++++++++
 configure.ac | 21 +++++++++++++++++++++
 3 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/Makefile.in b/Makefile.in
index 760602f..1eaa0df 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -818,7 +818,7 @@ EXTRA_DIST = CHANGES.txt COPYING.txt README.txt \
 	Android.mk Makefile.os2 version.rc	\
 	VisualC VisualC-WinRT Xcode external	\
 	SDL2_ttf.spec SDL2_ttf.spec.in		\
-	SDL2_ttfConfig.cmake.in			\
+	SDL2_ttfConfig.cmake.in		\
 	autogen.sh gcc-fat.sh
 
 showfont_LDADD = libSDL2_ttf.la
diff --git a/configure b/configure
index 7877d48..d89fa15 100755
--- a/configure
+++ b/configure
@@ -16495,6 +16495,41 @@ rm -f core conftest.err conftest.$ac_objext \
 CFLAGS="$CFLAGS $SDL_CFLAGS"
 LIBS="$LIBS $SDL_LIBS"
 
+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"
+       LDFLAGS="$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
+else
+  LDFLAGS="$save_LDFLAGS"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+       ;;
+    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
@@ -18517,6 +18552,8 @@ else
 fi
 
 
+CheckNoUndef
+
 case "$host" in
     *-*-cygwin* | *-*-mingw*)
         MATHLIB=""
diff --git a/configure.ac b/configure.ac
index a0f4f97..60b9f43 100644
--- a/configure.ac
+++ b/configure.ac
@@ -109,6 +109,24 @@ AM_PATH_SDL2($SDL_VERSION,
 CFLAGS="$CFLAGS $SDL_CFLAGS"
 LIBS="$LIBS $SDL_LIBS"
 
+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"
+       LDFLAGS="$LDFLAGS -Wl,-undefined,error" ;;
+    *) save_LDFLAGS="$LDFLAGS"
+       LDFLAGS="$LDFLAGS -Wl,--no-undefined"
+       AC_LINK_IFELSE([AC_LANG_PROGRAM],
+          [have_no_undefined=yes],[LDFLAGS="$save_LDFLAGS"])
+       ;;
+    esac
+    AC_MSG_RESULT($have_no_undefined)
+}
+
 dnl See if GCC's -Wall is supported.
 CheckWarnAll()
 {
@@ -277,6 +295,9 @@ fi
 AM_CONDITIONAL(OS_WIN32, test x$hb_os_win32 = xyes)
 AM_CONDITIONAL(USE_BUILTIN_HARFBUZZ, test x$enable_harfbuzz_builtin = xyes)
 
+dnl check for LD --no-undefined option
+CheckNoUndef
+
 dnl Check for OpenGL
 case "$host" in
     *-*-cygwin* | *-*-mingw*)