]> Pileus Git - ~andy/fetchmail/blob - m4-local/ac_ma_search_package.m4
Reset LIBS/LDFLAGS/CPPFLAGS/CFLAGS before trying next path prefix.
[~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         OLD_LIBS=$LIBS
66         OLD_LDFLAGS=$LDFLAGS
67         OLD_CFLAGS=$CFLAGS
68         OLD_CPPFLAGS=$CPPFLAGS
69
70         if test "${$1_libdir}" ; then
71                 LDFLAGS="$LDFLAGS -L${$1_libdir}"
72         fi
73         if test "${$1_include}" ; then
74                 CPPFLAGS="$CPPFLAGS -I${$1_include}"
75                 CFLAGS="$CFLAGS -I${$1_include}"
76         fi
77
78         success=no
79         AC_SEARCH_LIBS($2,$4,success=yes)
80         AC_CHECK_HEADERS($5,,success=no)
81         if test "$success" = yes; then
82 dnl     fixed
83                 ifelse([$6], , , [$6])
84                 AC_DEFINE(HAVE_PKG_$1,1,[Define to 1 if you have the '$1' package.])
85                 break
86         else
87                 LIBS=$OLD_LIBS
88                 LDFLAGS=$OLD_LDFLAGS
89                 CPPFLAGS=$OLD_CPPFLAGS
90                 CFLAGS=$OLD_CFLAGS
91         fi
92     done
93     if test "$success" = no ; then
94 dnl     broken
95     ifelse([$7], , , [$7])
96         LIBS=$OLD_LIBS
97         LDFLAGS=$OLD_LDFLAGS
98         CPPFLAGS=$OLD_CPPFLAGS
99         CFLAGS=$OLD_CFLAGS
100     fi
101 fi
102
103 ])