]> git.draconx.ca Git - dxcommon.git/blob - m4/libpng.m4
Add libpng detection macro.
[dxcommon.git] / m4 / libpng.m4
1 dnl Copyright © 2009-2010, 2014 Nick Bowler
2 dnl
3 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
4 dnl This is free software: you are free to do what the fuck you want to.
5 dnl There is NO WARRANTY, to the extent permitted by law.
6
7 dnl DX_LIB_LIBPNG([min-version], [action-if-ok], [acton-if-failed])
8 dnl
9 dnl Search for a suitable libpng.  If min-version is non-empty, the test will
10 dnl attempt to reject a libpng installation which is older than the specified
11 dnl version number (as determined by the libpng header file).
12 dnl
13 dnl If a working library is found, appropriate compiler and linker flags
14 dnl are stored in LIBPNG_CFLAGS and LIBPNG_LIBS, respectively, and the
15 dnl action-if-ok is performed (may be empty).  If no such library is found,
16 dnl then action-if-failed is performed if non-empty; otherwise configure will
17 dnl stop with a fatal error.
18 AC_DEFUN([DX_LIB_LIBPNG], [dnl
19 DX_LIB_SETUP([libpng])dnl
20 DX_LIB_PKGCONFIG_FLAGS([libpng])
21 AC_MSG_CHECKING([for libpng[]m4_ifnblank([$1], [ at least version $1])])
22 DX_LIB_SEARCH_LINK([libpng],
23         [m4_apply([_DX_LIB_LIBPNG_TEST], m4_split([$1], [\.]))],
24         [
25                 [[$LIBPNG_CFLAGS], [$LIBPNG_LIBS]],
26                 [[$dx_cv_libpng_pkg_cflags], [$dx_cv_libpng_pkg_libs],
27                         [test x"$dx_cv_libpng_pkg_found" = x"yes"]],
28                 [[], [-lpng]],
29         ])
30 AS_IF([test x"$dx_cv_libpng_lib_found" = x"yes"], [$2],
31         [m4_default([$3], [AC_MSG_FAILURE([dnl
32 libpng[]m4_ifnblank([$1], [ version $1 or newer]) is required.  The latest
33 version may be found at <http://libpng.org/pub/png/libpng.html>.
34 m4_newline([DX_LIB_USERFLAG_BLURB([libpng])])
35 m4_newline([DX_LIB_PKGCONFIG_BLURB([libpng])])
36 ])])])])
37
38 dnl Internal test program for libpng.  Check that the version numbers in the
39 dnl header are sufficient and that some important functions are defined.
40 m4_define([_DX_LIB_LIBPNG_TEST], [AC_LANG_PROGRAM([dnl
41 #include <png.h>
42 m4_ifnblank([$1], [dnl
43 #if PNG_LIBPNG_VER_MAJOR < $1
44 DX_LIB_COMPILE_ERROR([major version insufficient])
45 m4_ifnblank([$2], [dnl
46 #elif PNG_LIBPNG_VER_MAJOR == $1
47 #  if PNG_LIBPNG_VER_MINOR < $2
48 DX_LIB_COMPILE_ERROR([minor version insufficient])
49 m4_ifnblank([$3], [dnl
50 #  elif PNG_LIBPNG_VER_MINOR == $2
51 #    if PNG_LIBPNG_VER_RELEASE < $3
52 DX_LIB_COMPILE_ERROR([release version insufficient])
53 #    endif
54 ])dnl
55 #  endif
56 ])dnl
57 #endif
58 ])], [dnl
59 png_structp png = png_create_read_struct("", 0, 0, 0);
60 png_infop info = png_create_info_struct(png);
61 png_destroy_read_struct(&png, &info, 0);
62 ])])