debian: fix build-deps for focal
[amule.git] / m4 / gdlib.m4
blob6b81b2d531d090791fad3265f989ddc4b915ae33
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_GDLIB([VERSION = 2.0.0], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
27 dnl
28 dnl adds support for --with-gdlib-prefix and --with-gdlib-config
29 dnl command line options
30 dnl
31 dnl Test for gdlib, and define GDLIB_CFLAGS, GDLIB_LIBS and GDLIB_CONFIG_NAME
32 dnl environment variable to override the default name of the gdlib-config script
33 dnl to use. Set GDLIB_CONFIG_PATH to specify the full path to gdlib-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_GDLIB],
37 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
39 m4_define([REQUIRED_VERSION], [m4_ifval([$1], [$1], [2.0.0])])dnl
40 m4_define([REQUIRED_VERSION_MAJOR], [m4_bregexp(REQUIRED_VERSION, [\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)], [\1])])dnl
41 m4_define([REQUIRED_VERSION_MINOR], [m4_bregexp(REQUIRED_VERSION, [\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)], [\2])])dnl
42 m4_define([REQUIRED_VERSION_MICRO], [m4_bregexp(REQUIRED_VERSION, [\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)], [\3])])dnl
44         AC_ARG_WITH([gdlib-prefix], [AS_HELP_STRING([--with-gdlib-prefix=PREFIX], [prefix where gdlib is installed (optional)])])
45         AC_ARG_WITH([gdlib-config], [AS_HELP_STRING([--with-gdlib-config=CONFIG], [gdlib-config script to use (optional)])])
47         GDLIB_VERSION=
49         # Check gdlib in pkg-config first to avoid deprecation warnings
50         # If --with-gdlib-config or --with-gdlib-prefix was given, then
51         # skip the pkg-config check, the user probably wants to use
52         # another gdlib instance.
53         AS_IF([test -z "${with_gdlib_config:-}${with_gdlib_prefix:-}"], [
54                 AS_IF([test -n "$PKG_CONFIG"], [
55                         AC_MSG_CHECKING([for gdlib])
57                         AS_IF([$PKG_CONFIG gdlib --exists], [
58                                 GDLIB_VERSION=`$PKG_CONFIG gdlib --modversion`
60                                 AS_IF([$PKG_CONFIG gdlib --atleast-version=REQUIRED_VERSION], [
61                                         AC_MSG_RESULT([yes (version $GDLIB_VERSION)])
62                                         GDLIB_CFLAGS=`$PKG_CONFIG gdlib --cflags`
63                                         GDLIB_LDFLAGS=`$PKG_CONFIG gdlib --libs-only-L`
64                                         GDLIB_LIBS=`$PKG_CONFIG gdlib --libs-only-other`
65                                         GDLIB_LIBS="$GDLIB_LIBS `$PKG_CONFIG gdlib --libs-only-l`"
66                                 ], [
67                                         AC_MSG_RESULT([no (version $GDLIB_VERSION is not new enough)])
68                                         GDLIB_VERSION=
69                                 ])
70                         ], [
71                                 AC_MSG_RESULT([no])
72                         ])
73                 ])
74         ])
76         # Try gdlib-config if we did not find a sufficient gdlib version in pkg-config
77         AS_IF([test -z "$GDLIB_VERSION"], [
78                 # do we have gdlib-config name: it can be gdlib-config or gd-config or ...
79                 AS_IF([test x${GDLIB_CONFIG_NAME+set} != xset], [GDLIB_CONFIG_NAME=gdlib-config])
80                 AS_IF([test -n "$with_gdlib_config"], [GDLIB_CONFIG_NAME="$with_gdlib_config"])
82                 # deal with optional prefix
83                 AS_IF([test -n "$with_gdlib_prefix"], [GDLIB_LOOKUP_PATH="$with_gdlib_prefix/bin"])
85                 # don't search the PATH if GDLIB_CONFIG_NAME is absolute filename
86                 AS_IF([test -x "$GDLIB_CONFIG_NAME"], [
87                         AC_MSG_CHECKING([for gdlib-config])
88                         GDLIB_CONFIG_PATH="$GDLIB_CONFIG_NAME"
89                         AC_MSG_RESULT([$GDLIB_CONFIG_PATH])
90                 ], [AC_PATH_PROG([GDLIB_CONFIG_PATH], [$GDLIB_CONFIG_NAME], [no], [$GDLIB_LOOKUP_PATH:$PATH])])
92                 AS_IF([test ${GDLIB_CONFIG_PATH:-no} != no], [
93                         AC_MSG_CHECKING([for gdlib version >= REQUIRED_VERSION])
94                         GDLIB_CONFIG_WITH_ARGS="$GDLIB_CONFIG_PATH $gdlib_config_args"
96                         GDLIB_VERSION=`$GDLIB_CONFIG_WITH_ARGS --version`
97                         gdlib_config_major_version=`echo $GDLIB_VERSION | sed ['s/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/']`
98                         gdlib_config_minor_version=`echo $GDLIB_VERSION | sed ['s/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/']`
99                         gdlib_config_micro_version=`echo $GDLIB_VERSION | sed ['s/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/']`
101                         MULE_IF([test $gdlib_config_major_version -gt REQUIRED_VERSION_MAJOR], [gdlib_ver_ok=yes],
102                                 [test $gdlib_config_major_version -eq REQUIRED_VERSION_MAJOR], [
103                                         MULE_IF([test $gdlib_config_minor_version -gt REQUIRED_VERSION_MINOR], [gdlib_ver_ok=yes],
104                                                 [test $gdlib_config_minor_version -eq REQUIRED_VERSION_MINOR],
105                                                         [MULE_IF([test $gdlib_config_micro_version -ge REQUIRED_VERSION_MICRO], [gdlib_ver_ok=yes])])
106                                 ])
107                 ])
109                 AS_IF([test -z "${gdlib_ver_ok:-}"], [
110                         AS_IF([test -z "$GDLIB_VERSION"], [AC_MSG_RESULT([no])], [
111                                 AC_MSG_RESULT([no (version $GDLIB_VERSION is not new enough)])
112                                 GDLIB_VERSION=
113                         ])
114                 ], [
115                         AC_MSG_RESULT([yes (version $GDLIB_VERSION)])
116                         GDLIB_CFLAGS="`$GDLIB_CONFIG_WITH_ARGS --cflags`"
117                         GDLIB_LDFLAGS="`$GDLIB_CONFIG_WITH_ARGS --ldflags`"
118                         GDLIB_LIBS="`$GDLIB_CONFIG_WITH_ARGS --libs`"
119                 ])
120         ])
122         AS_IF([test -n "$GDLIB_VERSION"], [
123                 MULE_BACKUP([CFLAGS])
124                 MULE_APPEND([CFLAGS], [$GDLIB_CFLAGS])
126                 AC_CHECK_HEADER([gd.h],, [
127                         GDLIB_CFLAGS=
128                         GDLIB_LDFLAGS=
129                         GDLIB_LIBS=
130                         GDLIB_VERSION=
131                 ])
133                 MULE_RESTORE([CFLAGS])
134         ])
136         AS_IF([test -n "$GDLIB_VERSION"], [$2], [$3])
138 AC_SUBST([GDLIB_CFLAGS])dnl
139 AC_SUBST([GDLIB_LDFLAGS])dnl
140 AC_SUBST([GDLIB_LIBS])dnl
142 m4_undefine([REQUIRED_VERSION])dnl
143 m4_undefine([REQUIRED_VERSION_MAJOR])dnl
144 m4_undefine([REQUIRED_VERSION_MINOR])dnl
145 m4_undefine([REQUIRED_VERSION_MICRO])dnl