1 dnl Check to find the zlib headers/libraries
3 AC_DEFUN([AM_PATH_LIBPNG],
5 AC_ARG_WITH(libpng-exec-prefix,[ --with-libpng-exec-prefix=PFX Exec prefix where libpng-config is installed (optional)],
6 libpng_exec_prefix="$withval", libpng_exec_prefix="")
8 if test "x${LIBPNG_CONFIG+set}" != xset ; then
9 if test "x$libpng_exec_prefix" != x ; then
10 LIBPNG_CONFIG="$libpng_exec_prefix/bin/libpng-config"
14 AC_PATH_PROG(LIBPNG_CONFIG, libpng-config, no)
15 min_libpng_version=ifelse([$1], ,1.2.12,$1)
16 AC_MSG_CHECKING(for libpng - version >= $min_libpng_version)
18 if test "$LIBPNG_CONFIG" = "no" ; then
21 LIBPNG_CFLAGS=`$LIBPNG_CONFIG --cflags`
22 LIBPNG_LIBS=`$LIBPNG_CONFIG --libs`
24 libpng_major_version=`$LIBPNG_CONFIG --version | \
25 sed 's/^\([[0-9]]*\).*/\1/'`
26 if test "x${libpng_major_version}" = "x" ; then
27 libpng_major_version=0
30 libpng_minor_version=`$LIBPNG_CONFIG --version | \
31 sed 's/^\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\).*/\2/'`
32 if test "x${libpng_minor_version}" = "x" ; then
33 libpng_minor_version=0
36 libpng_micro_version=`$LIBPNG_CONFIG --version | \
37 sed 's/^\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\).*/\3/'`
38 if test "x${libpng_micro_version}" = "x" ; then
39 libpng_micro_version=0
42 ac_save_CFLAGS="$CFLAGS"
44 CFLAGS="$CFLAGS $LIBPNG_CFLAGS"
45 LIBS="$LIBS $LIBPNG_LIBS"
53 char* my_strdup (const char *str);
56 my_strdup (const char *str)
62 new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
63 strcpy (new_str, str);
73 int major = 0, minor = 0, micro = 0;
77 system ("touch conf.libpngtest");
79 /* HP/UX 9 (%@#!) writes to sscanf strings */
80 tmp_version = my_strdup("$min_libpng_version");
82 n = sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) ;
84 if (n != 2 && n != 3) {
85 printf("%s, bad version string\n", "$min_libpng_version");
89 if (($libpng_major_version > major) ||
90 (($libpng_major_version == major) && ($libpng_minor_version > minor)) ||
91 (($libpng_major_version == major) && ($libpng_minor_version == minor) && ($libpng_micro_version >= micro)))
97 printf("\n*** 'libpng-config --version' returned %d.%d.%d, but the minimum version\n", $libpng_major_version, $libpng_minor_version, $libpng_micro_version);
98 printf("*** of libpng required is %d.%d.%d. If libpng-config is correct, then it is\n", major, minor, micro);
99 printf("*** best to upgrade to the required version.\n");
100 printf("*** If libpng-config was wrong, set the environment variable LIBPNG_CONFIG\n");
101 printf("*** to point to the correct copy of libpng-config, and remove the file\n");
102 printf("*** config.cache before re-running configure\n");
106 ],, no_libpng=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
107 CFLAGS="$ac_save_CFLAGS"
110 if test "x$no_libpng" = x ; then
111 AC_DEFINE_UNQUOTED(HAVE_LIBPNG, true, [Define to true if libpng is installed])
114 ifelse([$2], , :, [$2])
118 if test "$LIBPNG_CONFIG" = "no" ; then
119 echo "*** The libpng-config script installed with libpng could not be found"
120 echo "*** If libpng was installed in PREFIX, make sure PREFIX/bin is in your path,"
121 echo "*** or use the --with-libpng-exec-prefix=PFX option to configure."
122 echo "*** You may also set the LIBPNG_CONFIG environment variable to the full path"
123 echo "*** to libpng-config."
125 if test -f conf.libpngtest ; then
128 echo "*** Could not run libpng test program, checking why..."
129 CFLAGS="$CFLAGS $LIBPNG_CFLAGS"
130 LIBS="$LIBS $LIBPNG_LIBS"
134 [ echo "*** The test program compiled, but did not run. This usually means"
135 echo "*** that the run-time linker is not finding libpng or finding the wrong"
136 echo "*** version of libpng. If it is not finding libpng, you'll need to set your"
137 echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
138 echo "*** to the installed location Also, make sure you have run ldconfig if that"
139 echo "*** is required on your system"
141 echo "*** If you have an old version installed, it is best to remove it, although"
142 echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
143 [ echo "*** The test program failed to compile or link. See the file config.log for the"
144 echo "*** exact error that occured. This usually means libpng was incorrectly installed"
145 echo "*** or that you have moved libpng since it was installed. In the latter case, you"
146 echo "*** may want to edit the libpng-config script: $LIBPNG_CONFIG" ])
147 CFLAGS="$ac_save_CFLAGS"
153 ifelse([$3], , :, [$3])
155 AC_SUBST(HAVE_LIBPNG)
156 AC_SUBST(LIBPNG_CFLAGS)
157 AC_SUBST(LIBPNG_LIBS)
158 rm -f conf.libpngtest