1 dnl Copyright (C) 2009 Nick Bowler
2 dnl Copying and distribution of this file, with or without modification,
3 dnl are permitted in any medium without royalty provided the copyright
4 dnl notice and this notice are preserved. This file is offered as-is,
5 dnl without any warranty.
7 dnl _LIBPNG_TRY_VERSION(min-version)
8 AC_DEFUN([_LIBPNG_TRY_VERSION], [dnl
9 shead='s/@<:@0-9@:>@@<:@0-9@:>@*/<<<&>>>/'
10 sbody='s/.*<<<\(.*\)>>>.*/\1/;t'
12 png_min_major=`printf '%s' '$1' | sed -e "$shead"1 -e "$sbody" -e "$stail"`
13 png_min_minor=`printf '%s' '$1' | sed -e "$shead"2 -e "$sbody" -e "$stail"`
14 png_min_release=`printf '%s' '$1' | sed -e "$shead"3 -e "$sbody" -e "$stail"`
15 png_min_build=`printf '%s' '$1' | sed -e "$shead"4 -e "$sbody" -e "$stail"`
16 png_min_status=`printf '%s' '$1' | sed '
18 s/.*alpha.*/PNG_LIBPNG_BUILD_ALPHA/
20 s/.*beta.*/PNG_LIBPNG_BUILD_BETA/
22 s/.*rc.*/PNG_LIBPNG_BUILD_RC/
24 s/.*/PNG_LIBPNG_BUILD_STABLE/
27 AC_CACHE_CHECK([for libpng version at least $1],
28 [libpng_cv_sufficient_ver],
29 [AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
31 #if PNG_LIBPNG_VER_MAJOR < $png_min_major
32 # error Invalid libpng major version
33 #elif PNG_LIBPNG_VER_MAJOR == $png_min_major
34 # if PNG_LIBPNG_VER_MINOR < $png_min_minor
35 # error Invalid libpng minor version
36 # elif PNG_LIBPNG_VER_MINOR == $png_min_minor
37 # if PNG_LIBPNG_VER_RELEASE < $png_min_release
38 # error Invalid libpng release
39 # elif PNG_LIBPNG_VER_RELEASE == $png_min_release
40 # if PNG_LIBPNG_BUILD_BASE_TYPE < $png_min_status
41 # error Invalid libpng release status
42 # elif PNG_LIBPNG_BUILD_BASE_TYPE == $png_min_status
43 # if PNG_LIBPNG_VER_BUILD < $png_min_build
44 # error Invalid libpng build
51 png_structp png = png_create_read_struct("", 0, 0, 0);
52 png_infop info = png_create_info_struct(png);
53 ])], [libpng_cv_sufficient_ver=yes], [libpng_cv_sufficient_ver=no])])
56 dnl CHECK_LIBPNG([min-version], [action-if-ok], [action-if-fail])
57 AC_DEFUN([CHECK_LIBPNG],
58 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
59 AC_ARG_VAR([LIBPNG_CFLAGS], [C compiler flags for libpng])dnl
60 AC_ARG_VAR([LIBPNG_LIBS], [linker flags for libpng])dnl
62 if test x"$PKG_CONFIG" != x; then
63 AC_MSG_CHECKING([pkg-config database for libpng])
64 _PKG_CONFIG([libpng_cflags], [cflags], [libpng])
65 _PKG_CONFIG([libpng_libs], [libs], [libpng])
66 if test x$pkg_failed = xyes; then
67 errors=`$PKG_CONFIG --errors-to-stdout --print-errors libpng`
68 echo "$errors" >&AS_MESSAGE_LOG_FD
71 if test x"$LIBPNG_CFLAGS" = x; then
72 LIBPNG_CFLAGS=$pkg_cv_libpng_cflags
74 if test x"$LIBPNG_LIBS" = x; then
75 LIBPNG_LIBS=$pkg_cv_libpng_libs
82 if test x"$LIBPNG_LIBS" = x; then
89 CFLAGS="$LIBPNG_CFLAGS $CFLAGS"
90 LIBS="$LIBPNG_LIBS $LIBS"
92 _LIBPNG_TRY_VERSION(ifelse([$1], [], [1.0], [$1]))
98 if test x"$libpng_cv_sufficient_ver" = x"yes"; then
99 AC_SUBST([LIBPNG_CFLAGS])
100 AC_SUBST([LIBPNG_LIBS])
101 ifelse([$2], [], [true], [$2])
103 ifelse([$3], [], [AC_MSG_FAILURE([dnl
104 libpng version >= ifelse([$1], [], [1.0], [$1]) is required. The latest
105 version can be obtained from http://libpng.org/pub/png/libpng.html.
107 If libpng is installed but was not found by this configure script,
108 consider adjusting LIBPNG_CFLAGS and/or LIBPNG_LIBS as necessary.
110 If pkg-config is installed, it may help to adjust PKG_CONFIG_PATH
111 if libpng is installed in a non-standard prefix.