New file to override autoconf's AC_SEARCH_LIBS.
[gnulib.git] / m4 / search-libs.m4
1 #serial 1
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_PREREQ([2.13])
18   AC_CACHE_CHECK([for library containing $1], [ac_cv_search_$1],
19   [
20     ac_func_search_save_LIBS="$LIBS"
21     ac_cv_search_$1="no"
22     AC_TRY_LINK_FUNC([$1], [ac_cv_search_$1="none required"])
23     if test "$ac_cv_search_$1" = "no"; then
24       for ac_lib in $2; do
25         LIBS="-l$ac_lib $5 $ac_func_search_save_LIBS"
26         AC_TRY_LINK_FUNC([$1],
27           [ac_cv_search_$1="-l$ac_lib"
28           break])
29       done
30     fi
31     LIBS="$ac_func_search_save_LIBS"
32   ])
33
34   if test "$ac_cv_search_$1" = "no"; then
35     $4
36   else
37     if test "$ac_cv_search_$1" = "none required"; then
38       $4
39     else :
40       LIBS="$ac_cv_search_$1 $LIBS"
41       $3
42     fi
43   fi
44 ])