]> git.sur5r.net Git - openldap/blob - build/openldap.m4
Use AC_CHECK_MEMBER to implement struct passwd checks
[openldap] / build / openldap.m4
1 dnl $OpenLDAP$
2 dnl
3 dnl Copyright 1998-2003 The OpenLDAP Foundation, Redwood City, California, USA
4 dnl All rights reserved.
5 dnl 
6 dnl Redistribution and use in source and binary forms, with or without
7 dnl modification, are permitted only as authorized by the OpenLDAP
8 dnl Public License.  A copy of this license is available at
9 dnl http://www.OpenLDAP.org/license.html or in file LICENSE in the
10 dnl top-level directory of the distribution.
11 dnl
12 dnl OpenLDAP Autoconf Macros
13 dnl
14 dnl --------------------------------------------------------------------
15 dnl Restricted form of AC_ARG_ENABLE that limits user options
16 dnl
17 dnl $1 = option name
18 dnl $2 = help-string
19 dnl $3 = default value  (auto)
20 dnl $4 = allowed values (auto yes no)
21 AC_DEFUN([OL_ARG_ENABLE], [# OpenLDAP --enable-$1
22         AC_ARG_ENABLE($1,changequote(<,>)<$2 [>ifelse($3,,auto,$3)<]>changequote([,]),[
23         ol_arg=invalid
24         for ol_val in ifelse($4,,[auto yes no],[$4]) ; do
25                 if test "$enableval" = "$ol_val" ; then
26                         ol_arg="$ol_val"
27                 fi
28         done
29         if test "$ol_arg" = "invalid" ; then
30                 AC_MSG_ERROR(bad value $enableval for --enable-$1)
31         fi
32         ol_enable_$1="$ol_arg"
33 ],
34 [       ol_enable_$1=ifelse($3,,"auto","$3")])dnl
35 dnl AC_VERBOSE(OpenLDAP -enable-$1 $ol_enable_$1)
36 # end --enable-$1
37 ])dnl
38 dnl
39 dnl --------------------------------------------------------------------
40 dnl Restricted form of AC_ARG_WITH that limits user options
41 dnl
42 dnl $1 = option name
43 dnl $2 = help-string
44 dnl $3 = default value (no)
45 dnl $4 = allowed values (yes or no)
46 AC_DEFUN([OL_ARG_WITH], [# OpenLDAP --with-$1
47         AC_ARG_WITH($1,changequote(<,>)<$2 [>ifelse($3,,yes,$3)<]>changequote([,]),[
48         ol_arg=invalid
49         for ol_val in ifelse($4,,[yes no],[$4]) ; do
50                 if test "$withval" = "$ol_val" ; then
51                         ol_arg="$ol_val"
52                 fi
53         done
54         if test "$ol_arg" = "invalid" ; then
55                 AC_MSG_ERROR(bad value $withval for --with-$1)
56         fi
57         ol_with_$1="$ol_arg"
58 ],
59 [       ol_with_$1=ifelse($3,,"no","$3")])dnl
60 dnl AC_VERBOSE(OpenLDAP --with-$1 $ol_with_$1)
61 # end --with-$1
62 ])dnl
63 dnl
64 dnl ====================================================================
65 dnl
66 AC_DEFUN(AC_COMPILE_CHECK_SIZEOF,
67 [changequote(<<, >>)dnl 
68 dnl The name to #define. 
69 define(<<AC_TYPE_NAME>>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl 
70 dnl The cache variable name. 
71 define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl 
72 changequote([, ])dnl 
73 AC_MSG_CHECKING(size of $1) 
74 AC_CACHE_VAL(AC_CV_NAME, 
75 [for ac_size in 4 8 1 2 16 $2 ; do # List sizes in rough order of prevalence. 
76   AC_TRY_COMPILE([#include "confdefs.h" 
77 #include <sys/types.h> 
78 $2 
79 ], [switch (0) case 0: case (sizeof ($1) == $ac_size):;], AC_CV_NAME=$ac_size) 
80   if test x$AC_CV_NAME != x ; then break; fi 
81 done 
82 ]) 
83 if test x$AC_CV_NAME = x ; then 
84   AC_MSG_ERROR([cannot determine a size for $1]) 
85 fi 
86 AC_MSG_RESULT($AC_CV_NAME) 
87 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The number of bytes in type $1]) 
88 undefine([AC_TYPE_NAME])dnl 
89 undefine([AC_CV_NAME])dnl 
90 ])
91 dnl ====================================================================
92 dnl check if hard links are supported.
93 dnl
94 AC_DEFUN([OL_PROG_LN_H], [# test for ln hardlink support
95 AC_MSG_CHECKING(whether ln works)
96 AC_CACHE_VAL(ol_cv_prog_LN_H,
97 [rm -f conftest.src conftest.dst
98 echo "conftest" > conftest.src
99 if ln conftest.src conftest.dst 2>/dev/null
100 then
101   ol_cv_prog_LN_H="ln"
102 else
103   ol_cv_prog_LN_H="cp"
104 fi
105 rm -f conftest.src conftest.dst
106 ])dnl
107 LN_H="$ol_cv_prog_LN_H"
108 if test "$ol_cv_prog_LN_H" = "ln"; then
109         AC_MSG_RESULT(yes)
110 else
111         AC_MSG_RESULT(no)
112 fi
113 AC_SUBST(LN_H)dnl
114 ])dnl
115 dnl
116 dnl ====================================================================
117 dnl Check for dependency generation flag
118 AC_DEFUN([OL_MKDEPEND], [# test for make depend flag
119 OL_MKDEP=
120 OL_MKDEP_FLAGS=
121 if test -z "${MKDEP}"; then
122         OL_MKDEP="${CC-cc}"
123         if test -z "${MKDEP_FLAGS}"; then
124                 AC_CACHE_CHECK([for ${OL_MKDEP} depend flag], ol_cv_mkdep, [
125                         ol_cv_mkdep=no
126                         for flag in "-M" "-xM"; do
127                                 cat > conftest.c <<EOF
128  noCode;
129 EOF
130                                 if AC_TRY_COMMAND($OL_MKDEP $flag conftest.c) \
131                                         | egrep '^conftest\.'"${ac_objext}" >/dev/null 2>&1
132                                 then
133                                         if test ! -f conftest."${ac_object}" ; then
134                                                 ol_cv_mkdep=$flag
135                                                 OL_MKDEP_FLAGS="$flag"
136                                                 break
137                                         fi
138                                 fi
139                         done
140                         rm -f conftest*
141                 ])
142         else
143                 cc_cv_mkdep=yes
144                 OL_MKDEP_FLAGS="${MKDEP_FLAGS}"
145         fi
146 else
147         cc_cv_mkdep=yes
148         OL_MKDEP="${MKDEP}"
149         OL_MKDEP_FLAGS="${MKDEP_FLAGS}"
150 fi
151 AC_SUBST(OL_MKDEP)
152 AC_SUBST(OL_MKDEP_FLAGS)
153 ])
154 dnl
155 dnl ====================================================================
156 dnl Check if system uses EBCDIC instead of ASCII
157 AC_DEFUN([OL_CPP_EBCDIC], [# test for EBCDIC
158 AC_CACHE_CHECK([for EBCDIC],ol_cv_cpp_ebcdic,[
159         AC_TRY_CPP([
160 #if !('M' == 0xd4)
161 #include <__ASCII__/generate_error.h>
162 #endif
163 ],
164         [ol_cv_cpp_ebcdic=yes],
165         [ol_cv_cpp_ebcdic=no])])
166 if test $ol_cv_cpp_ebcdic = yes ; then
167         AC_DEFINE(HAVE_EBCDIC,1, [define if system uses EBCDIC instead of ASCII])
168 fi
169 ])
170 dnl
171 dnl --------------------------------------------------------------------
172 dnl OpenLDAP version of STDC header check w/ EBCDIC support
173 AC_DEFUN(OL_HEADER_STDC,
174 [AC_REQUIRE_CPP()dnl
175 AC_REQUIRE([OL_CPP_EBCDIC])dnl
176 AC_CACHE_CHECK([for ANSI C header files], ol_cv_header_stdc,
177 [AC_TRY_CPP([#include <stdlib.h>
178 #include <stdarg.h>
179 #include <string.h>
180 #include <float.h>], ol_cv_header_stdc=yes, ol_cv_header_stdc=no)
181
182 if test $ol_cv_header_stdc = yes; then
183   # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
184 AC_EGREP_HEADER(memchr, string.h, , ol_cv_header_stdc=no)
185 fi
186
187 if test $ol_cv_header_stdc = yes; then
188   # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
189 AC_EGREP_HEADER(free, stdlib.h, , ol_cv_header_stdc=no)
190 fi
191
192 if test $ol_cv_header_stdc = yes; then
193   # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
194 AC_TRY_RUN([#include <ctype.h>
195 #ifndef HAVE_EBCDIC
196 #       define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
197 #       define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
198 #else
199 #       define ISLOWER(c) (('a' <= (c) && (c) <= 'i') \
200                 || ('j' <= (c) && (c) <= 'r') \
201                 || ('s' <= (c) && (c) <= 'z'))
202 #       define TOUPPER(c)       (ISLOWER(c) ? ((c) | 0x40) : (c))
203 #endif
204 #define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
205 int main () { int i; for (i = 0; i < 256; i++)
206 if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2);
207 exit (0); }
208 ], , ol_cv_header_stdc=no, :)
209 fi])
210 if test $ol_cv_header_stdc = yes; then
211   AC_DEFINE(STDC_HEADERS)
212 fi
213 ac_cv_header_stdc=disable
214 ])
215 dnl
216 dnl ====================================================================
217 dnl Check if struct passwd has pw_gecos
218 AC_DEFUN([OL_STRUCT_PASSWD_PW_GECOS], [# test for pw_gecos in struct passwd
219    AC_CHECK_MEMBER(struct passwd.pw_gecos,,,[#include <pwd.h>])
220    if test $ac_cv_member_struct_passwd_pw_gecos = "yes" ; then
221                 AC_DEFINE(HAVE_PW_GECOS,1, [define if struct passwd has pw_gecos])
222    fi
223 ])dnl
224 dnl --------------------------------------------------------------------
225 dnl Check if struct passwd has pw_passwd
226 AC_DEFUN([OL_STRUCT_PASSWD_PW_PASSWD], [# test for pw_passwd in struct passwd
227    AC_CHECK_MEMBER(struct passwd.pw_passwd,,,[#include <pwd.h>])
228    if test $ac_cv_member_struct_passwd_pw_passwd = "yes" ; then
229                 AC_DEFINE(HAVE_PW_PASSWD,1, [define if struct passwd has pw_passwd])
230    fi
231 ])dnl
232 dnl ====================================================================
233 dnl Berkeley DB macros
234 dnl
235 dnl --------------------------------------------------------------------
236 dnl Try to link
237 AC_DEFUN([OL_BERKELEY_DB_TRY],
238 [if test $ol_cv_lib_db = no ; then
239         AC_CACHE_CHECK([for Berkeley DB link (]ifelse($2,,default,$2)[)],[$1],
240 [
241         ol_DB_LIB=ifelse($2,,,$2)
242         ol_LIBS=$LIBS
243         LIBS="$ol_DB_LIB $LTHREAD_LIBS $LIBS"
244
245         AC_TRY_LINK([
246 #ifdef HAVE_DB_185_H
247 # include <db_185.h>
248 #else
249 # include <db.h>
250 #endif
251
252 #ifndef DB_VERSION_MAJOR
253 # define DB_VERSION_MAJOR 1
254 #endif
255
256 #ifndef NULL
257 #define NULL ((void*)0)
258 #endif
259 ],[
260 #if DB_VERSION_MAJOR > 1
261         {
262                 char *version;
263                 int major, minor, patch;
264
265                 version = db_version( &major, &minor, &patch );
266
267                 if( major != DB_VERSION_MAJOR ||
268                         minor < DB_VERSION_MINOR )
269                 {
270                         printf("Berkeley DB version mismatch\n"
271                                 "\texpected: %s\n\tgot: %s\n",
272                                 DB_VERSION_STRING, version);
273                         return 1;
274                 }
275         }
276 #endif
277
278 #if DB_VERSION_MAJOR > 2
279         db_env_create( NULL, 0 );
280 #elif DB_VERSION_MAJOR > 1
281         db_appexit( NULL );
282 #else
283         (void) dbopen( NULL, 0, 0, 0, NULL);
284 #endif
285 ],[$1=yes],[$1=no])
286
287         LIBS="$ol_LIBS"
288 ])
289
290         if test $$1 = yes ; then
291                 ol_cv_lib_db=ifelse($2,,yes,$2)
292         fi
293 fi
294 ])
295 dnl
296 dnl --------------------------------------------------------------------
297 dnl Try to locate appropriate library
298 AC_DEFUN([OL_BERKELEY_DB_LINK],
299 [ol_cv_lib_db=no
300 OL_BERKELEY_DB_TRY(ol_cv_db_none)
301 OL_BERKELEY_DB_TRY(ol_cv_db_db41,[-ldb41])
302 OL_BERKELEY_DB_TRY(ol_cv_db_db_41,[-ldb-41])
303 OL_BERKELEY_DB_TRY(ol_cv_db_db_4_dot_1,[-ldb-4.1])
304 OL_BERKELEY_DB_TRY(ol_cv_db_db_4_1,[-ldb-4-1])
305 OL_BERKELEY_DB_TRY(ol_cv_db_db_4,[-ldb-4])
306 OL_BERKELEY_DB_TRY(ol_cv_db_db4,[-ldb4])
307 OL_BERKELEY_DB_TRY(ol_cv_db_db,[-ldb])
308 OL_BERKELEY_DB_TRY(ol_cv_db_db3,[-ldb3])
309 OL_BERKELEY_DB_TRY(ol_cv_db_db_3,[-ldb-3])
310 OL_BERKELEY_DB_TRY(ol_cv_db_db2,[-ldb2])
311 OL_BERKELEY_DB_TRY(ol_cv_db_db_2,[-ldb-2])
312 OL_BERKELEY_DB_TRY(ol_cv_db_db1,[-ldb1])
313 OL_BERKELEY_DB_TRY(ol_cv_db_db_1,[-ldb-1])
314 ])
315 dnl
316 dnl --------------------------------------------------------------------
317 dnl Check if Berkeley DB supports DB_THREAD
318 AC_DEFUN([OL_BERKELEY_DB_THREAD],
319 [AC_CACHE_CHECK([for Berkeley DB thread support], [ol_cv_berkeley_db_thread], [
320         ol_LIBS="$LIBS"
321         LIBS="$LTHREAD_LIBS $LIBS"
322         if test $ol_cv_lib_db != yes ; then
323                 LIBS="$ol_cv_lib_db $LIBS"
324         fi
325
326         AC_TRY_RUN([
327 #ifdef HAVE_DB_185_H
328         choke me;
329 #else
330 #include <db.h>
331 #endif
332 #ifndef NULL
333 #define NULL ((void *)0)
334 #endif
335 main()
336 {
337         int rc;
338         u_int32_t flags = DB_CREATE |
339 #ifdef DB_PRIVATE
340                 DB_PRIVATE |
341 #endif
342                 DB_THREAD;
343
344 #if DB_VERSION_MAJOR > 2
345         DB_ENV *env = NULL;
346
347         rc = db_env_create( &env, 0 );
348
349         flags |= DB_INIT_MPOOL;
350 #ifdef DB_MPOOL_PRIVATE
351         flags |= DB_MPOOL_PRIVATE;
352 #endif
353
354         if( rc ) {
355                 printf("BerkeleyDB: %s\n", db_strerror(rc) );
356                 return rc;
357         }
358
359 #if (DB_VERSION_MAJOR > 3) || (DB_VERSION_MINOR >= 1)
360         rc = env->open( env, NULL, flags, 0 );
361 #else
362         rc = env->open( env, NULL, NULL, flags, 0 );
363 #endif
364
365         if ( rc == 0 ) {
366                 rc = env->close( env, 0 );
367         }
368
369         if( rc ) {
370                 printf("BerkeleyDB: %s\n", db_strerror(rc) );
371                 return rc;
372         }
373
374 #else
375         DB_ENV env;
376         memset( &env, '\0', sizeof(env) );
377
378         rc = db_appinit( NULL, NULL, &env, flags );
379
380         if( rc == 0 ) {
381                 db_appexit( &env );
382         }
383
384         unlink("__db_mpool.share");
385         unlink("__db_lock.share");
386 #endif
387
388         return rc;
389 }],
390         [ol_cv_berkeley_db_thread=yes],
391         [ol_cv_berkeley_db_thread=no],
392         [ol_cv_berkeley_db_thread=cross])
393
394         LIBS="$ol_LIBS"
395 ])
396
397         if test $ol_cv_berkeley_db_thread != no ; then
398                 AC_DEFINE(HAVE_BERKELEY_DB_THREAD, 1,
399                         [define if Berkeley DB has DB_THREAD support])
400         fi
401 ])dnl
402 dnl
403 dnl --------------------------------------------------------------------
404 dnl Find any DB
405 AC_DEFUN([OL_BERKELEY_DB],
406 [ol_cv_berkeley_db=no
407 AC_CHECK_HEADERS(db.h)
408 if test $ac_cv_header_db_h = yes; then
409         OL_BERKELEY_DB_LINK
410         if test "$ol_cv_lib_db" != no ; then
411                 ol_cv_berkeley_db=yes
412                 OL_BERKELEY_DB_THREAD
413         fi
414 fi
415 ])
416 dnl --------------------------------------------------------------------
417 dnl Check for version compatility with back-bdb
418 AC_DEFUN([OL_BDB_COMPAT],
419 [AC_CACHE_CHECK([Berkeley DB version for BDB backend], [ol_cv_bdb_compat],[
420         AC_EGREP_CPP(__db_version_compat,[
421 #include <db.h>
422
423  /* this check could be improved */
424 #ifndef DB_VERSION_MAJOR
425 #       define DB_VERSION_MAJOR 1
426 #endif
427 #ifndef DB_VERSION_MINOR
428 #       define DB_VERSION_MINOR 0
429 #endif
430
431 /* require 4.1 or later */
432 #if (DB_VERSION_MAJOR >= 4) && (DB_VERSION_MINOR >= 1)
433         __db_version_compat
434 #endif
435         ], [ol_cv_bdb_compat=yes], [ol_cv_bdb_compat=no])])
436 ])
437
438 dnl --------------------------------------------------------------------
439 dnl Find old Berkeley DB 1.85/1.86
440 AC_DEFUN([OL_BERKELEY_COMPAT_DB],
441 [AC_CHECK_HEADERS(db_185.h db.h)
442 if test $ac_cv_header_db_185_h = yes -o $ac_cv_header_db_h = yes; then
443         AC_CACHE_CHECK([if Berkeley DB header compatibility], [ol_cv_header_db1],[
444                 AC_EGREP_CPP(__db_version_1,[
445 #if HAVE_DB_185_H
446 #       include <db_185.h>
447 #else
448 #       include <db.h>
449 #endif
450
451  /* this check could be improved */
452 #ifndef DB_VERSION_MAJOR
453 #       define DB_VERSION_MAJOR 1
454 #endif
455
456 #if DB_VERSION_MAJOR == 1 
457         __db_version_1
458 #endif
459 ],      [ol_cv_header_db1=yes], [ol_cv_header_db1=no])])
460
461         if test $ol_cv_header_db1 = yes ; then
462                 OL_BERKELEY_DB_LINK
463                 if test "$ol_cv_lib_db" != no ; then
464                         ol_cv_berkeley_db=yes
465                 fi
466         fi
467 fi
468 ])
469 dnl
470 dnl ====================================================================
471 dnl Check if GDBM library exists
472 dnl Check for gdbm_open in standard libraries or -lgdbm
473 dnl
474 dnl defines ol_cv_lib_gdbm to 'yes' or '-lgdbm' or 'no'
475 dnl             'yes' implies gdbm_open is in $LIBS
476 dnl
477 dnl uses:
478 dnl             AC_CHECK_FUNC(gdbm_open)
479 dnl             AC_CHECK_LIB(gdbm,gdbm_open)
480 dnl
481 AC_DEFUN([OL_LIB_GDBM],
482 [AC_CACHE_CHECK(for GDBM library, [ol_cv_lib_gdbm],
483 [       ol_LIBS="$LIBS"
484         AC_CHECK_FUNC(gdbm_open,[ol_cv_lib_gdbm=yes], [
485                 AC_CHECK_LIB(gdbm,gdbm_open,[ol_cv_lib_gdbm=-lgdbm],[ol_cv_lib_gdbm=no])
486         ])
487         LIBS="$ol_LIBS"
488 ])
489 ])dnl
490 dnl
491 dnl --------------------------------------------------------------------
492 dnl Check if GDBM exists
493 dnl
494 dnl defines ol_cv_gdbm to 'yes' or 'no'
495 dnl 
496 dnl uses:
497 dnl             OL_LIB_GDBM
498 dnl             AC_CHECK_HEADERS(gdbm.h)
499 dnl
500 AC_DEFUN([OL_GDBM],
501 [AC_REQUIRE([OL_LIB_GDBM])
502  AC_CHECK_HEADERS(gdbm.h)
503  AC_CACHE_CHECK(for db, [ol_cv_gdbm], [
504         if test $ol_cv_lib_gdbm = no -o $ac_cv_header_gdbm_h = no ; then
505                 ol_cv_gdbm=no
506         else
507                 ol_cv_gdbm=yes
508         fi
509 ])
510  if test $ol_cv_gdbm = yes ; then
511         AC_DEFINE(HAVE_GDBM,1, [define if GNU DBM is available])
512  fi
513 ])dnl
514 dnl
515 dnl ====================================================================
516 dnl Check if MDBM library exists
517 dnl Check for mdbm_open in standard libraries or -lmdbm
518 dnl
519 dnl defines ol_cv_lib_mdbm to 'yes' or '-lmdbm' or 'no'
520 dnl             'yes' implies mdbm_open is in $LIBS
521 dnl
522 dnl uses:
523 dnl             AC_CHECK_FUNC(mdbm_set_chain)
524 dnl             AC_CHECK_LIB(mdbm,mdbm_set_chain)
525 dnl
526 AC_DEFUN([OL_LIB_MDBM],
527 [AC_CACHE_CHECK(for MDBM library, [ol_cv_lib_mdbm],
528 [       ol_LIBS="$LIBS"
529         AC_CHECK_FUNC(mdbm_set_chain,[ol_cv_lib_mdbm=yes], [
530                 AC_CHECK_LIB(mdbm,mdbm_set_chain,[ol_cv_lib_mdbm=-lmdbm],[ol_cv_lib_mdbm=no])
531         ])
532         LIBS="$ol_LIBS"
533 ])
534 ])dnl
535 dnl
536 dnl --------------------------------------------------------------------
537 dnl Check if MDBM exists
538 dnl
539 dnl defines ol_cv_mdbm to 'yes' or 'no'
540 dnl 
541 dnl uses:
542 dnl             OL_LIB_MDBM
543 dnl             AC_CHECK_HEADERS(mdbm.h)
544 dnl
545 AC_DEFUN([OL_MDBM],
546 [AC_REQUIRE([OL_LIB_MDBM])
547  AC_CHECK_HEADERS(mdbm.h)
548  AC_CACHE_CHECK(for db, [ol_cv_mdbm], [
549         if test $ol_cv_lib_mdbm = no -o $ac_cv_header_mdbm_h = no ; then
550                 ol_cv_mdbm=no
551         else
552                 ol_cv_mdbm=yes
553         fi
554 ])
555  if test $ol_cv_mdbm = yes ; then
556         AC_DEFINE(HAVE_MDBM,1, [define if MDBM is available])
557  fi
558 ])dnl
559 dnl
560 dnl ====================================================================
561 dnl Check if NDBM library exists
562 dnl Check for dbm_open in standard libraries or -lndbm or -ldbm
563 dnl
564 dnl defines ol_cv_lib_ndbm to 'yes' or '-lndbm' or -ldbm or 'no'
565 dnl             'yes' implies ndbm_open is in $LIBS
566 dnl
567 dnl uses:
568 dnl             AC_CHECK_FUNC(dbm_open)
569 dnl             AC_CHECK_LIB(ndbm,dbm_open)
570 dnl             AC_CHECK_LIB(dbm,dbm_open)
571 dnl
572 dnl restrictions:
573 dnl             should also check SVR4 case: dbm_open() in -lucb but that
574 dnl             would requiring dealing with -L/usr/ucblib
575 dnl
576 AC_DEFUN([OL_LIB_NDBM],
577 [AC_CACHE_CHECK(for NDBM library, [ol_cv_lib_ndbm],
578 [       ol_LIBS="$LIBS"
579         AC_CHECK_FUNC(dbm_open,[ol_cv_lib_ndbm=yes], [
580                 AC_CHECK_LIB(ndbm,dbm_open,[ol_cv_lib_ndbm=-lndbm], [
581                         AC_CHECK_LIB(dbm,dbm_open,[ol_cv_lib_ndbm=-ldbm],
582                                 [ol_cv_lib_ndbm=no])dnl
583                 ])
584         ])
585         LIBS="$ol_LIBS"
586 ])
587 ])dnl
588 dnl
589 dnl --------------------------------------------------------------------
590 dnl Check if NDBM exists
591 dnl
592 dnl defines ol_cv_ndbm to 'yes' or 'no'
593 dnl 
594 dnl uses:
595 dnl             OL_LIB_NDBM
596 dnl             AC_CHECK_HEADERS(ndbm.h)
597 dnl
598 dnl restrictions:
599 dnl             Doesn't handle SVR4 case (see above)
600 dnl
601 AC_DEFUN([OL_NDBM],
602 [AC_REQUIRE([OL_LIB_NDBM])
603  AC_CHECK_HEADERS(ndbm.h)
604  AC_CACHE_CHECK(for db, [ol_cv_ndbm], [
605         if test $ol_cv_lib_ndbm = no -o $ac_cv_header_ndbm_h = no ; then
606                 ol_cv_ndbm=no
607         else
608                 ol_cv_ndbm=yes
609         fi
610 ])
611  if test $ol_cv_ndbm = yes ; then
612         AC_DEFINE(HAVE_NDBM,1, [define if NDBM is available])
613  fi
614 ])dnl
615 dnl
616 dnl ====================================================================
617 dnl Check POSIX Thread version 
618 dnl
619 dnl defines ol_cv_pthread_version to 4, 5, 6, 7, 8, 10, depending on the
620 dnl     version of the POSIX.4a Draft that is implemented.
621 dnl     10 == POSIX.4a Final == POSIX.1c-1996 for our purposes.
622 dnl     Existence of pthread.h should be tested separately.
623 dnl
624 dnl tests:
625 dnl     pthread_detach() was dropped in Draft 8, it is present
626 dnl             in every other version
627 dnl     PTHREAD_CREATE_UNDETACHED is only in Draft 7, it was called
628 dnl             PTHREAD_CREATE_JOINABLE after that
629 dnl     pthread_attr_create was renamed to pthread_attr_init in Draft 6.
630 dnl             Draft 6-10 has _init, Draft 4-5 has _create.
631 dnl     pthread_attr_default was dropped in Draft 6, only 4 and 5 have it
632 dnl     PTHREAD_MUTEX_INITIALIZER was introduced in Draft 5. It's not
633 dnl             interesting to us because we don't try to statically
634 dnl             initialize mutexes. 5-10 has it.
635 dnl
636 dnl Draft 9 and 10 are equivalent for our purposes.
637 dnl
638 AC_DEFUN([OL_POSIX_THREAD_VERSION],
639 [AC_CACHE_CHECK([POSIX thread version],[ol_cv_pthread_version],[
640         AC_TRY_COMPILE([
641 #               include <pthread.h>
642         ],[
643                 int i = PTHREAD_CREATE_JOINABLE;
644         ],[
645         AC_EGREP_HEADER(pthread_detach,pthread.h,
646         ol_cv_pthread_version=10, ol_cv_pthread_version=8)],[
647         AC_EGREP_CPP(draft7,[
648 #               include <pthread.h>
649 #               ifdef PTHREAD_CREATE_UNDETACHED
650                 draft7
651 #               endif
652         ], ol_cv_pthread_version=7, [
653         AC_EGREP_HEADER(pthread_attr_init,pthread.h,
654         ol_cv_pthread_version=6, [
655         AC_EGREP_CPP(draft5,[
656 #               include <pthread.h>
657 #ifdef          PTHREAD_MUTEX_INITIALIZER
658                 draft5
659 #endif
660         ], ol_cv_pthread_version=5, ol_cv_pthread_version=4) ]) ]) ])
661 ])
662 ])dnl
663 dnl
664 dnl --------------------------------------------------------------------
665 AC_DEFUN([OL_PTHREAD_TEST_INCLUDES],
666 [/* pthread test headers */
667 #include <pthread.h>
668 #if HAVE_PTHREADS < 7
669 #include <errno.h>
670 #endif
671 #ifndef NULL
672 #define NULL (void*)0
673 #endif
674
675 static void *task(p)
676         void *p;
677 {
678         return (void *) (p == NULL);
679 }
680 ])
681 AC_DEFUN([OL_PTHREAD_TEST_FUNCTION],[
682         /* pthread test function */
683 #ifndef PTHREAD_CREATE_DETACHED
684 #define PTHREAD_CREATE_DETACHED 1
685 #endif
686         pthread_t t;
687         int status;
688         int detach = PTHREAD_CREATE_DETACHED;
689
690 #if HAVE_PTHREADS > 4
691         /* Final pthreads */
692         pthread_attr_t attr;
693
694         status = pthread_attr_init(&attr);
695         if( status ) return status;
696
697 #if HAVE_PTHREADS < 7
698         status = pthread_attr_setdetachstate(&attr, &detach);
699         if( status < 0 ) status = errno;
700 #else
701         status = pthread_attr_setdetachstate(&attr, detach);
702 #endif
703         if( status ) return status;
704         status = pthread_create( &t, &attr, task, NULL );
705 #if HAVE_PTHREADS < 7
706         if( status < 0 ) status = errno;
707 #endif
708         if( status ) return status;
709 #else
710         /* Draft 4 pthreads */
711         status = pthread_create( &t, pthread_attr_default, task, NULL );
712         if( status ) return errno;
713
714         /* give thread a chance to complete */
715         /* it should remain joinable and hence detachable */
716         sleep( 1 );
717
718         status = pthread_detach( &t );
719         if( status ) return errno;
720 #endif
721
722 #ifdef HAVE_LINUX_THREADS
723         pthread_kill_other_threads_np();
724 #endif
725
726         return 0;
727 ])
728
729 AC_DEFUN([OL_PTHREAD_TEST_PROGRAM],
730 [OL_PTHREAD_TEST_INCLUDES
731
732 int main(argc, argv)
733         int argc;
734         char **argv;
735 {
736 OL_PTHREAD_TEST_FUNCTION
737 }
738 ])
739 dnl --------------------------------------------------------------------
740 AC_DEFUN([OL_PTHREAD_TRY], [# Pthread try link: $1 ($2)
741 if test "$ol_link_threads" = no ; then
742         # try $1
743         AC_CACHE_CHECK([for pthread link with $1], [$2], [
744                 # save the flags
745                 ol_LIBS="$LIBS"
746                 LIBS="$1 $LIBS"
747
748                 AC_TRY_RUN(OL_PTHREAD_TEST_PROGRAM,
749                         [$2=yes], [$2=no],
750                         [AC_TRY_LINK(OL_PTHREAD_TEST_INCLUDES,OL_PTHREAD_TEST_FUNCTION,
751                                 [$2=yes], [$2=no])])
752
753                 # restore the LIBS
754                 LIBS="$ol_LIBS"
755         ])
756
757         if test $$2 = yes ; then
758                 ol_link_pthreads="$1"
759                 ol_link_threads=posix
760         fi
761 fi
762 ])
763 dnl
764 dnl ====================================================================
765 dnl Check GNU Pth pthread Header
766 dnl
767 dnl defines ol_cv_header linux_threads to 'yes' or 'no'
768 dnl             'no' implies pthreads.h is not LinuxThreads or pthreads.h
769 dnl             doesn't exists.  Existance of pthread.h should separately
770 dnl             checked.
771 dnl 
772 AC_DEFUN([OL_HEADER_GNU_PTH_PTHREAD_H], [
773         AC_CACHE_CHECK([for GNU Pth pthread.h],
774                 [ol_cv_header_gnu_pth_pthread_h],
775                 [AC_EGREP_CPP(__gnu_pth__,
776                         [#include <pthread.h>
777 #ifdef _POSIX_THREAD_IS_GNU_PTH
778         __gnu_pth__;
779 #endif
780 ],
781                         [ol_cv_header_gnu_pth_pthread_h=yes],
782                         [ol_cv_header_gnu_pth_pthread_h=no])
783                 ])
784 ])dnl
785 dnl ====================================================================
786 dnl Check for NT Threads
787 AC_DEFUN([OL_NT_THREADS], [
788         AC_CHECK_FUNC(_beginthread)
789
790         if test $ac_cv_func__beginthread = yes ; then
791                 AC_DEFINE(HAVE_NT_THREADS,1,[if you have NT Threads])
792                 ol_cv_nt_threads=yes
793         fi
794 ])
795 dnl ====================================================================
796 dnl Check LinuxThreads Header
797 dnl
798 dnl defines ol_cv_header linux_threads to 'yes' or 'no'
799 dnl             'no' implies pthreads.h is not LinuxThreads or pthreads.h
800 dnl             doesn't exists.  Existance of pthread.h should separately
801 dnl             checked.
802 dnl 
803 AC_DEFUN([OL_HEADER_LINUX_THREADS], [
804         AC_CACHE_CHECK([for LinuxThreads pthread.h],
805                 [ol_cv_header_linux_threads],
806                 [AC_EGREP_CPP(pthread_kill_other_threads_np,
807                         [#include <pthread.h>],
808                         [ol_cv_header_linux_threads=yes],
809                         [ol_cv_header_linux_threads=no])
810                 ])
811         if test $ol_cv_header_linux_threads = yes; then
812                 AC_DEFINE(HAVE_LINUX_THREADS,1,[if you have LinuxThreads])
813         fi
814 ])dnl
815 dnl --------------------------------------------------------------------
816 dnl     Check LinuxThreads Implementation
817 dnl
818 dnl     defines ol_cv_sys_linux_threads to 'yes' or 'no'
819 dnl     'no' implies pthreads implementation is not LinuxThreads.
820 dnl 
821 AC_DEFUN([OL_SYS_LINUX_THREADS], [
822         AC_CHECK_FUNCS(pthread_kill_other_threads_np)
823         AC_CACHE_CHECK([for LinuxThreads implementation],
824                 [ol_cv_sys_linux_threads],
825                 [ol_cv_sys_linux_threads=$ac_cv_func_pthread_kill_other_threads_np])
826 ])dnl
827 dnl
828 dnl --------------------------------------------------------------------
829 dnl Check LinuxThreads consistency
830 AC_DEFUN([OL_LINUX_THREADS], [
831         AC_REQUIRE([OL_HEADER_LINUX_THREADS])
832         AC_REQUIRE([OL_SYS_LINUX_THREADS])
833         AC_CACHE_CHECK([for LinuxThreads consistency], [ol_cv_linux_threads], [
834                 if test $ol_cv_header_linux_threads = yes -a \
835                         $ol_cv_sys_linux_threads = yes; then
836                         ol_cv_linux_threads=yes
837                 elif test $ol_cv_header_linux_threads = no -a \
838                         $ol_cv_sys_linux_threads = no; then
839                         ol_cv_linux_threads=no
840                 else
841                         ol_cv_linux_threads=error
842                 fi
843         ])
844 ])dnl
845 dnl
846 dnl ====================================================================
847 dnl Check for POSIX Regex
848 AC_DEFUN([OL_POSIX_REGEX], [
849 AC_CACHE_CHECK([for compatible POSIX regex],ol_cv_c_posix_regex,[
850         AC_TRY_RUN([
851 #include <sys/types.h>
852 #include <regex.h>
853 static char *pattern, *string;
854 main()
855 {
856         int rc;
857         regex_t re;
858
859         pattern = "^A";
860
861         if(regcomp(&re, pattern, 0)) {
862                 return -1;
863         }
864         
865         string = "ALL MATCH";
866         
867         rc = regexec(&re, string, 0, (void*)0, 0);
868
869         regfree(&re);
870
871         return rc;
872 }],
873         [ol_cv_c_posix_regex=yes],
874         [ol_cv_c_posix_regex=no],
875         [ol_cv_c_posix_regex=cross])])
876 ])
877 dnl
878 dnl ====================================================================
879 dnl Check if toupper() requires islower() to be called first
880 AC_DEFUN([OL_C_UPPER_LOWER],
881 [AC_CACHE_CHECK([if toupper() requires islower()],ol_cv_c_upper_lower,[
882         AC_TRY_RUN([
883 #include <ctype.h>
884 main()
885 {
886         if ('C' == toupper('C'))
887                 exit(0);
888         else
889                 exit(1);
890 }],
891         [ol_cv_c_upper_lower=no],
892         [ol_cv_c_upper_lower=yes],
893         [ol_cv_c_upper_lower=safe])])
894 if test $ol_cv_c_upper_lower != no ; then
895         AC_DEFINE(C_UPPER_LOWER,1, [define if toupper() requires islower()])
896 fi
897 ])
898 dnl
899 dnl ====================================================================
900 dnl Check for declaration of sys_errlist in one of stdio.h and errno.h.
901 dnl Declaration of sys_errlist on BSD4.4 interferes with our declaration.
902 dnl Reported by Keith Bostic.
903 AC_DEFUN([OL_SYS_ERRLIST],
904 [AC_CACHE_CHECK([declaration of sys_errlist],ol_cv_dcl_sys_errlist,[
905         AC_TRY_COMPILE([
906 #include <stdio.h>
907 #include <sys/types.h>
908 #include <errno.h>
909 #ifdef WINNT
910 #include <stdlib.h>
911 #endif ],
912         [char *c = (char *) *sys_errlist],
913         [ol_cv_dcl_sys_errlist=yes
914         ol_cv_have_sys_errlist=yes],
915         [ol_cv_dcl_sys_errlist=no])])
916 #
917 # It's possible (for near-UNIX clones) that sys_errlist doesn't exist
918 if test $ol_cv_dcl_sys_errlist = no ; then
919         AC_DEFINE(DECL_SYS_ERRLIST,1,
920                 [define if sys_errlist is not declared in stdio.h or errno.h])
921
922         AC_CACHE_CHECK([existence of sys_errlist],ol_cv_have_sys_errlist,[
923                 AC_TRY_LINK([#include <errno.h>],
924                         [char *c = (char *) *sys_errlist],
925                         [ol_cv_have_sys_errlist=yes],
926                         [ol_cv_have_sys_errlist=no])])
927 fi
928 if test $ol_cv_have_sys_errlist = yes ; then
929         AC_DEFINE(HAVE_SYS_ERRLIST,1,
930                 [define if you actually have sys_errlist in your libs])
931 fi
932 ])dnl
933 dnl
934 dnl ====================================================================
935 dnl Early MIPS compilers (used in Ultrix 4.2) don't like
936 dnl "int x; int *volatile a = &x; *a = 0;"
937 dnl     -- borrowed from PDKSH
938 AC_DEFUN(OL_C_VOLATILE,
939  [AC_CACHE_CHECK(if compiler understands volatile, ol_cv_c_volatile,
940     [AC_TRY_COMPILE([int x, y, z;],
941       [volatile int a; int * volatile b = x ? &y : &z;
942       /* Older MIPS compilers (eg., in Ultrix 4.2) don't like *b = 0 */
943       *b = 0;], ol_cv_c_volatile=yes, ol_cv_c_volatile=no)])
944   if test $ol_cv_c_volatile = yes; then
945     : 
946   else
947     AC_DEFINE(volatile,,[define as empty if volatile is not supported])
948   fi
949  ])dnl
950 dnl
951 dnl ====================================================================
952 dnl Look for fetch(3)
953 AC_DEFUN([OL_LIB_FETCH],
954 [ol_LIBS=$LIBS
955 LIBS="-lfetch -lcom_err $LIBS"
956 AC_CACHE_CHECK([fetch(3) library],ol_cv_lib_fetch,[
957         AC_TRY_LINK([
958 #include <sys/param.h>
959 #include <stdio.h>
960 #include <fetch.h>],
961         [struct url *u = fetchParseURL("file:///"); ],
962         [ol_cv_lib_fetch=yes],
963         [ol_cv_lib_fetch=no])])
964 LIBS=$ol_LIBS
965 if test $ol_cv_lib_fetch != no ; then
966         ol_link_fetch="-lfetch -lcom_err"
967         AC_DEFINE(HAVE_FETCH,1,
968                 [define if you actually have FreeBSD fetch(3)])
969 fi
970 ])dnl
971 dnl
972 dnl ====================================================================
973 dnl Define sig_atomic_t if not defined in signal.h
974 AC_DEFUN(OL_TYPE_SIG_ATOMIC_T,
975  [AC_CACHE_CHECK(for sig_atomic_t, ol_cv_type_sig_atomic_t,
976     [AC_TRY_COMPILE([#include <signal.h>], [sig_atomic_t atomic;],
977                 ol_cv_type_sig_atomic_t=yes, ol_cv_type_sig_atomic_t=no)])
978   if test $ol_cv_type_sig_atomic_t = no; then
979     AC_DEFINE(sig_atomic_t,int,
980                 [define to atomic type if sig_atomic_t is not available])
981   fi
982  ])dnl
983 dnl
984 dnl ====================================================================
985 dnl Define socklen_t if not defined in sys/types.h or sys/socket.h
986 AC_DEFUN(OL_TYPE_SOCKLEN_T,
987  [AC_CACHE_CHECK(for socklen_t, ol_cv_type_socklen_t,
988     [AC_TRY_COMPILE([
989 #ifdef HAVE_SYS_TYPES_H
990 #include <sys/types.h>
991 #endif
992 #ifdef HAVE_SYS_SOCKET_H
993 #include <sys/socket.h>
994 #endif
995 ], [socklen_t len;],
996                 ol_cv_type_socklen_t=yes, ol_cv_type_socklen_t=no)])
997   if test $ol_cv_type_socklen_t = no; then
998     AC_DEFINE(socklen_t, int,
999                 [define to int if socklen_t is not available])
1000   fi
1001  ])dnl
1002 dnl
1003 dnl ====================================================================
1004 dnl Define inet_aton is available
1005 AC_DEFUN(OL_FUNC_INET_ATON,
1006  [AC_CACHE_CHECK([for inet_aton()], ol_cv_func_inet_aton,
1007     [AC_TRY_LINK([
1008 #ifdef HAVE_SYS_TYPES_H
1009 #       include <sys/types.h>
1010 #endif
1011 #ifdef HAVE_SYS_SOCKET_H
1012 #       include <sys/socket.h>
1013 #       ifdef HAVE_SYS_SELECT_H
1014 #               include <sys/select.h>
1015 #       endif
1016 #       include <netinet/in.h>
1017 #       ifdef HAVE_ARPA_INET_H
1018 #               include <arpa/inet.h>
1019 #       endif
1020 #endif
1021 ], [struct in_addr in;
1022 int rc = inet_aton( "255.255.255.255", &in );],
1023                 ol_cv_func_inet_aton=yes, ol_cv_func_inet_aton=no)])
1024   if test $ol_cv_func_inet_aton != no; then
1025     AC_DEFINE(HAVE_INET_ATON, 1,
1026                 [define to you inet_aton(3) is available])
1027   fi
1028  ])dnl
1029 dnl
1030 dnl ====================================================================
1031 dnl check no of arguments for ctime_r
1032 AC_DEFUN(OL_FUNC_CTIME_R_NARGS,
1033  [AC_CACHE_CHECK(number of arguments of ctime_r, ol_cv_func_ctime_r_nargs,
1034    [AC_TRY_COMPILE([#include <time.h>],
1035                 [time_t ti; char *buffer; ctime_r(&ti,buffer,32);],
1036                         ol_cv_func_ctime_r_nargs3=yes,
1037                         ol_cv_func_ctime_r_nargs3=no)
1038
1039         AC_TRY_COMPILE([#include <time.h>],
1040                 [time_t ti; char *buffer; ctime_r(&ti,buffer);],
1041                         ol_cv_func_ctime_r_nargs2=yes,
1042                         ol_cv_func_ctime_r_nargs2=no)
1043
1044         if test $ol_cv_func_ctime_r_nargs3 = yes -a \
1045                 $ol_cv_func_ctime_r_nargs2 = no ; then
1046
1047                 ol_cv_func_ctime_r_nargs=3
1048
1049         elif test $ol_cv_func_ctime_r_nargs3 = no -a \
1050                 $ol_cv_func_ctime_r_nargs2 = yes ; then
1051
1052                 ol_cv_func_ctime_r_nargs=2
1053
1054         else
1055                 ol_cv_func_ctime_r_nargs=0
1056         fi
1057   ])
1058
1059   if test $ol_cv_func_ctime_r_nargs -gt 1 ; then
1060         AC_DEFINE_UNQUOTED(CTIME_R_NARGS, $ol_cv_func_ctime_r_nargs,
1061                 [set to the number of arguments ctime_r() expects])
1062   fi
1063 ])dnl
1064 dnl
1065 dnl --------------------------------------------------------------------
1066 dnl check return type of ctime_r()
1067 AC_DEFUN(OL_FUNC_CTIME_R_TYPE,
1068  [AC_CACHE_CHECK(return type of ctime_r, ol_cv_func_ctime_r_type,
1069    [AC_TRY_COMPILE([#include <time.h>],
1070                 [extern int (ctime_r)();],
1071                         ol_cv_func_ctime_r_type="int", ol_cv_func_ctime_r_type="charp")
1072         ])
1073   if test $ol_cv_func_ctime_r_type = "int" ; then
1074         AC_DEFINE(CTIME_R_RETURNS_INT,1, [define if ctime_r() returns int])
1075   fi
1076 ])dnl
1077 dnl ====================================================================
1078 dnl check no of arguments for gethostbyname_r
1079 AC_DEFUN(OL_FUNC_GETHOSTBYNAME_R_NARGS,
1080  [AC_CACHE_CHECK(number of arguments of gethostbyname_r,
1081         ol_cv_func_gethostbyname_r_nargs,
1082         [AC_TRY_COMPILE([#include <sys/types.h>
1083 #include <sys/socket.h>
1084 #include <netinet/in.h>
1085 #include <netdb.h>
1086 #define BUFSIZE (sizeof(struct hostent)+10)],
1087                 [struct hostent hent; char buffer[BUFSIZE];
1088                 int bufsize=BUFSIZE;int h_errno;
1089                 (void)gethostbyname_r("segovia.cs.purdue.edu", &hent,
1090                         buffer, bufsize, &h_errno);],
1091                 ol_cv_func_gethostbyname_r_nargs5=yes, 
1092                 ol_cv_func_gethostbyname_r_nargs5=no)
1093
1094         AC_TRY_COMPILE([#include <sys/types.h>
1095 #include <sys/socket.h>
1096 #include <netinet/in.h>
1097 #include <netdb.h>
1098 #define BUFSIZE (sizeof(struct hostent)+10)],
1099                 [struct hostent hent;struct hostent *rhent;
1100                 char buffer[BUFSIZE];
1101                 int bufsize=BUFSIZE;int h_errno;
1102                 (void)gethostbyname_r("localhost", &hent, buffer, bufsize,
1103                         &rhent, &h_errno);],
1104                 ol_cv_func_gethostbyname_r_nargs6=yes,
1105                 ol_cv_func_gethostbyname_r_nargs6=no)
1106
1107         if test $ol_cv_func_gethostbyname_r_nargs5 = yes -a \
1108                 $ol_cv_func_gethostbyname_r_nargs6 = no ; then
1109
1110                 ol_cv_func_gethostbyname_r_nargs=5
1111
1112         elif test $ol_cv_func_gethostbyname_r_nargs5 = no -a \
1113                 $ol_cv_func_gethostbyname_r_nargs6 = yes ; then
1114
1115                 ol_cv_func_gethostbyname_r_nargs=6
1116
1117         else
1118                 ol_cv_func_gethostbyname_r_nargs=0
1119         fi
1120   ])
1121   if test $ol_cv_func_gethostbyname_r_nargs -gt 1 ; then
1122         AC_DEFINE_UNQUOTED(GETHOSTBYNAME_R_NARGS,
1123                 $ol_cv_func_gethostbyname_r_nargs,
1124                 [set to the number of arguments gethostbyname_r() expects])
1125   fi
1126 ])dnl
1127 dnl
1128 dnl check no of arguments for gethostbyaddr_r
1129 AC_DEFUN(OL_FUNC_GETHOSTBYADDR_R_NARGS,
1130  [AC_CACHE_CHECK(number of arguments of gethostbyaddr_r,
1131         [ol_cv_func_gethostbyaddr_r_nargs],
1132         [AC_TRY_COMPILE([#include <sys/types.h>
1133 #include <sys/socket.h>
1134 #include <netinet/in.h>
1135 #include <netdb.h>
1136 #define BUFSIZE (sizeof(struct hostent)+10)],
1137            [struct hostent hent; char buffer[BUFSIZE]; 
1138             struct in_addr add;
1139             size_t alen=sizeof(struct in_addr);
1140             int bufsize=BUFSIZE;int h_errno;
1141                 (void)gethostbyaddr_r( (void *)&(add.s_addr),
1142                         alen, AF_INET, &hent, buffer, bufsize, &h_errno);],
1143                 ol_cv_func_gethostbyaddr_r_nargs7=yes,
1144                 ol_cv_func_gethostbyaddr_r_nargs7=no)
1145
1146         AC_TRY_COMPILE([#include <sys/types.h>
1147 #include <sys/socket.h>
1148 #include <netinet/in.h>
1149 #include <netdb.h>
1150 #define BUFSIZE (sizeof(struct hostent)+10)],
1151                 [struct hostent hent;
1152                 struct hostent *rhent; char buffer[BUFSIZE]; 
1153                 struct in_addr add;
1154                 size_t alen=sizeof(struct in_addr);
1155                 int bufsize=BUFSIZE;int h_errno;
1156                 (void)gethostbyaddr_r( (void *)&(add.s_addr),
1157                         alen, AF_INET, &hent, buffer, bufsize, 
1158                         &rhent, &h_errno);],
1159                 ol_cv_func_gethostbyaddr_r_nargs8=yes,
1160                 ol_cv_func_gethostbyaddr_r_nargs8=no)
1161
1162         if test $ol_cv_func_gethostbyaddr_r_nargs7 = yes -a \
1163                 $ol_cv_func_gethostbyaddr_r_nargs8 = no ; then
1164
1165                 ol_cv_func_gethostbyaddr_r_nargs=7
1166
1167         elif test $ol_cv_func_gethostbyaddr_r_nargs7 = no -a \
1168                 $ol_cv_func_gethostbyaddr_r_nargs8 = yes ; then
1169
1170                 ol_cv_func_gethostbyaddr_r_nargs=8
1171
1172         else
1173                 ol_cv_func_gethostbyaddr_r_nargs=0
1174         fi
1175   ])
1176   if test $ol_cv_func_gethostbyaddr_r_nargs -gt 1 ; then
1177     AC_DEFINE_UNQUOTED(GETHOSTBYADDR_R_NARGS,
1178                 $ol_cv_func_gethostbyaddr_r_nargs,
1179                 [set to the number of arguments gethostbyaddr_r() expects])
1180   fi
1181 ])dnl
1182 dnl
1183 dnl --------------------------------------------------------------------
1184 dnl Check for Cyrus SASL version compatility, need 2.1.3 or newer
1185 AC_DEFUN([OL_SASL_COMPAT],
1186 [AC_CACHE_CHECK([Cyrus SASL library version], [ol_cv_sasl_compat],[
1187         AC_EGREP_CPP(__sasl_compat,[
1188 #ifdef HAVE_SASL_SASL_H
1189 #include <sasl/sasl.h>
1190 #else
1191 #include <sasl.h>
1192 #endif
1193
1194 /* require 2.1.3 or later */
1195 #if SASL_VERSION_MAJOR == 1  && SASL_VERSION_MINOR >= 5
1196         char *__sasl_compat = "1.5.x okay";
1197 #elif SASL_VERSION_MAJOR == 2  && SASL_VERSION_MINOR > 1
1198         __sasl_compat "2.2+ or better okay (we guess)";
1199 #elif SASL_VERSION_MAJOR == 2  && SASL_VERSION_MINOR == 1 \
1200         && SASL_VERSION_STEP >=3
1201         __sasl_compat = "2.1.3+ or better okay";
1202 #endif
1203         ],      [ol_cv_sasl_compat=yes], [ol_cv_sasl_compat=no])])
1204 ])
1205 dnl ====================================================================
1206 dnl check for msg_accrights in msghdr
1207 AC_DEFUN(OL_MSGHDR_MSG_ACCRIGHTS,
1208  [AC_CHECK_MEMBER(struct msghdr.msg_accrights,,,[#include <sys/socket.h>])
1209    if test $ac_cv_member_struct_msghdr_msg_accrights = "yes" ; then
1210                 AC_DEFINE(HAVE_MSGHDR_MSG_ACCRIGHTS,1,
1211                         [define if struct msghdr has msg_accrights])
1212    fi
1213 ])dnl