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])