1 dnl ---------------------------------------------------------------------------
2 dnl AM_OPTIONS_LIBPNG_CONFIG
4 dnl adds support for --libpng-prefix and --libpng-config
5 dnl command line options
6 dnl ---------------------------------------------------------------------------
8 AC_DEFUN([AM_OPTIONS_LIBPNGCONFIG],
13 [--with-libpng-prefix=PREFIX],
14 [prefix where libpng is installed (optional)])],
15 [libpng_config_prefix="$withval"],
16 [libpng_config_prefix=""])
20 [--with-libpng-config=CONFIG],
21 [libpng-config script to use (optional)])],
22 [libpng_config_name="$withval"],
23 [libpng_config_name=""])
26 dnl ---------------------------------------------------------------------------
27 dnl AM_PATH_LIBPNGCONFIG([VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
29 dnl Test for libpng, and define LIBPNG*FLAGS, LIBPNG_LIBS and LIBPNG_CONFIG_NAME
30 dnl environment variable to override the default name of the libpng-config script
31 dnl to use. Set LIBPNG_CONFIG_PATH to specify the full path to libpng-config -
32 dnl in this case the macro won't even waste time on tests for its existence.
33 dnl ---------------------------------------------------------------------------
34 AC_DEFUN([AM_PATH_LIBPNGCONFIG],
35 [AC_REQUIRE([AM_OPTIONS_LIBPNGCONFIG])dnl
36 m4_define([REQUIRED_VERSION], [ifelse([$1],, [1.2.0], [$1])])dnl
37 m4_define([REQUIRED_VERSION_MAJOR], [m4_bregexp(REQUIRED_VERSION, [\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)], [\1])])dnl
38 m4_define([REQUIRED_VERSION_MINOR], [m4_bregexp(REQUIRED_VERSION, [\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)], [\2])])dnl
39 m4_define([REQUIRED_VERSION_MICRO], [m4_bregexp(REQUIRED_VERSION, [\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)], [\3])])dnl
41 dnl do we have libpng-config name: it can be libpng-config or libpng12-config or ...
42 if test x${LIBPNG_CONFIG_NAME+set} != xset ; then
43 LIBPNG_CONFIG_NAME=libpng-config
45 if test "x$libpng_config_name" != x ; then
46 LIBPNG_CONFIG_NAME="$libpng_config_name"
49 dnl deal with optional prefix
50 if test x$libpng_config_prefix != x ; then
51 LIBPNG_LOOKUP_PATH="$libpng_config_prefix/bin"
54 dnl don't search the PATH if LIBPNG_CONFIG_NAME is absolute filename
55 if test -x "$LIBPNG_CONFIG_NAME" ; then
56 AC_MSG_CHECKING(for libpng-config)
57 LIBPNG_CONFIG_PATH="$LIBPNG_CONFIG_NAME"
58 AC_MSG_RESULT($LIBPNG_CONFIG_PATH)
60 AC_PATH_PROG(LIBPNG_CONFIG_PATH, $LIBPNG_CONFIG_NAME, no, "$LIBPNG_LOOKUP_PATH:$PATH")
63 if test "$LIBPNG_CONFIG_PATH" != "no" ; then
66 AC_MSG_CHECKING([for libpng version >= REQUIRED_VERSION])
68 LIBPNG_CONFIG_WITH_ARGS="$LIBPNG_CONFIG_PATH $libpng_config_args"
70 LIBPNG_VERSION=`$LIBPNG_CONFIG_WITH_ARGS --version`
71 libpng_config_major_version=`echo $LIBPNG_VERSION | sed ['s/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/']`
72 libpng_config_minor_version=`echo $LIBPNG_VERSION | sed ['s/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/']`
73 libpng_config_micro_version=`echo $LIBPNG_VERSION | sed ['s/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/']`
76 if test $libpng_config_major_version -gt REQUIRED_VERSION_MAJOR; then
79 if test $libpng_config_major_version -eq REQUIRED_VERSION_MAJOR; then
80 if test $libpng_config_minor_version -gt REQUIRED_VERSION_MINOR; then
83 if test $libpng_config_minor_version -eq REQUIRED_VERSION_MINOR; then
84 if test $libpng_config_micro_version -ge REQUIRED_VERSION_MICRO; then
92 if test x$libpng_ver_ok = x ; then
93 if test x$LIBPNG_VERSION = x; then
94 dnl '$LIBPNG_CONFIG_WITH_ARGS --version' didn't produce output
97 AC_MSG_RESULT([no (version $LIBPNG_VERSION is not new enough)])
106 LIBPNG_LIBS=`$LIBPNG_CONFIG_WITH_ARGS --libs`
107 LIBPNG_LDFLAGS=`$LIBPNG_CONFIG_WITH_ARGS --ldflags | sed -e "s/ *${LIBPNG_LIBS}$//"`
108 LIBPNG_CFLAGS=`$LIBPNG_CONFIG_WITH_ARGS --cflags`
109 LIBPNG_CXXFLAGS=$LIBPNG_CFLAGS
110 AC_MSG_RESULT([yes (version $LIBPNG_VERSION)])
115 dnl Some RedHat RPMs miss libpng-config, so test for
116 dnl the usability with default options.
117 AC_MSG_CHECKING([for libpng >= REQUIRED_VERSION])
118 dnl Set up LIBS for the test
120 LIBS="$LIBS -lpng -lz -lm"
121 dnl Set default (empty) values.
131 /* Check linking to png library */
133 png_check_sig(NULL, 0);
135 ]], [dnl Don't use double-quoting here!
136 /* png.h defines PNG_LIBPNG_VER=xyyzz */
137 FILE *f=fopen("conftestval", "w");
139 fprintf(f, "%s", (PNG_LIBPNG_VER >= REQUIRED_VERSION_MAJOR * 10000 + REQUIRED_VERSION_MINOR * 100 + REQUIRED_VERSION_MICRO) ? "yes" : "no");
141 f=fopen("conftestver", "w");
143 fprintf(f, "%s", PNG_LIBPNG_VER_STRING);
148 AS_IF([test -f conftestval], [result=`cat conftestval`], [result=no])
149 if test x$result = xyes; then
150 if test -f conftestver; then
151 LIBPNG_VERSION=`cat conftestver`
152 lib_version=" (version $LIBPNG_VERSION)"
157 AC_MSG_RESULT([$result$lib_version])
158 LIBPNG_LIBS="-lpng -lz -lm"
161 AC_MSG_RESULT([$result])
163 AC_MSG_RESULT([cross-compilation detected, checking only the header])
164 AC_CHECK_HEADER([png.h], [result=yes], [result=no])
165 if test x$result = xyes; then
166 LIBPNG_VERSION="detected"
167 LIBPNG_LIBS="-lpng -lz -lm"
170 AS_IF([test x$result = xyes], [$2], [$3])
175 AC_SUBST(LIBPNG_CFLAGS)dnl
176 AC_SUBST(LIBPNG_CXXFLAGS)dnl
177 AC_SUBST(LIBPNG_LDFLAGS)dnl
178 AC_SUBST(LIBPNG_LIBS)dnl
180 m4_undefine([REQUIRED_VERSION])dnl
181 m4_undefine([REQUIRED_VERSION_MAJOR])dnl
182 m4_undefine([REQUIRED_VERSION_MINOR])dnl
183 m4_undefine([REQUIRED_VERSION_MICRO])dnl