-fi
-if test $HAVE_PNG = yes; then
- AC_DEFINE([HAVE_PNG], [1], [Define to 1 if you have the png library.])
-
- SAVE_CFLAGS=$CFLAGS
- CFLAGS="$CFLAGS $PNG_CFLAGS"
- AC_CHECK_DECL([png_longjmp],
- [],
- [AC_DEFINE([PNG_DEPSTRUCT], [],
- [Define to empty to suppress deprecation warnings when building
- with --enable-gcc-warnings and with libpng versions before 1.5,
- which lack png_longjmp.])],
- [[#include <png.h>
- ]])
- CFLAGS=$SAVE_CFLAGS
+
+ if test "${HAVE_PNG}" = "yes"; then
+ AC_DEFINE(HAVE_PNG, 1, [Define to 1 if you have the png library.])
+
+ dnl Some systems, eg NetBSD 6, only provide eg "libpng16", not "libpng".
+ lpng=`libpng-config --libs 2> /dev/null`
+ case $lpng in
+ -l*) : ;;
+ *) lpng="-lpng" ;;
+ esac
+ LIBPNG="$lpng -lz -lm"
+
+ AC_CHECK_DECL(png_longjmp,
+ [],
+ [AC_DEFINE(PNG_DEPSTRUCT, [],
+ [Define to empty to suppress deprecation warnings when building
+ with --enable-gcc-warnings and with libpng versions before 1.5,
+ which lack png_longjmp.])],
+ [[#ifdef HAVE_LIBPNG_PNG_H
+ # include <libpng/png.h>
+ #else
+ # include <png.h>
+ #endif
+ ]])
+ fi