debian: fix build-deps for focal
[amule.git] / m4 / libpng.m4
blob87feca4fb1ee4f7ed38c28afc44ae12b8459a3b2
1 #                                                       -*- Autoconf -*-
2 # This file is part of the aMule Project.
4 # Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
6 # Any parts of this program derived from the xMule, lMule or eMule project,
7 # or contributed by third-party developers are copyrighted by their
8 # respective authors.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
25 dnl ---------------------------------------------------------------------------
26 dnl MULE_CHECK_LIBPNG([VERSION = 1.2.0], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
27 dnl
28 dnl adds support for --with-libpng-prefix and --with-libpng-config
29 dnl command line options
30 dnl
31 dnl Test for libpng, and define LIBPNG_CFLAGS, LIBPNG_LIBS and LIBPNG_CONFIG_NAME
32 dnl environment variable to override the default name of the libpng-config script
33 dnl to use. Set LIBPNG_CONFIG_PATH to specify the full path to libpng-config -
34 dnl in this case the macro won't even waste time on tests for its existence.
35 dnl ---------------------------------------------------------------------------
36 AC_DEFUN([MULE_CHECK_LIBPNG],
37 [dnl
38 m4_define([REQUIRED_VERSION], [m4_ifval([$1], [$1], [1.2.0])])dnl
39 m4_define([REQUIRED_VERSION_MAJOR], [m4_bregexp(REQUIRED_VERSION, [\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)], [\1])])dnl
40 m4_define([REQUIRED_VERSION_MINOR], [m4_bregexp(REQUIRED_VERSION, [\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)], [\2])])dnl
41 m4_define([REQUIRED_VERSION_MICRO], [m4_bregexp(REQUIRED_VERSION, [\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)], [\3])])dnl
43         AC_ARG_WITH([libpng-prefix], [AS_HELP_STRING([--with-libpng-prefix=PREFIX], [prefix where libpng is installed (optional)])])
44         AC_ARG_WITH([libpng-config], [AS_HELP_STRING([--with-libpng-config=CONFIG], [libpng-config script to use (optional)])])
46         LIBPNG_VERSION=
48         # do we have libpng-config name: it can be libpng-config or libpng12-config or ...
49         AS_IF([test x${LIBPNG_CONFIG_NAME+set} != xset], [LIBPNG_CONFIG_NAME=libpng-config])
50         AS_IF([test -n "$with_libpng_config"], [LIBPNG_CONFIG_NAME="$with_libpng_config"])
52         # deal with optional prefix
53         AS_IF([test -n "$with_libpng_prefix"], [LIBPNG_LOOKUP_PATH="$with_libpng_prefix/bin"])
55         # don't search the PATH if LIBPNG_CONFIG_NAME is absolute filename
56         AS_IF([test -x "$LIBPNG_CONFIG_NAME"], [
57                 AC_MSG_CHECKING([for libpng-config])
58                 LIBPNG_CONFIG_PATH="$LIBPNG_CONFIG_NAME"
59                 AC_MSG_RESULT($LIBPNG_CONFIG_PATH)
60         ], [AC_PATH_PROG([LIBPNG_CONFIG_PATH], [$LIBPNG_CONFIG_NAME], [no], [$LIBPNG_LOOKUP_PATH:$PATH])])
62         AS_IF([test ${LIBPNG_CONFIG_PATH:-no} != no],
63         [
64                 AC_MSG_CHECKING([for libpng version >= REQUIRED_VERSION])
66                 LIBPNG_CONFIG_WITH_ARGS="$LIBPNG_CONFIG_PATH $libpng_config_args"
68                 LIBPNG_VERSION=`$LIBPNG_CONFIG_WITH_ARGS --version`
69                 libpng_config_major_version=`echo $LIBPNG_VERSION | sed ['s/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/']`
70                 libpng_config_minor_version=`echo $LIBPNG_VERSION | sed ['s/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/']`
71                 libpng_config_micro_version=`echo $LIBPNG_VERSION | sed ['s/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/']`
73                 libpng_ver_ok=
74                 MULE_IF([test $libpng_config_major_version -gt REQUIRED_VERSION_MAJOR], [libpng_ver_ok=yes],
75                         [test $libpng_config_major_version -eq REQUIRED_VERSION_MAJOR], [
76                                 MULE_IF([test $libpng_config_minor_version -gt REQUIRED_VERSION_MINOR], [libpng_ver_ok=yes],
77                                         [test $libpng_config_minor_version -eq REQUIRED_VERSION_MINOR],
78                                                 [MULE_IF([test $libpng_config_micro_version -ge REQUIRED_VERSION_MICRO], [libpng_ver_ok=yes])])
79                         ])
81                 AS_IF([test -z "$libpng_ver_ok"], [
82                         AS_IF([test -z "$LIBPNG_VERSION"], [AC_MSG_RESULT([no])], [
83                                 AC_MSG_RESULT([no (version $LIBPNG_VERSION is not new enough)])
84                                 LIBPNG_VERSION=
85                         ])
86                 ], [
87                         LIBPNG_LIBS=`$LIBPNG_CONFIG_WITH_ARGS --libs`
88                         LIBPNG_LDFLAGS=`$LIBPNG_CONFIG_WITH_ARGS --ldflags | sed -e "s/ *${LIBPNG_LIBS}$//"`
89                         LIBPNG_CFLAGS=`$LIBPNG_CONFIG_WITH_ARGS --cflags`
90                         AC_MSG_RESULT([yes (version $LIBPNG_VERSION)])
92                         AC_MSG_CHECKING([if libpng is usable])
94                         SAVED_CFLAGS=$CFLAGS
95                         SAVED_LDFLAGS=$LDFLAGS
96                         SAVED_LIBS=$LIBS
98                         CFLAGS="$CFLAGS $LIBPNG_CFLAGS"
99                         LDFLAGS="$LDFLAGS $LIBPNG_LDFLAGS"
100                         LIBS="$LIBS $LIBPNG_LIBS"
102                         AC_LINK_IFELSE([
103                                 AC_LANG_PROGRAM([[
104                                         #include <png.h>
105                                         #include <stdio.h>
106                                 ]], [[
107                                         png_uint_32 libpng_vn = png_access_version_number();
108                                         printf("\nlibpng version %i\n\n", libpng_vn);
109                                 ]])
110                         ], [
111                                 AC_MSG_RESULT([yes])
112                         ],
113                         [
114                                 AC_MSG_RESULT([no (failed to compile and link test program)])
115                                 LIBPNG_LIBS=
116                                 LIBPNG_LDFLAGS=
117                                 LIBPNG_CFLAGS=
118                                 LIBPNG_VERSION=
119                         ])
121                         CFLAGS="$SAVED_CFLAGS"
122                         LDFLAGS="$SAVED_LDFLAGS"
123                         LIBS="$SAVED_LIBS"
124                 ])
125         ])
127         AS_IF([test -n "$LIBPNG_VERSION"], [$2], [$3])
129 AC_SUBST([LIBPNG_CFLAGS])dnl
130 AC_SUBST([LIBPNG_LDFLAGS])dnl
131 AC_SUBST([LIBPNG_LIBS])dnl
133 m4_undefine([REQUIRED_VERSION])dnl
134 m4_undefine([REQUIRED_VERSION_MAJOR])dnl
135 m4_undefine([REQUIRED_VERSION_MINOR])dnl
136 m4_undefine([REQUIRED_VERSION_MICRO])dnl