Upstream tarball 20080512
[amule.git] / m4 / gdlib.m4
blob295050da6a88d01fe73744b5dd7ea80fa7d1e1bb
1 dnl ---------------------------------------------------------------------------
2 dnl AM_OPTIONS_GDLIBCONFIG
3 dnl
4 dnl adds support for --gdlib-prefix and --gdlib-config
5 dnl command line options
6 dnl ---------------------------------------------------------------------------
8 AC_DEFUN([AM_OPTIONS_GDLIBCONFIG],
10         AC_ARG_WITH(
11                 [gdlib-prefix],
12                 [AS_HELP_STRING(
13                         [--with-gdlib-prefix=PREFIX],
14                         [prefix where gdlib is installed (optional)])],
15                 [gdlib_config_prefix="$withval"],
16                 [gdlib_config_prefix=""])
17         AC_ARG_WITH(
18                 [gdlib-config],
19                 [AS_HELP_STRING(
20                         [--with-gdlib-config=CONFIG],
21                         [gdlib-config script to use (optional)])],
22                 [gdlib_config_name="$withval"],
23                 [gdlib_config_name=""])
26 dnl ---------------------------------------------------------------------------
27 dnl AM_PATH_GDLIBCONFIG([VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
28 dnl
29 dnl Test for gdlib, and define GDLIB*FLAGS, GDLIB_LIBS and GDLIB_CONFIG_NAME
30 dnl environment variable to override the default name of the gdlib-config script
31 dnl to use. Set GDLIB_CONFIG_PATH to specify the full path to gdlib-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_GDLIBCONFIG],
35 [AC_REQUIRE([AM_OPTIONS_GDLIBCONFIG])dnl
36 m4_define([REQUIRED_VERSION], [ifelse([$1],, [2.0.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 gdlib-config name: it can be gdlib-config or gd-config or ...
42   if test x${GDLIB_CONFIG_NAME+set} != xset ; then
43      GDLIB_CONFIG_NAME=gdlib-config
44   fi
45   if test "x$gdlib_config_name" != x ; then
46      GDLIB_CONFIG_NAME="$gdlib_config_name"
47   fi
49   dnl deal with optional prefix
50   if test x$gdlib_config_prefix != x ; then
51      GDLIB_LOOKUP_PATH="$gdlib_config_prefix/bin"
52   fi
53   
54   dnl don't search the PATH if GDLIB_CONFIG_NAME is absolute filename
55   if test -x "$GDLIB_CONFIG_NAME" ; then
56      AC_MSG_CHECKING(for gdlib-config)
57      GDLIB_CONFIG_PATH="$GDLIB_CONFIG_NAME"
58      AC_MSG_RESULT($GDLIB_CONFIG_PATH)
59   else
60      AC_PATH_PROG(GDLIB_CONFIG_PATH, $GDLIB_CONFIG_NAME, no, "$GDLIB_LOOKUP_PATH:$PATH")
61   fi
63   if test "$GDLIB_CONFIG_PATH" != "no" ; then
64     GDLIB_VERSION=""
66     AC_MSG_CHECKING([for gdlib version >= REQUIRED_VERSION])
68     GDLIB_CONFIG_WITH_ARGS="$GDLIB_CONFIG_PATH $gdlib_config_args"
70     GDLIB_VERSION=`$GDLIB_CONFIG_WITH_ARGS --version`
71     gdlib_config_major_version=`echo $GDLIB_VERSION | sed ['s/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/']`
72     gdlib_config_minor_version=`echo $GDLIB_VERSION | sed ['s/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/']`
73     gdlib_config_micro_version=`echo $GDLIB_VERSION | sed ['s/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/']`
75     gdlib_ver_ok=""
76     if test $gdlib_config_major_version -gt REQUIRED_VERSION_MAJOR; then
77       gdlib_ver_ok=yes
78     else
79       if test $gdlib_config_major_version -eq REQUIRED_VERSION_MAJOR; then
80          if test $gdlib_config_minor_version -gt REQUIRED_VERSION_MINOR; then
81             gdlib_ver_ok=yes
82          else
83             if test $gdlib_config_minor_version -eq REQUIRED_VERSION_MINOR; then
84                if test $gdlib_config_micro_version -ge REQUIRED_VERSION_MICRO; then
85                   gdlib_ver_ok=yes
86                fi
87             fi
88          fi
89       fi
90     fi
92     if test x$gdlib_ver_ok = x ; then
93       if test x$GDLIB_VERSION = x; then
94         dnl no gdlib-config at all
95         AC_MSG_RESULT([no])
96       else
97         AC_MSG_RESULT([no (version $GDLIB_VERSION is not new enough)])
98         GDLIB_VERSION=
99       fi
100       $3
101     else
102       AC_MSG_RESULT([yes (version $GDLIB_VERSION)])
103       AC_CHECK_HEADER([gd.h])
104       if test $ac_cv_header_gd_h = yes; then
105         GDLIB_CFLAGS="`$GDLIB_CONFIG_WITH_ARGS --cflags`"
106         GDLIB_LDFLAGS="`$GDLIB_CONFIG_WITH_ARGS --ldflags`"
107         GDLIB_LIBS="`$GDLIB_CONFIG_WITH_ARGS --libs`"
108         $2
109       else
110         GDLIB_VERSION=
111         $3
112       fi
113     fi
114   else
115     ifelse([$3],, :, [$3])
116   fi
118 AC_SUBST(GDLIB_CFLAGS)dnl
119 AC_SUBST(GDLIB_LDFLAGS)dnl
120 AC_SUBST(GDLIB_LIBS)dnl
122 m4_undefine([REQUIRED_VERSION])dnl
123 m4_undefine([REQUIRED_VERSION_MAJOR])dnl
124 m4_undefine([REQUIRED_VERSION_MINOR])dnl
125 m4_undefine([REQUIRED_VERSION_MICRO])dnl