--- /dev/null
+dnl Copyright © 2009-2010, 2014 Nick Bowler
+dnl
+dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
+dnl This is free software: you are free to do what the fuck you want to.
+dnl There is NO WARRANTY, to the extent permitted by law.
+
+dnl DX_LIB_LIBPNG([min-version], [action-if-ok], [acton-if-failed])
+dnl
+dnl Search for a suitable libpng. If min-version is non-empty, the test will
+dnl attempt to reject a libpng installation which is older than the specified
+dnl version number (as determined by the libpng header file).
+dnl
+dnl If a working library is found, appropriate compiler and linker flags
+dnl are stored in LIBPNG_CFLAGS and LIBPNG_LIBS, respectively, and the
+dnl action-if-ok is performed (may be empty). If no such library is found,
+dnl then action-if-failed is performed if non-empty; otherwise configure will
+dnl stop with a fatal error.
+AC_DEFUN([DX_LIB_LIBPNG], [dnl
+DX_LIB_SETUP([libpng])dnl
+DX_LIB_PKGCONFIG_FLAGS([libpng])
+AC_MSG_CHECKING([for libpng[]m4_ifnblank([$1], [ at least version $1])])
+DX_LIB_SEARCH_LINK([libpng],
+ [m4_apply([_DX_LIB_LIBPNG_TEST], m4_split([$1], [\.]))],
+ [
+ [[$LIBPNG_CFLAGS], [$LIBPNG_LIBS]],
+ [[$dx_cv_libpng_pkg_cflags], [$dx_cv_libpng_pkg_libs],
+ [test x"$dx_cv_libpng_pkg_found" = x"yes"]],
+ [[], [-lpng]],
+ ])
+AS_IF([test x"$dx_cv_libpng_lib_found" = x"yes"], [$2],
+ [m4_default([$3], [AC_MSG_FAILURE([dnl
+libpng[]m4_ifnblank([$1], [ version $1 or newer]) is required. The latest
+version may be found at <http://libpng.org/pub/png/libpng.html>.
+m4_newline([DX_LIB_USERFLAG_BLURB([libpng])])
+m4_newline([DX_LIB_PKGCONFIG_BLURB([libpng])])
+])])])])
+
+dnl Internal test program for libpng. Check that the version numbers in the
+dnl header are sufficient and that some important functions are defined.
+m4_define([_DX_LIB_LIBPNG_TEST], [AC_LANG_PROGRAM([dnl
+#include <png.h>
+m4_ifnblank([$1], [dnl
+#if PNG_LIBPNG_VER_MAJOR < $1
+DX_LIB_COMPILE_ERROR([major version insufficient])
+m4_ifnblank([$2], [dnl
+#elif PNG_LIBPNG_VER_MAJOR == $1
+# if PNG_LIBPNG_VER_MINOR < $2
+DX_LIB_COMPILE_ERROR([minor version insufficient])
+m4_ifnblank([$3], [dnl
+# elif PNG_LIBPNG_VER_MINOR == $2
+# if PNG_LIBPNG_VER_RELEASE < $3
+DX_LIB_COMPILE_ERROR([release version insufficient])
+# endif
+])dnl
+# endif
+])dnl
+#endif
+])], [dnl
+png_structp png = png_create_read_struct("", 0, 0, 0);
+png_infop info = png_create_info_struct(png);
+png_destroy_read_struct(&png, &info, 0);
+])])