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