xref: /netbsd-src/external/bsd/am-utils/dist/m4/macros/check_lib2.m4 (revision a53f50b9b44dc9467ccc9c464999b1d1c509cb0c)
1dnl a bug-fixed version of autoconf 2.12.
2dnl first try to link library without $5, and only of that failed,
3dnl try with $5 if specified.
4dnl it adds $5 to $LIBS if it was needed -Erez.
5dnl AC_CHECK_LIB2(LIBRARY, FUNCTION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND
6dnl              [, OTHER-LIBRARIES]]])
7AC_DEFUN([AMU_CHECK_LIB2],
8[AC_MSG_CHECKING([for $2 in -l$1])
9dnl Use a cache variable name containing both the library and function name,
10dnl because the test really is for library $1 defining function $2, not
11dnl just for library $1.  Separate tests with the same $1 and different $2s
12dnl may have different results.
13ac_lib_var=`echo $1['_']$2 | sed 'y%./+-%__p_%'`
14AC_CACHE_VAL(ac_cv_lib_$ac_lib_var,
15[ac_save_LIBS="$LIBS"
16
17# first try with base library, without auxiliary library
18LIBS="-l$1 $LIBS"
19AC_TRY_LINK(dnl
20ifelse([$2], [main], , dnl Avoid conflicting decl of main.
21[/* Override any gcc2 internal prototype to avoid an error.  */
22]
23[/* We use char because int might match the return type of a gcc2
24    builtin and then its argument prototype would still apply.  */
25char $2();
26]),
27	    [$2()],
28	    eval "ac_cv_lib_$ac_lib_var=\"$1\"",
29	    eval "ac_cv_lib_$ac_lib_var=no")
30
31# if OK, set to no auxiliary library, else try auxiliary library
32if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = no"; then
33 LIBS="-l$1 $5 $LIBS"
34 AC_TRY_LINK(dnl
35 ifelse([$2], [main], , dnl Avoid conflicting decl of main.
36 [/* Override any gcc2 internal prototype to avoid an error.  */
37 ]
38 [/* We use char because int might match the return type of a gcc2
39     builtin and then its argument prototype would still apply.  */
40 char $2();
41 ]),
42 	    [$2()],
43 	    eval "ac_cv_lib_$ac_lib_var=\"$1 $5\"",
44 	    eval "ac_cv_lib_$ac_lib_var=no")
45fi
46
47LIBS="$ac_save_LIBS"
48])dnl
49ac_tmp="`eval echo '$''{ac_cv_lib_'$ac_lib_var'}'`"
50if test "${ac_tmp}" != no; then
51  AC_MSG_RESULT(-l$ac_tmp)
52  ifelse([$3], ,
53[
54  ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[[^a-zA-Z0-9_]]/_/g' \
55    -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
56
57  AC_DEFINE_UNQUOTED($ac_tr_lib)
58  LIBS="-l$ac_tmp $LIBS"
59], [$3])
60else
61  AC_MSG_RESULT(no)
62ifelse([$4], , , [$4
63])dnl
64fi
65
66])
67