]> Pileus Git - ~andy/fetchmail/blob - m4-local/ac_ma_search_package.m4
Update website for 6.3.24.
[~andy/fetchmail] / m4-local / ac_ma_search_package.m4
1 dnl @synopsis AC_ma_SEARCH_PACKAGE(PACKAGE, FUNCTION, PREFIX LIST, LIBRARY LIST, HEADERFILE [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
2 dnl based on AC_caolan_SEARCH_PACKAGE
3 dnl
4 dnl Provides --with-PACKAGE, --with-PACKAGE-include and --with-PACKAGE-libdir
5 dnl options to configure. Supports the now standard --with-PACKAGE=DIR
6 dnl approach where the package's include dir and lib dir are underneath DIR,
7 dnl but also allows the include and lib directories to be specified seperately
8 dnl
9 dnl PREFIX LIST can be a list of directories to search for the package
10 dnl if set to "no", the package must be enabled with --with-PACKAGE
11 dnl otherwise it is enabled unless overridden with --without-PACKAGE
12 dnl
13 dnl adds the extra -Ipath to CFLAGS if needed
14 dnl adds extra -Lpath to LD_FLAGS if needed
15 dnl searches for the FUNCTION in each of the LIBRARY LIST with
16 dnl AC_SEARCH_LIBRARY and thus adds the lib to LIBS
17 dnl
18 dnl defines HAVE_PKG_PACKAGE if it is found, (where PACKAGE in the
19 dnl HAVE_PKG_PACKAGE is replaced with the actual first parameter passed)
20 dnl note that autoheader will complain of not having the HAVE_PKG_PACKAGE and you
21 dnl will have to add it to acconfig.h manually
22 dnl
23 dnl @version $Id: ac_caolan_search_package.m4,v 1.3 2003/10/29 02:13:06 guidod Exp $
24 dnl @author Caolan McNamara <caolan@skynet.ie>
25 dnl
26 dnl with fixes from...
27 dnl Alexandre Duret-Lutz <duret_g@lrde.epita.fr>
28 dnl Matthew Mueller <donut@azstarnet.com>
29 dnl Matthias Andree <matthias.andree@gmx.de>
30
31 AC_PREREQ(2.59)dnl oldest tested version
32
33 AC_DEFUN([AC_ma_SEARCH_PACKAGE],
34 [
35
36 search="$3"
37 AC_ARG_WITH($1,
38 AS_HELP_STRING([--without-$1],[disables $1 usage completely])
39 AS_HELP_STRING([--with-$1[=DIR]],[root directory of $1 installation]),
40 if test "${with_$1}" != yes; then
41         search="$withval"
42         $1_winclude="$withval/include"
43         $1_wlibdir="$withval/lib"
44 fi
45 )
46
47 AC_ARG_WITH($1-include,
48 AS_HELP_STRING([--with-$1-include=DIR],[specify exact include dir for $1 headers]),
49 $1_winclude="$withval")
50
51 AC_ARG_WITH($1-libdir,
52 AS_HELP_STRING([--with-$1-libdir=DIR],[specify exact library dir for $1 library]),
53 $1_wlibdir="$withval")
54
55 if test "${with_$1}" != no ; then
56     for i in $search ; do
57         if test "$search" = "${with_$1}" ; then
58             $1_include="${$1_winclude}"
59             $1_libdir="${$1_wlibdir}"
60         else
61             $1_include=$i/include
62             $1_libdir=$i/lib
63         fi
64
65         if test ! -f "${$1_include}/$5" -o ! -d "${$1_libdir}" ; then
66             continue
67         fi
68
69         OLD_LIBS=$LIBS
70         OLD_LDFLAGS=$LDFLAGS
71         OLD_CFLAGS=$CFLAGS
72         OLD_CPPFLAGS=$CPPFLAGS
73
74         if test -n "${$1_libdir}" -a "${$1_libdir}" != /usr/lib ; then
75                 LDFLAGS="$LDFLAGS -L${$1_libdir}"
76         fi
77         if test -n "${$1_include}" -a "${$1_include}" != /usr/include ; then
78                 CPPFLAGS="$CPPFLAGS -I${$1_include}"
79         fi
80
81         success=no
82         AC_SEARCH_LIBS($2,$4,success=yes)
83         AC_CHECK_HEADERS($5,,success=no)
84         if test "$success" = yes; then
85 dnl     fixed
86                 ifelse([$6], , , [$6])
87                 AC_DEFINE(HAVE_PKG_$1,1,[Define to 1 if you have the '$1' package.])
88                 break
89         else
90                 LIBS=$OLD_LIBS
91                 LDFLAGS=$OLD_LDFLAGS
92                 CPPFLAGS=$OLD_CPPFLAGS
93                 CFLAGS=$OLD_CFLAGS
94         fi
95     done
96     if test "$success" = no ; then
97 dnl     broken
98     ifelse([$7], , , [$7])
99         LIBS=$OLD_LIBS
100         LDFLAGS=$OLD_LDFLAGS
101         CPPFLAGS=$OLD_CPPFLAGS
102         CFLAGS=$OLD_CFLAGS
103     fi
104 fi
105
106 ])