| 1 |
dnl |
| 2 |
dnl Improved version of AC_CHECK_LIB |
| 3 |
dnl |
| 4 |
dnl Thanks to John Hawkinson (jhawk@mit.edu) |
| 5 |
dnl |
| 6 |
dnl usage: |
| 7 |
dnl |
| 8 |
dnl AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [, |
| 9 |
dnl ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]]) |
| 10 |
dnl |
| 11 |
dnl results: |
| 12 |
dnl |
| 13 |
dnl LIBS |
| 14 |
dnl |
| 15 |
|
| 16 |
define(AC_LBL_CHECK_LIB, |
| 17 |
[AC_MSG_CHECKING([for $2 in -l$1]) |
| 18 |
dnl Use a cache variable name containing both the library and function name, |
| 19 |
dnl because the test really is for library $1 defining function $2, not |
| 20 |
dnl just for library $1. Separate tests with the same $1 and different $2's |
| 21 |
dnl may have different results. |
| 22 |
ac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'` |
| 23 |
AC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var, |
| 24 |
[ac_save_LIBS="$LIBS" |
| 25 |
LIBS="-l$1 $5 $LIBS" |
| 26 |
AC_TRY_LINK(dnl |
| 27 |
ifelse([$2], [main], , dnl Avoid conflicting decl of main. |
| 28 |
[/* Override any gcc2 internal prototype to avoid an error. */ |
| 29 |
]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus |
| 30 |
extern "C" |
| 31 |
#endif |
| 32 |
])dnl |
| 33 |
[/* We use char because int might match the return type of a gcc2 |
| 34 |
builtin and then its argument prototype would still apply. */ |
| 35 |
char $2(); |
| 36 |
]), |
| 37 |
[$2()], |
| 38 |
eval "ac_cv_lbl_lib_$ac_lib_var=yes", |
| 39 |
eval "ac_cv_lbl_lib_$ac_lib_var=no") |
| 40 |
LIBS="$ac_save_LIBS" |
| 41 |
])dnl |
| 42 |
if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then |
| 43 |
AC_MSG_RESULT(yes) |
| 44 |
ifelse([$3], , |
| 45 |
[changequote(, )dnl |
| 46 |
ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \ |
| 47 |
-e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` |
| 48 |
changequote([, ])dnl |
| 49 |
AC_DEFINE_UNQUOTED($ac_tr_lib) |
| 50 |
LIBS="-l$1 $LIBS" |
| 51 |
], [$3]) |
| 52 |
else |
| 53 |
AC_MSG_RESULT(no) |
| 54 |
ifelse([$4], , , [$4 |
| 55 |
])dnl |
| 56 |
fi |
| 57 |
]) |
| 58 |
|
| 59 |
dnl |
| 60 |
dnl AC_LBL_LIBRARY_NET |
| 61 |
dnl |
| 62 |
dnl This test is for network applications that need socket() and |
| 63 |
dnl gethostbyname() -ish functions. Under Solaris, those applications |
| 64 |
dnl need to link with "-lsocket -lnsl". Under IRIX, they need to link |
| 65 |
dnl with "-lnsl" but should *not* link with "-lsocket" because |
| 66 |
dnl libsocket.a breaks a number of things (for instance: |
| 67 |
dnl gethostbyname() under IRIX 5.2, and snoop sockets under most |
| 68 |
dnl versions of IRIX). |
| 69 |
dnl |
| 70 |
dnl Unfortunately, many application developers are not aware of this, |
| 71 |
dnl and mistakenly write tests that cause -lsocket to be used under |
| 72 |
dnl IRIX. It is also easy to write tests that cause -lnsl to be used |
| 73 |
dnl under operating systems where neither are necessary (or useful), |
| 74 |
dnl such as SunOS 4.1.4, which uses -lnsl for TLI. |
| 75 |
dnl |
| 76 |
dnl This test exists so that every application developer does not test |
| 77 |
dnl this in a different, and subtly broken fashion. |
| 78 |
|
| 79 |
dnl It has been argued that this test should be broken up into two |
| 80 |
dnl seperate tests, one for the resolver libraries, and one for the |
| 81 |
dnl libraries necessary for using Sockets API. Unfortunately, the two |
| 82 |
dnl are carefully intertwined and allowing the autoconf user to use |
| 83 |
dnl them independantly potentially results in unfortunate ordering |
| 84 |
dnl dependancies -- as such, such component macros would have to |
| 85 |
dnl carefully use indirection and be aware if the other components were |
| 86 |
dnl executed. Since other autoconf macros do not go to this trouble, |
| 87 |
dnl and almost no applications use sockets without the resolver, this |
| 88 |
dnl complexity has not been implemented. |
| 89 |
dnl |
| 90 |
dnl The check for libresolv is in case you are attempting to link |
| 91 |
dnl statically and happen to have a libresolv.a lying around (and no |
| 92 |
dnl libnsl.a). |
| 93 |
dnl |
| 94 |
AC_DEFUN(AC_LBL_LIBRARY_NET, [ |
| 95 |
# Most operating systems have gethostbyname() in the default searched |
| 96 |
# libraries (i.e. libc): |
| 97 |
AC_CHECK_FUNC(gethostbyname, , |
| 98 |
# Some OSes (eg. Solaris) place it in libnsl: |
| 99 |
AC_LBL_CHECK_LIB(nsl, gethostbyname, , |
| 100 |
# Some strange OSes (SINIX) have it in libsocket: |
| 101 |
AC_LBL_CHECK_LIB(socket, gethostbyname, , |
| 102 |
# Unfortunately libsocket sometimes depends on libnsl. |
| 103 |
# AC_CHECK_LIB's API is essentially broken so the |
| 104 |
# following ugliness is necessary: |
| 105 |
AC_LBL_CHECK_LIB(socket, gethostbyname, |
| 106 |
LIBS="-lsocket -lnsl $LIBS", |
| 107 |
AC_CHECK_LIB(resolv, gethostbyname), |
| 108 |
-lnsl)))) |
| 109 |
AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, , |
| 110 |
AC_LBL_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , |
| 111 |
-lnsl))) |
| 112 |
# DLPI needs putmsg under HPUX so test for -lstr while we're at it |
| 113 |
AC_CHECK_LIB(str, putmsg) |
| 114 |
]) |
| 115 |
|
| 116 |
dnl |
| 117 |
dnl Checks to see if struct tm has the BSD tm_gmtoff member |
| 118 |
dnl |
| 119 |
dnl usage: |
| 120 |
dnl |
| 121 |
dnl AC_ACME_TM_GMTOFF |
| 122 |
dnl |
| 123 |
dnl results: |
| 124 |
dnl |
| 125 |
dnl HAVE_TM_GMTOFF (defined) |
| 126 |
dnl |
| 127 |
AC_DEFUN(AC_ACME_TM_GMTOFF, |
| 128 |
[AC_MSG_CHECKING(if struct tm has tm_gmtoff member) |
| 129 |
AC_CACHE_VAL(ac_cv_acme_tm_has_tm_gmtoff, |
| 130 |
AC_TRY_COMPILE([ |
| 131 |
# include <sys/types.h> |
| 132 |
# include <time.h>], |
| 133 |
[u_int i = sizeof(((struct tm *)0)->tm_gmtoff)], |
| 134 |
ac_cv_acme_tm_has_tm_gmtoff=yes, |
| 135 |
ac_cv_acme_tm_has_tm_gmtoff=no)) |
| 136 |
AC_MSG_RESULT($ac_cv_acme_tm_has_tm_gmtoff) |
| 137 |
if test $ac_cv_acme_tm_has_tm_gmtoff = yes ; then |
| 138 |
AC_DEFINE(HAVE_TM_GMTOFF) |
| 139 |
fi]) |
| 140 |
|
| 141 |
dnl |
| 142 |
dnl Checks to see if struct sockaddr_storage exists |
| 143 |
dnl |
| 144 |
dnl usage: |
| 145 |
dnl |
| 146 |
dnl AC_ACME_SOCKADDR_STORAGE |
| 147 |
dnl |
| 148 |
dnl results: |
| 149 |
dnl |
| 150 |
dnl HAVE_SOCKADDR_STORAGE (defined) |
| 151 |
dnl |
| 152 |
AC_DEFUN(AC_ACME_SOCKADDR_STORAGE, |
| 153 |
[AC_MSG_CHECKING(if struct sockaddr_storage exists) |
| 154 |
AC_CACHE_VAL(ac_cv_acme_sockaddr_storage, |
| 155 |
AC_TRY_COMPILE([ |
| 156 |
# include <sys/types.h> |
| 157 |
# include <sys/socket.h>], |
| 158 |
[struct sockaddr_storage sas], |
| 159 |
ac_cv_acme_sockaddr_storage=yes, |
| 160 |
ac_cv_acme_sockaddr_storage=no)) |
| 161 |
AC_MSG_RESULT($ac_cv_acme_sockaddr_storage) |
| 162 |
if test $ac_cv_acme_sockaddr_storage = yes ; then |
| 163 |
AC_DEFINE(HAVE_SOCKADDR_STORAGE) |
| 164 |
fi]) |
| 165 |
|
| 166 |
dnl |
| 167 |
dnl Checks to see if struct sockaddr_in6 exists |
| 168 |
dnl |
| 169 |
dnl usage: |
| 170 |
dnl |
| 171 |
dnl AC_ACME_SOCKADDR_IN6 |
| 172 |
dnl |
| 173 |
dnl results: |
| 174 |
dnl |
| 175 |
dnl HAVE_SOCKADDR_IN6 (defined) |
| 176 |
dnl |
| 177 |
AC_DEFUN(AC_ACME_SOCKADDR_IN6, |
| 178 |
[AC_MSG_CHECKING(if struct sockaddr_in6 exists) |
| 179 |
AC_CACHE_VAL(ac_cv_acme_sockaddr_in6, |
| 180 |
AC_TRY_COMPILE([ |
| 181 |
# include <sys/types.h> |
| 182 |
# include <sys/socket.h> |
| 183 |
# include <netinet/in.h>], |
| 184 |
[struct sockaddr_in6 sa6], |
| 185 |
ac_cv_acme_sockaddr_in6=yes, |
| 186 |
ac_cv_acme_sockaddr_in6=no)) |
| 187 |
AC_MSG_RESULT($ac_cv_acme_sockaddr_in6) |
| 188 |
if test $ac_cv_acme_sockaddr_in6 = yes ; then |
| 189 |
AC_DEFINE(HAVE_SOCKADDR_IN6) |
| 190 |
fi]) |