]> git.draconx.ca Git - liblbx.git/blob - m4/libpng.m4
license: Fix copyright years in source files.
[liblbx.git] / m4 / libpng.m4
1 dnl Copyright (C) 2009-2010 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 shead='s/@<:@0-9@:>@@<:@0-9@:>@*/<<<&>>>/'
10 sbody='s/.*<<<\(.*\)>>>.*/\1/;t'
11 stail='s/.*/0/'
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 '
17         t
18         s/.*alpha.*/PNG_LIBPNG_BUILD_ALPHA/
19         t
20         s/.*beta.*/PNG_LIBPNG_BUILD_BETA/
21         t
22         s/.*rc.*/PNG_LIBPNG_BUILD_RC/
23         t
24         s/.*/PNG_LIBPNG_BUILD_STABLE/
25 '`
26
27 AC_CACHE_CHECK([for libpng version at least $1],
28         [libpng_cv_sufficient_ver],
29         [AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
30 #include <png.h>
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
45 #        endif
46 #      endif
47 #    endif
48 #  endif
49 #endif
50 ], [dnl
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])])
54 ])
55
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
61
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
69                 AC_MSG_RESULT([no])
70         else
71                 if test x"$LIBPNG_CFLAGS" = x; then
72                         LIBPNG_CFLAGS=$pkg_cv_libpng_cflags
73                 fi
74                 if test x"$LIBPNG_LIBS" = x; then
75                         LIBPNG_LIBS=$pkg_cv_libpng_libs
76                 fi
77
78                 AC_MSG_RESULT([yes])
79         fi
80 fi
81
82 if test x"$LIBPNG_LIBS" = x; then
83         LIBPNG_LIBS=-lpng
84 fi
85
86 AC_LANG_PUSH([C])
87 old_cflags=$CFLAGS
88 old_libs=$LIBS
89 CFLAGS="$LIBPNG_CFLAGS $CFLAGS"
90 LIBS="$LIBPNG_LIBS $LIBS"
91
92 _LIBPNG_TRY_VERSION(ifelse([$1], [], [1.0], [$1]))
93
94 CFLAGS=$old_cflags
95 LIBS=$old_libs
96 AC_LANG_POP([C])
97
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])
102 else
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.
106
107 If libpng is installed but was not found by this configure script,
108 consider adjusting LIBPNG_CFLAGS and/or LIBPNG_LIBS as necessary.
109
110 If pkg-config is installed, it may help to adjust PKG_CONFIG_PATH
111 if libpng is installed in a non-standard prefix.
112 ])], [$3])
113 fi
114 ])