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

From a4c08c025df3115fc8216799734cdd15b25aced8 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        | 53 ++++++++++++++++++++++++++++++++++++++++--------
 configure.ac     | 29 ++++++++++++++++++++++----
 test/Makefile.in |  2 +-
 3 files changed, 71 insertions(+), 13 deletions(-)

diff --git a/configure b/configure
index 9558b792..314b692d 100755
--- a/configure
+++ b/configure
@@ -12721,6 +12721,41 @@ find_lib()
     done
 }
 
+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
@@ -14181,8 +14216,8 @@ fi
                     ;;
             esac
         else
-            { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** Unable to find PNG library (http://www.libpng.org/pub/png/libpng.html)" >&5
-$as_echo "$as_me: WARNING: *** Unable to find PNG library (http://www.libpng.org/pub/png/libpng.html)" >&2;}
+            { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** Unable to find PNG library (http://www.libpng.org/pub/png/)" >&5
+$as_echo "$as_me: WARNING: *** Unable to find PNG library (http://www.libpng.org/pub/png/)" >&2;}
             { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: PNG image loading disabled" >&5
 $as_echo "$as_me: WARNING: PNG image loading disabled" >&2;}
         fi
@@ -14387,8 +14422,8 @@ fi
                 ;;
         esac
     else
-        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** Unable to find Tiff library (http://www.remotesensing.org/libtiff/)" >&5
-$as_echo "$as_me: WARNING: *** Unable to find Tiff library (http://www.remotesensing.org/libtiff/)" >&2;}
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** Unable to find Tiff library (http://www.simplesystems.org/libtiff/)" >&5
+$as_echo "$as_me: WARNING: *** Unable to find Tiff library (http://www.simplesystems.org/libtiff/)" >&2;}
         { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: TIF image loading disabled" >&5
 $as_echo "$as_me: WARNING: TIF image loading disabled" >&2;}
     fi
@@ -14601,10 +14636,10 @@ fi
                 ;;
         esac
     else
-        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** Unable to find WEBP library (http://code.google.com/intl/en-US/speed/webp/index.html)" >&5
-$as_echo "$as_me: WARNING: *** Unable to find WEBP library (http://code.google.com/intl/en-US/speed/webp/index.html)" >&2;}
-        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: WEBP Pimage loading disabled" >&5
-$as_echo "$as_me: WARNING: WEBP Pimage loading disabled" >&2;}
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** Unable to find WEBP library (https://developers.google.com/speed/webp)" >&5
+$as_echo "$as_me: WARNING: *** Unable to find WEBP library (https://developers.google.com/speed/webp)" >&2;}
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: WEBP image loading disabled" >&5
+$as_echo "$as_me: WARNING: WEBP image loading disabled" >&2;}
     fi
 fi
 
@@ -14806,6 +14841,8 @@ else
 fi
 
 
+CheckNoUndef
+
 CheckWarnAll
 
 CheckVisibilityHidden
diff --git a/configure.ac b/configure.ac
index 1d638ff1..a4aac04a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -137,6 +137,24 @@ find_lib()
     done
 }
 
+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()
 {
@@ -436,7 +454,7 @@ if test x$enable_png = xyes; then
                     ;;
             esac
         else
-            AC_MSG_WARN([*** Unable to find PNG library (http://www.libpng.org/pub/png/libpng.html)])
+            AC_MSG_WARN([*** Unable to find PNG library (http://www.libpng.org/pub/png/)])
             AC_MSG_WARN([PNG image loading disabled])
         fi
     fi
@@ -475,7 +493,7 @@ if test x$enable_tif = xyes -a x$enable_imageio != xyes; then
                 ;;
         esac
     else
-        AC_MSG_WARN([*** Unable to find Tiff library (http://www.remotesensing.org/libtiff/)])
+        AC_MSG_WARN([*** Unable to find Tiff library (http://www.simplesystems.org/libtiff/)])
         AC_MSG_WARN([TIF image loading disabled])
     fi
 fi
@@ -518,8 +536,8 @@ if test x$enable_webp = xyes; then
                 ;;
         esac
     else
-        AC_MSG_WARN([*** Unable to find WEBP library (http://code.google.com/intl/en-US/speed/webp/index.html)])
-        AC_MSG_WARN([WEBP Pimage loading disabled])
+        AC_MSG_WARN([*** Unable to find WEBP library (https://developers.google.com/speed/webp)])
+        AC_MSG_WARN([WEBP image loading disabled])
     fi
 fi
 
@@ -674,6 +692,9 @@ AC_SUBST([PC_REQUIRES])
 AM_CONDITIONAL([BUILD_TESTS], [test "x$enable_tests" = xyes])
 AM_CONDITIONAL([INSTALL_TESTS], [test "x$enable_installed_tests" = xyes])
 
+dnl check for LD --no-undefined option
+CheckNoUndef
+
 dnl check for GCC warning options
 CheckWarnAll
 
diff --git a/test/Makefile.in b/test/Makefile.in
index 9762cf55..110050f8 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -390,7 +390,7 @@ TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver
 TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \
 	$(TEST_LOG_FLAGS)
 am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp \
-	$(top_srcdir)/test-driver
+	$(top_srcdir)/test-driver README.md
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 AMTAR = @AMTAR@