Subject: bug#30431: 27.0.50; "Work even if libpng is install in /usr/local" causes build failure

From: Glenn Morris <[email-masked]>
Date: Mon, 12 Feb 2018 14:13:02 -0500

AFAICS, the issue is that the CHECK_MODULES method sets PNG_LIBS (and
PNG_CFLAGS), whereas the old method sets LIBPNG (and PNG_CFLAGS).

So revert the reversion, and then apply eg:

--- a/configure.ac
+++ b/configure.ac
@@ -3613,7 +3613,9 @@ elif test "${with_png}" != no; then
     AC_CHECK_HEADER([png.h], [HAVE_PNG=yes])
   elif test "${HAVE_X11}" = "yes" || test "${HAVE_W32}" = "yes"; then
    EMACS_CHECK_MODULES([PNG], [libpng >= 1.0.0])
-   if test $HAVE_PNG = no; then
+   if test $HAVE_PNG = yes; then
+    LIBPNG="$PNG_LIBS"
+   else
     # Test old way in case pkg-config doesn't have it (older machines).
     AC_MSG_CHECKING([for libpng not configured by pkg-config])

(Might want to move the "append -lz to LIBPNG" to outside the conditional too.)