]> git.draconx.ca Git - liblbx.git/blob - m4/libpng.m4
build: Import the libpng check from marksim.
[liblbx.git] / m4 / libpng.m4
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.
6
7 dnl _LIBPNG_TRY_VERSION(min-version)
8 AC_DEFUN([_LIBPNG_TRY_VERSION], [dnl
9 sedhead='s/@<:@0-9@:>@@<:@0-9@:>@*/<<<&>>>/'
10 sedtail='s/.*<<<\(.*\)>>>.*/\1/;t;s/.*/0/'
11 png_min_major=`printf   '%s' '$1' | sed -e "$sedhead"1 -e "$sedtail"`
12 png_min_minor=`printf   '%s' '$1' | sed -e "$sedhead"2 -e "$sedtail"`
13 png_min_release=`printf '%s' '$1' | sed -e "$sedhead"3 -e "$sedtail"`
14 png_min_build=`printf   '%s' '$1' | sed -e "$sedhead"4 -e "$sedtail"`
15 png_min_status=`printf  '%s' '$1' | sed '
16         t; s/.*alpha.*/PNG_LIBPNG_BUILD_ALPHA/
17         t; s/.*beta.*/PNG_LIBPNG_BUILD_BETA/
18         t; s/.*rc.*/PNG_LIBPNG_BUILD_RC/
19         t; s/.*/PNG_LIBPNG_BUILD_STABLE/
20 '`
21
22 AC_CACHE_CHECK([for libpng version at least $1],
23         [libpng_cv_sufficient_ver],
24         [AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
25 #include <png.h>
26 #if PNG_LIBPNG_VER_MAJOR < $png_min_major
27 #  error Invalid libpng major version
28 #elif PNG_LIBPNG_VER_MAJOR == $png_min_major
29 #  if PNG_LIBPNG_VER_MINOR < $png_min_minor
30 #    error Invalid libpng minor version
31 #  elif PNG_LIBPNG_VER_MINOR == $png_min_minor
32 #    if PNG_LIBPNG_VER_RELEASE < $png_min_release
33 #      error Invalid libpng release
34 #    elif PNG_LIBPNG_VER_RELEASE == $png_min_release
35 #      if PNG_LIBPNG_BUILD_BASE_TYPE < $png_min_status
36 #        error Invalid libpng release status
37 #      elif PNG_LIBPNG_BUILD_BASE_TYPE == $png_min_status
38 #        if PNG_LIBPNG_VER_BUILD < $png_min_build
39 #          error Invalid libpng build
40 #        endif
41 #      endif
42 #    endif
43 #  endif
44 #endif
45 ], [dnl
46 png_structp png  = png_create_read_struct("", 0, 0, 0);
47 png_infop   info = png_create_info_struct(png);
48 ])], [libpng_cv_sufficient_ver=yes], [libpng_cv_sufficient_ver=no])])
49 ])
50
51 dnl CHECK_LIBPNG([min-version], [action-if-ok], [action-if-fail])
52 AC_DEFUN([CHECK_LIBPNG],
53 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
54 AC_ARG_VAR([LIBPNG_CFLAGS], [C compiler flags for libpng])dnl
55 AC_ARG_VAR([LIBPNG_LIBS],   [linker flags for libpng])dnl
56
57 if test x"$PKG_CONFIG" != x; then
58         AC_MSG_CHECKING([pkg-config database for libpng])
59         _PKG_CONFIG([libpng_cflags], [cflags], [libpng])
60         _PKG_CONFIG([libpng_libs],   [libs],   [libpng])
61         if test x$pkg_failed = xyes; then
62                 errors=`$PKG_CONFIG --errors-to-stdout --print-errors libpng`
63                 echo "$errors" >&AS_MESSAGE_LOG_FD
64                 AC_MSG_RESULT([no])
65         else
66                 if test x"$LIBPNG_CFLAGS" = x; then
67                         LIBPNG_CFLAGS=$pkg_cv_libpng_cflags
68                 fi
69                 if test x"$LIBPNG_LIBS" = x; then
70                         LIBPNG_LIBS=$pkg_cv_libpng_libs
71                 fi
72
73                 AC_MSG_RESULT([yes])
74         fi
75 fi
76
77 if test x"$LIBPNG_LIBS" = x; then
78         LIBPNG_LIBS=-lpng
79 fi
80
81 AC_LANG_PUSH([C])
82 old_cflags=$CFLAGS
83 old_libs=$LIBS
84 CFLAGS="$LIBPNG_CFLAGS $CFLAGS"
85 LIBS="$LIBPNG_LIBS $LIBS"
86
87 _LIBPNG_TRY_VERSION(ifelse([$1], [], [1.0], [$1]))
88
89 CFLAGS=$old_cflags
90 LIBS=$old_libs
91 AC_LANG_POP([C])
92
93 if test x"$libpng_cv_sufficient_ver" = x"yes"; then
94         AC_SUBST([LIBPNG_CFLAGS])
95         AC_SUBST([LIBPNG_LIBS])
96         ifelse([$2], [], [true], [$2])
97 else
98         ifelse([$3], [], [AC_MSG_FAILURE([dnl
99 libpng version >= ifelse([$1], [], [1.0], [$1]) is required.  The latest
100 version can be obtained from http://libpng.org/pub/png/libpng.html.
101
102 If libpng is installed but was not found by this configure script,
103 consider adjusting LIBPNG_CFLAGS and/or LIBPNG_LIBS as necessary.
104
105 If pkg-config is installed, it may help to adjust PKG_CONFIG_PATH
106 if libpng is installed in a non-standard prefix.
107 ])], [$3])
108 fi
109 ])