*** empty log message ***
[gnulib.git] / m4 / search-libs.m4
1 #serial 3
2
3 dnl A replacement for autoconf's macro by the same name.  This version
4 dnl uses `ac_lib' rather than `i' for the loop variable, but more importantly
5 dnl moves the ACTION-IF-FOUND ([$]3) into the inner `if'-block so that it is
6 dnl run only if one of the listed libraries ends up being used (and not in
7 dnl the `none required' case.
8 dnl I hope it's only temporary while we wait for that version to be fixed.
9 undefine([AC_SEARCH_LIBS])
10
11 dnl AC_SEARCH_LIBS(FUNCTION, SEARCH-LIBS [, ACTION-IF-FOUND
12 dnl            [, ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
13 dnl Search for a library defining FUNC, if it's not already available.
14
15 AC_DEFUN(AC_SEARCH_LIBS,
16 [
17   AC_CACHE_CHECK([for library containing $1], [ac_cv_search_$1],
18   [
19     ac_func_search_save_LIBS="$LIBS"
20     ac_cv_search_$1="no"
21     AC_TRY_LINK_FUNC([$1], [ac_cv_search_$1="none required"])
22     if test "$ac_cv_search_$1" = "no"; then
23       for ac_lib in $2; do
24         LIBS="-l$ac_lib $5 $ac_func_search_save_LIBS"
25         AC_TRY_LINK_FUNC([$1],
26           [ac_cv_search_$1="-l$ac_lib"
27           break])
28       done
29     fi
30     LIBS="$ac_func_search_save_LIBS"
31   ])
32
33   if test "$ac_cv_search_$1" = "no"; then :
34     $4
35   else
36     if test "$ac_cv_search_$1" = "none required"; then :
37       $4
38     else
39       LIBS="$ac_cv_search_$1 $LIBS"
40       $3
41     fi
42   fi
43 ])