]> git.sur5r.net Git - openldap/blob - build/openldap.m4
Fix AC_CACHE_CHECK bug in DB_THREAD detection.
[openldap] / build / openldap.m4
1 dnl $OpenLDAP$
2 dnl
3 dnl Copyright 1998-2002 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_CACHE_CHECK([struct passwd for pw_gecos],ol_cv_struct_passwd_pw_gecos,[
220         AC_TRY_COMPILE([#include <pwd.h>],[
221         struct passwd pwd;
222         pwd.pw_gecos = pwd.pw_name;
223 ],
224         [ol_cv_struct_passwd_pw_gecos=yes],
225         [ol_cv_struct_passwd_pw_gecos=no])])
226 if test $ol_cv_struct_passwd_pw_gecos = yes ; then
227         AC_DEFINE(HAVE_PW_GECOS,1, [define if struct passwd has pw_gecos])
228 fi
229 ])
230 dnl
231 dnl --------------------------------------------------------------------
232 dnl Check if struct passwd has pw_passwd
233 AC_DEFUN([OL_STRUCT_PASSWD_PW_PASSWD], [# test for pw_passwd in struct passwd
234 AC_CACHE_CHECK([struct passwd for pw_passwd],ol_cv_struct_passwd_pw_passwd,[
235         AC_TRY_COMPILE([#include <pwd.h>],[
236         struct passwd pwd;
237         pwd.pw_passwd = pwd.pw_name;
238 ],
239         [ol_cv_struct_passwd_pw_passwd=yes],
240         [ol_cv_struct_passwd_pw_passwd=no])])
241 if test $ol_cv_struct_passwd_pw_passwd = yes ; then
242         AC_DEFINE(HAVE_PW_PASSWD,1, [define if struct passwd has pw_passwd])
243 fi
244 ])
245 dnl
246 dnl ====================================================================
247 dnl Berkeley DB macros
248 dnl
249 dnl --------------------------------------------------------------------
250 dnl Try to link
251 AC_DEFUN([OL_BERKELEY_DB_TRY],
252 [if test $ol_cv_lib_db = no ; then
253         AC_CACHE_CHECK([for Berkeley DB link (]ifelse($2,,default,$2)[)],[$1],
254 [
255         ol_DB_LIB=ifelse($2,,,$2)
256         ol_LIBS=$LIBS
257         LIBS="$ol_DB_LIB $LIBS"
258
259         AC_TRY_LINK([
260 #ifdef HAVE_DB_185_H
261 # include <db_185.h>
262 #else
263 # include <db.h>
264 #endif
265
266 #ifndef DB_VERSION_MAJOR
267 # define DB_VERSION_MAJOR 1
268 #endif
269
270 #ifndef NULL
271 #define NULL ((void*)0)
272 #endif
273 ],[
274 #if DB_VERSION_MAJOR > 1
275         {
276                 char *version;
277                 int major, minor, patch;
278
279                 version = db_version( &major, &minor, &patch );
280
281                 if( major != DB_VERSION_MAJOR ||
282                         minor < DB_VERSION_MINOR )
283                 {
284                         printf("Berkeley DB version mismatch\n"
285                                 "\texpected: %s\n\tgot: %s\n",
286                                 DB_VERSION_STRING, version);
287                         return 1;
288                 }
289         }
290 #endif
291
292 #if DB_VERSION_MAJOR > 2
293         db_env_create( NULL, 0 );
294 #elif DB_VERSION_MAJOR > 1
295         db_appexit( NULL );
296 #else
297         (void) dbopen( NULL, 0, 0, 0, NULL);
298 #endif
299 ],[$1=yes],[$1=no])
300
301         LIBS="$ol_LIBS"
302 ])
303
304         if test $$1 = yes ; then
305                 ol_cv_lib_db=ifelse($2,,yes,$2)
306         fi
307 fi
308 ])
309 dnl
310 dnl --------------------------------------------------------------------
311 dnl Try to locate appropriate library
312 AC_DEFUN([OL_BERKELEY_DB_LINK],
313 [ol_cv_lib_db=no
314 OL_BERKELEY_DB_TRY(ol_cv_db_none)
315 OL_BERKELEY_DB_TRY(ol_cv_db_db4,[-ldb4])
316 OL_BERKELEY_DB_TRY(ol_cv_db_db_4,[-ldb-4])
317 OL_BERKELEY_DB_TRY(ol_cv_db_db,[-ldb])
318 OL_BERKELEY_DB_TRY(ol_cv_db_db3,[-ldb3])
319 OL_BERKELEY_DB_TRY(ol_cv_db_db_3,[-ldb-3])
320 OL_BERKELEY_DB_TRY(ol_cv_db_db2,[-ldb2])
321 OL_BERKELEY_DB_TRY(ol_cv_db_db_2,[-ldb-2])
322 OL_BERKELEY_DB_TRY(ol_cv_db_db1,[-ldb1])
323 OL_BERKELEY_DB_TRY(ol_cv_db_db_1,[-ldb-1])
324 ])
325 dnl
326 dnl --------------------------------------------------------------------
327 dnl Check if Berkeley DB supports DB_THREAD
328 AC_DEFUN([OL_BERKELEY_DB_THREAD],
329 [AC_CACHE_CHECK([for Berkeley DB thread support], [ol_cv_berkeley_db_thread], [
330         ol_LIBS="$LIBS"
331         if test $ol_cv_lib_db != yes ; then
332                 LIBS="$ol_cv_lib_db"
333         fi
334
335         AC_TRY_RUN([
336 #ifdef HAVE_DB_185_H
337         choke me;
338 #else
339 #include <db.h>
340 #endif
341 #ifndef NULL
342 #define NULL ((void *)0)
343 #endif
344 main()
345 {
346         int rc;
347         u_int32_t flags = DB_CREATE |
348 #ifdef DB_PRIVATE
349                 DB_PRIVATE |
350 #endif
351                 DB_THREAD;
352
353 #if DB_VERSION_MAJOR > 2
354         DB_ENV *env = NULL;
355
356         rc = db_env_create( &env, 0 );
357
358         flags |= DB_INIT_MPOOL;
359 #ifdef DB_MPOOL_PRIVATE
360         flags |= DB_MPOOL_PRIVATE;
361 #endif
362
363         if( rc ) {
364                 printf("BerkeleyDB: %s\n", db_strerror(rc) );
365                 return rc;
366         }
367
368 #if (DB_VERSION_MAJOR > 3) || (DB_VERSION_MINOR >= 1)
369         rc = env->open( env, NULL, flags, 0 );
370 #else
371         rc = env->open( env, NULL, NULL, flags, 0 );
372 #endif
373
374         if ( rc == 0 ) {
375                 rc = env->close( env, 0 );
376         }
377
378         if( rc ) {
379                 printf("BerkeleyDB: %s\n", db_strerror(rc) );
380                 return rc;
381         }
382
383 #else
384         DB_ENV env;
385         memset( &env, '\0', sizeof(env) );
386
387         rc = db_appinit( NULL, NULL, &env, flags );
388
389         if( rc == 0 ) {
390                 db_appexit( &env );
391         }
392
393         unlink("__db_mpool.share");
394         unlink("__db_lock.share");
395 #endif
396
397         return rc;
398 }],
399         [ol_cv_berkeley_db_thread=yes],
400         [ol_cv_berkeley_db_thread=no],
401         [ol_cv_berkeley_db_thread=cross])
402
403         LIBS="$ol_LIBS"
404 ])
405
406         if test $ol_cv_berkeley_db_thread != no ; then
407                 AC_DEFINE(HAVE_BERKELEY_DB_THREAD, 1,
408                         [define if Berkeley DB has DB_THREAD support])
409         fi
410 ])dnl
411 dnl
412 dnl --------------------------------------------------------------------
413 dnl Find any DB
414 AC_DEFUN([OL_BERKELEY_DB],
415 [ol_cv_berkeley_db=no
416 AC_CHECK_HEADERS(db.h)
417 if test $ac_cv_header_db_h = yes; then
418         OL_BERKELEY_DB_LINK
419         if test "$ol_cv_lib_db" != no ; then
420                 ol_cv_berkeley_db=yes
421                 OL_BERKELEY_DB_THREAD
422         fi
423 fi
424 ])
425 dnl --------------------------------------------------------------------
426 dnl Check for version compatility with back-bdb
427 AC_DEFUN([OL_BDB_COMPAT],
428 [AC_CACHE_CHECK([Berkeley DB version for BDB backend], [ol_cv_bdb_compat],[
429         AC_EGREP_CPP(__db_version_compat,[
430 #include <db.h>
431
432  /* this check could be improved */
433 #ifndef DB_VERSION_MAJOR
434 #       define DB_VERSION_MAJOR 1
435 #endif
436
437 /* require 4.0 or later */
438 #if DB_VERSION_MAJOR >= 4 
439         __db_version_compat
440 #endif
441         ], [ol_cv_bdb_compat=yes], [ol_cv_bdb_compat=no])])
442 ])
443
444 dnl --------------------------------------------------------------------
445 dnl Find old Berkeley DB 1.85/1.86
446 AC_DEFUN([OL_BERKELEY_COMPAT_DB],
447 [AC_CHECK_HEADERS(db_185.h db.h)
448 if test $ac_cv_header_db_185_h = yes -o $ac_cv_header_db_h = yes; then
449         AC_CACHE_CHECK([if Berkeley DB header compatibility], [ol_cv_header_db1],[
450                 AC_EGREP_CPP(__db_version_1,[
451 #if HAVE_DB_185_H
452 #       include <db_185.h>
453 #else
454 #       include <db.h>
455 #endif
456
457  /* this check could be improved */
458 #ifndef DB_VERSION_MAJOR
459 #       define DB_VERSION_MAJOR 1
460 #endif
461
462 #if DB_VERSION_MAJOR == 1 
463         __db_version_1
464 #endif
465 ],      [ol_cv_header_db1=yes], [ol_cv_header_db1=no])])
466
467         if test $ol_cv_header_db1 = yes ; then
468                 OL_BERKELEY_DB_LINK
469                 if test "$ol_cv_lib_db" != no ; then
470                         ol_cv_berkeley_db=yes
471                 fi
472         fi
473 fi
474 ])
475 dnl
476 dnl ====================================================================
477 dnl Check if GDBM library exists
478 dnl Check for gdbm_open in standard libraries or -lgdbm
479 dnl
480 dnl defines ol_cv_lib_gdbm to 'yes' or '-lgdbm' or 'no'
481 dnl             'yes' implies gdbm_open is in $LIBS
482 dnl
483 dnl uses:
484 dnl             AC_CHECK_FUNC(gdbm_open)
485 dnl             AC_CHECK_LIB(gdbm,gdbm_open)
486 dnl
487 AC_DEFUN([OL_LIB_GDBM],
488 [AC_CACHE_CHECK(for GDBM library, [ol_cv_lib_gdbm],
489 [       ol_LIBS="$LIBS"
490         AC_CHECK_FUNC(gdbm_open,[ol_cv_lib_gdbm=yes], [
491                 AC_CHECK_LIB(gdbm,gdbm_open,[ol_cv_lib_gdbm=-lgdbm],[ol_cv_lib_gdbm=no])
492         ])
493         LIBS="$ol_LIBS"
494 ])
495 ])dnl
496 dnl
497 dnl --------------------------------------------------------------------
498 dnl Check if GDBM exists
499 dnl
500 dnl defines ol_cv_gdbm to 'yes' or 'no'
501 dnl 
502 dnl uses:
503 dnl             OL_LIB_GDBM
504 dnl             AC_CHECK_HEADERS(gdbm.h)
505 dnl
506 AC_DEFUN([OL_GDBM],
507 [AC_REQUIRE([OL_LIB_GDBM])
508  AC_CHECK_HEADERS(gdbm.h)
509  AC_CACHE_CHECK(for db, [ol_cv_gdbm], [
510         if test $ol_cv_lib_gdbm = no -o $ac_cv_header_gdbm_h = no ; then
511                 ol_cv_gdbm=no
512         else
513                 ol_cv_gdbm=yes
514         fi
515 ])
516  if test $ol_cv_gdbm = yes ; then
517         AC_DEFINE(HAVE_GDBM,1, [define if GNU DBM is available])
518  fi
519 ])dnl
520 dnl
521 dnl ====================================================================
522 dnl Check if MDBM library exists
523 dnl Check for mdbm_open in standard libraries or -lmdbm
524 dnl
525 dnl defines ol_cv_lib_mdbm to 'yes' or '-lmdbm' or 'no'
526 dnl             'yes' implies mdbm_open is in $LIBS
527 dnl
528 dnl uses:
529 dnl             AC_CHECK_FUNC(mdbm_set_chain)
530 dnl             AC_CHECK_LIB(mdbm,mdbm_set_chain)
531 dnl
532 AC_DEFUN([OL_LIB_MDBM],
533 [AC_CACHE_CHECK(for MDBM library, [ol_cv_lib_mdbm],
534 [       ol_LIBS="$LIBS"
535         AC_CHECK_FUNC(mdbm_set_chain,[ol_cv_lib_mdbm=yes], [
536                 AC_CHECK_LIB(mdbm,mdbm_set_chain,[ol_cv_lib_mdbm=-lmdbm],[ol_cv_lib_mdbm=no])
537         ])
538         LIBS="$ol_LIBS"
539 ])
540 ])dnl
541 dnl
542 dnl --------------------------------------------------------------------
543 dnl Check if MDBM exists
544 dnl
545 dnl defines ol_cv_mdbm to 'yes' or 'no'
546 dnl 
547 dnl uses:
548 dnl             OL_LIB_MDBM
549 dnl             AC_CHECK_HEADERS(mdbm.h)
550 dnl
551 AC_DEFUN([OL_MDBM],
552 [AC_REQUIRE([OL_LIB_MDBM])
553  AC_CHECK_HEADERS(mdbm.h)
554  AC_CACHE_CHECK(for db, [ol_cv_mdbm], [
555         if test $ol_cv_lib_mdbm = no -o $ac_cv_header_mdbm_h = no ; then
556                 ol_cv_mdbm=no
557         else
558                 ol_cv_mdbm=yes
559         fi
560 ])
561  if test $ol_cv_mdbm = yes ; then
562         AC_DEFINE(HAVE_MDBM,1, [define if MDBM is available])
563  fi
564 ])dnl
565 dnl
566 dnl ====================================================================
567 dnl Check if NDBM library exists
568 dnl Check for dbm_open in standard libraries or -lndbm or -ldbm
569 dnl
570 dnl defines ol_cv_lib_ndbm to 'yes' or '-lndbm' or -ldbm or 'no'
571 dnl             'yes' implies ndbm_open is in $LIBS
572 dnl
573 dnl uses:
574 dnl             AC_CHECK_FUNC(dbm_open)
575 dnl             AC_CHECK_LIB(ndbm,dbm_open)
576 dnl             AC_CHECK_LIB(dbm,dbm_open)
577 dnl
578 dnl restrictions:
579 dnl             should also check SVR4 case: dbm_open() in -lucb but that
580 dnl             would requiring dealing with -L/usr/ucblib
581 dnl
582 AC_DEFUN([OL_LIB_NDBM],
583 [AC_CACHE_CHECK(for NDBM library, [ol_cv_lib_ndbm],
584 [       ol_LIBS="$LIBS"
585         AC_CHECK_FUNC(dbm_open,[ol_cv_lib_ndbm=yes], [
586                 AC_CHECK_LIB(ndbm,dbm_open,[ol_cv_lib_ndbm=-lndbm], [
587                         AC_CHECK_LIB(dbm,dbm_open,[ol_cv_lib_ndbm=-ldbm],
588                                 [ol_cv_lib_ndbm=no])dnl
589                 ])
590         ])
591         LIBS="$ol_LIBS"
592 ])
593 ])dnl
594 dnl
595 dnl --------------------------------------------------------------------
596 dnl Check if NDBM exists
597 dnl
598 dnl defines ol_cv_ndbm to 'yes' or 'no'
599 dnl 
600 dnl uses:
601 dnl             OL_LIB_NDBM
602 dnl             AC_CHECK_HEADERS(ndbm.h)
603 dnl
604 dnl restrictions:
605 dnl             Doesn't handle SVR4 case (see above)
606 dnl
607 AC_DEFUN([OL_NDBM],
608 [AC_REQUIRE([OL_LIB_NDBM])
609  AC_CHECK_HEADERS(ndbm.h)
610  AC_CACHE_CHECK(for db, [ol_cv_ndbm], [
611         if test $ol_cv_lib_ndbm = no -o $ac_cv_header_ndbm_h = no ; then
612                 ol_cv_ndbm=no
613         else
614                 ol_cv_ndbm=yes
615         fi
616 ])
617  if test $ol_cv_ndbm = yes ; then
618         AC_DEFINE(HAVE_NDBM,1, [define if NDBM is available])
619  fi
620 ])dnl
621 dnl
622 dnl ====================================================================
623 dnl Check POSIX Thread version 
624 dnl
625 dnl defines ol_cv_pthread_version to 4, 5, 6, 7, 8, 10, depending on the
626 dnl     version of the POSIX.4a Draft that is implemented.
627 dnl     10 == POSIX.4a Final == POSIX.1c-1996 for our purposes.
628 dnl     Existence of pthread.h should be tested separately.
629 dnl
630 dnl tests:
631 dnl     pthread_detach() was dropped in Draft 8, it is present
632 dnl             in every other version
633 dnl     PTHREAD_CREATE_UNDETACHED is only in Draft 7, it was called
634 dnl             PTHREAD_CREATE_JOINABLE after that
635 dnl     pthread_attr_create was renamed to pthread_attr_init in Draft 6.
636 dnl             Draft 6-10 has _init, Draft 4-5 has _create.
637 dnl     pthread_attr_default was dropped in Draft 6, only 4 and 5 have it
638 dnl     PTHREAD_MUTEX_INITIALIZER was introduced in Draft 5. It's not
639 dnl             interesting to us because we don't try to statically
640 dnl             initialize mutexes. 5-10 has it.
641 dnl
642 dnl Draft 9 and 10 are equivalent for our purposes.
643 dnl
644 AC_DEFUN([OL_POSIX_THREAD_VERSION],
645 [AC_CACHE_CHECK([POSIX thread version],[ol_cv_pthread_version],[
646         AC_TRY_COMPILE([
647 #               include <pthread.h>
648         ],[
649                 int i = PTHREAD_CREATE_JOINABLE;
650         ],[
651         AC_EGREP_HEADER(pthread_detach,pthread.h,
652         ol_cv_pthread_version=10, ol_cv_pthread_version=8)],[
653         AC_EGREP_CPP(draft7,[
654 #               include <pthread.h>
655 #               ifdef PTHREAD_CREATE_UNDETACHED
656                 draft7
657 #               endif
658         ], ol_cv_pthread_version=7, [
659         AC_EGREP_HEADER(pthread_attr_init,pthread.h,
660         ol_cv_pthread_version=6, [
661         AC_EGREP_CPP(draft5,[
662 #               include <pthread.h>
663 #ifdef          PTHREAD_MUTEX_INITIALIZER
664                 draft5
665 #endif
666         ], ol_cv_pthread_version=5, ol_cv_pthread_version=4) ]) ]) ])
667 ])
668 ])dnl
669 dnl
670 dnl --------------------------------------------------------------------
671 AC_DEFUN([OL_PTHREAD_TEST_INCLUDES],
672 [/* pthread test headers */
673 #include <pthread.h>
674 #if HAVE_PTHREADS < 7
675 #include <errno.h>
676 #endif
677 #ifndef NULL
678 #define NULL (void*)0
679 #endif
680
681 static void *task(p)
682         void *p;
683 {
684         return (void *) (p == NULL);
685 }
686 ])
687 AC_DEFUN([OL_PTHREAD_TEST_FUNCTION],[
688         /* pthread test function */
689 #ifndef PTHREAD_CREATE_DETACHED
690 #define PTHREAD_CREATE_DETACHED 1
691 #endif
692         pthread_t t;
693         int status;
694         int detach = PTHREAD_CREATE_DETACHED;
695
696 #if HAVE_PTHREADS > 4
697         /* Final pthreads */
698         pthread_attr_t attr;
699
700         status = pthread_attr_init(&attr);
701         if( status ) return status;
702
703 #if HAVE_PTHREADS < 7
704         status = pthread_attr_setdetachstate(&attr, &detach);
705         if( status < 0 ) status = errno;
706 #else
707         status = pthread_attr_setdetachstate(&attr, detach);
708 #endif
709         if( status ) return status;
710         status = pthread_create( &t, &attr, task, NULL );
711 #if HAVE_PTHREADS < 7
712         if( status < 0 ) status = errno;
713 #endif
714         if( status ) return status;
715 #else
716         /* Draft 4 pthreads */
717         status = pthread_create( &t, pthread_attr_default, task, NULL );
718         if( status ) return errno;
719
720         /* give thread a chance to complete */
721         /* it should remain joinable and hence detachable */
722         sleep( 1 );
723
724         status = pthread_detach( &t );
725         if( status ) return errno;
726 #endif
727
728 #ifdef HAVE_LINUX_THREADS
729         pthread_kill_other_threads_np();
730 #endif
731
732         return 0;
733 ])
734
735 AC_DEFUN([OL_PTHREAD_TEST_PROGRAM],
736 [OL_PTHREAD_TEST_INCLUDES
737
738 int main(argc, argv)
739         int argc;
740         char **argv;
741 {
742 OL_PTHREAD_TEST_FUNCTION
743 }
744 ])
745 dnl --------------------------------------------------------------------
746 AC_DEFUN([OL_PTHREAD_TRY], [# Pthread try link: $1 ($2)
747 if test "$ol_link_threads" = no ; then
748         # try $1
749         AC_CACHE_CHECK([for pthread link with $1], [$2], [
750                 # save the flags
751                 ol_LIBS="$LIBS"
752                 LIBS="$1 $LIBS"
753
754                 AC_TRY_RUN(OL_PTHREAD_TEST_PROGRAM,
755                         [$2=yes], [$2=no],
756                         [AC_TRY_LINK(OL_PTHREAD_TEST_INCLUDES,OL_PTHREAD_TEST_FUNCTION,
757                                 [$2=yes], [$2=no])])
758
759                 # restore the LIBS
760                 LIBS="$ol_LIBS"
761         ])
762
763         if test $$2 = yes ; then
764                 ol_link_pthreads="$1"
765                 ol_link_threads=posix
766         fi
767 fi
768 ])
769 dnl
770 dnl ====================================================================
771 dnl Check GNU Pth pthread Header
772 dnl
773 dnl defines ol_cv_header linux_threads to 'yes' or 'no'
774 dnl             'no' implies pthreads.h is not LinuxThreads or pthreads.h
775 dnl             doesn't exists.  Existance of pthread.h should separately
776 dnl             checked.
777 dnl 
778 AC_DEFUN([OL_HEADER_GNU_PTH_PTHREAD_H], [
779         AC_CACHE_CHECK([for GNU Pth pthread.h],
780                 [ol_cv_header_gnu_pth_pthread_h],
781                 [AC_EGREP_CPP(__gnu_pth__,
782                         [#include <pthread.h>
783 #ifdef _POSIX_THREAD_IS_GNU_PTH
784         __gnu_pth__;
785 #endif
786 ],
787                         [ol_cv_header_gnu_pth_pthread_h=yes],
788                         [ol_cv_header_gnu_pth_pthread_h=no])
789                 ])
790 ])dnl
791 dnl ====================================================================
792 dnl Check for NT Threads
793 AC_DEFUN([OL_NT_THREADS], [
794         AC_CHECK_FUNC(_beginthread)
795
796         if test $ac_cv_func__beginthread = yes ; then
797                 AC_DEFINE(HAVE_NT_THREADS,1,[if you have NT Threads])
798                 ol_cv_nt_threads=yes
799         fi
800 ])
801 dnl ====================================================================
802 dnl Check LinuxThreads Header
803 dnl
804 dnl defines ol_cv_header linux_threads to 'yes' or 'no'
805 dnl             'no' implies pthreads.h is not LinuxThreads or pthreads.h
806 dnl             doesn't exists.  Existance of pthread.h should separately
807 dnl             checked.
808 dnl 
809 AC_DEFUN([OL_HEADER_LINUX_THREADS], [
810         AC_CACHE_CHECK([for LinuxThreads pthread.h],
811                 [ol_cv_header_linux_threads],
812                 [AC_EGREP_CPP(pthread_kill_other_threads_np,
813                         [#include <pthread.h>],
814                         [ol_cv_header_linux_threads=yes],
815                         [ol_cv_header_linux_threads=no])
816                 ])
817         if test $ol_cv_header_linux_threads = yes; then
818                 AC_DEFINE(HAVE_LINUX_THREADS,1,[if you have LinuxThreads])
819         fi
820 ])dnl
821 dnl --------------------------------------------------------------------
822 dnl     Check LinuxThreads Implementation
823 dnl
824 dnl     defines ol_cv_sys_linux_threads to 'yes' or 'no'
825 dnl     'no' implies pthreads implementation is not LinuxThreads.
826 dnl 
827 AC_DEFUN([OL_SYS_LINUX_THREADS], [
828         AC_CHECK_FUNCS(pthread_kill_other_threads_np)
829         AC_CACHE_CHECK([for LinuxThreads implementation],
830                 [ol_cv_sys_linux_threads],
831                 [ol_cv_sys_linux_threads=$ac_cv_func_pthread_kill_other_threads_np])
832 ])dnl
833 dnl
834 dnl --------------------------------------------------------------------
835 dnl Check LinuxThreads consistency
836 AC_DEFUN([OL_LINUX_THREADS], [
837         AC_REQUIRE([OL_HEADER_LINUX_THREADS])
838         AC_REQUIRE([OL_SYS_LINUX_THREADS])
839         AC_CACHE_CHECK([for LinuxThreads consistency], [ol_cv_linux_threads], [
840                 if test $ol_cv_header_linux_threads = yes -a \
841                         $ol_cv_sys_linux_threads = yes; then
842                         ol_cv_linux_threads=yes
843                 elif test $ol_cv_header_linux_threads = no -a \
844                         $ol_cv_sys_linux_threads = no; then
845                         ol_cv_linux_threads=no
846                 else
847                         ol_cv_linux_threads=error
848                 fi
849         ])
850 ])dnl
851 dnl
852 dnl ====================================================================
853 dnl Check for POSIX Regex
854 AC_DEFUN([OL_POSIX_REGEX], [
855 AC_CACHE_CHECK([for compatible POSIX regex],ol_cv_c_posix_regex,[
856         AC_TRY_RUN([
857 #include <sys/types.h>
858 #include <regex.h>
859 static char *pattern, *string;
860 main()
861 {
862         int rc;
863         regex_t re;
864
865         pattern = "^A";
866
867         if(regcomp(&re, pattern, 0)) {
868                 return -1;
869         }
870         
871         string = "ALL MATCH";
872         
873         rc = regexec(&re, string, 0, (void*)0, 0);
874
875         regfree(&re);
876
877         return rc;
878 }],
879         [ol_cv_c_posix_regex=yes],
880         [ol_cv_c_posix_regex=no],
881         [ol_cv_c_posix_regex=cross])])
882 ])
883 dnl
884 dnl ====================================================================
885 dnl Check if toupper() requires islower() to be called first
886 AC_DEFUN([OL_C_UPPER_LOWER],
887 [AC_CACHE_CHECK([if toupper() requires islower()],ol_cv_c_upper_lower,[
888         AC_TRY_RUN([
889 #include <ctype.h>
890 main()
891 {
892         if ('C' == toupper('C'))
893                 exit(0);
894         else
895                 exit(1);
896 }],
897         [ol_cv_c_upper_lower=no],
898         [ol_cv_c_upper_lower=yes],
899         [ol_cv_c_upper_lower=safe])])
900 if test $ol_cv_c_upper_lower != no ; then
901         AC_DEFINE(C_UPPER_LOWER,1, [define if toupper() requires islower()])
902 fi
903 ])
904 dnl
905 dnl ====================================================================
906 dnl Check for declaration of sys_errlist in one of stdio.h and errno.h.
907 dnl Declaration of sys_errlist on BSD4.4 interferes with our declaration.
908 dnl Reported by Keith Bostic.
909 AC_DEFUN([OL_SYS_ERRLIST],
910 [AC_CACHE_CHECK([declaration of sys_errlist],ol_cv_dcl_sys_errlist,[
911         AC_TRY_COMPILE([
912 #include <stdio.h>
913 #include <sys/types.h>
914 #include <errno.h>
915 #ifdef WINNT
916 #include <stdlib.h>
917 #endif ],
918         [char *c = (char *) *sys_errlist],
919         [ol_cv_dcl_sys_errlist=yes
920         ol_cv_have_sys_errlist=yes],
921         [ol_cv_dcl_sys_errlist=no])])
922 #
923 # It's possible (for near-UNIX clones) that sys_errlist doesn't exist
924 if test $ol_cv_dcl_sys_errlist = no ; then
925         AC_DEFINE(DECL_SYS_ERRLIST,1,
926                 [define if sys_errlist is not declared in stdio.h or errno.h])
927
928         AC_CACHE_CHECK([existence of sys_errlist],ol_cv_have_sys_errlist,[
929                 AC_TRY_LINK([#include <errno.h>],
930                         [char *c = (char *) *sys_errlist],
931                         [ol_cv_have_sys_errlist=yes],
932                         [ol_cv_have_sys_errlist=no])])
933 fi
934 if test $ol_cv_have_sys_errlist = yes ; then
935         AC_DEFINE(HAVE_SYS_ERRLIST,1,
936                 [define if you actually have sys_errlist in your libs])
937 fi
938 ])dnl
939 dnl
940 dnl ====================================================================
941 dnl Early MIPS compilers (used in Ultrix 4.2) don't like
942 dnl "int x; int *volatile a = &x; *a = 0;"
943 dnl     -- borrowed from PDKSH
944 AC_DEFUN(OL_C_VOLATILE,
945  [AC_CACHE_CHECK(if compiler understands volatile, ol_cv_c_volatile,
946     [AC_TRY_COMPILE([int x, y, z;],
947       [volatile int a; int * volatile b = x ? &y : &z;
948       /* Older MIPS compilers (eg., in Ultrix 4.2) don't like *b = 0 */
949       *b = 0;], ol_cv_c_volatile=yes, ol_cv_c_volatile=no)])
950   if test $ol_cv_c_volatile = yes; then
951     : 
952   else
953     AC_DEFINE(volatile,,[define as empty if volatile is not supported])
954   fi
955  ])dnl
956 dnl
957 dnl ====================================================================
958 dnl Look for fetch(3)
959 AC_DEFUN([OL_LIB_FETCH],
960 [ol_LIBS=$LIBS
961 LIBS="-lfetch -lcom_err $LIBS"
962 AC_CACHE_CHECK([fetch(3) library],ol_cv_lib_fetch,[
963         AC_TRY_LINK([
964 #include <sys/param.h>
965 #include <stdio.h>
966 #include <fetch.h>],
967         [struct url *u = fetchParseURL("file:///"); ],
968         [ol_cv_lib_fetch=yes],
969         [ol_cv_lib_fetch=no])])
970 LIBS=$ol_LIBS
971 if test $ol_cv_lib_fetch != no ; then
972         ol_link_fetch="-lfetch -lcom_err"
973         AC_DEFINE(HAVE_FETCH,1,
974                 [define if you actually have FreeBSD fetch(3)])
975 fi
976 ])dnl
977 dnl
978 dnl ====================================================================
979 dnl Define sig_atomic_t if not defined in signal.h
980 AC_DEFUN(OL_TYPE_SIG_ATOMIC_T,
981  [AC_CACHE_CHECK(for sig_atomic_t, ol_cv_type_sig_atomic_t,
982     [AC_TRY_COMPILE([#include <signal.h>], [sig_atomic_t atomic;],
983                 ol_cv_type_sig_atomic_t=yes, ol_cv_type_sig_atomic_t=no)])
984   if test $ol_cv_type_sig_atomic_t = no; then
985     AC_DEFINE(sig_atomic_t,int,
986                 [define to atomic type if sig_atomic_t is not available])
987   fi
988  ])dnl
989 dnl
990 dnl ====================================================================
991 dnl Define socklen_t if not defined in sys/types.h or sys/socket.h
992 AC_DEFUN(OL_TYPE_SOCKLEN_T,
993  [AC_CACHE_CHECK(for socklen_t, ol_cv_type_socklen_t,
994     [AC_TRY_COMPILE([
995 #ifdef HAVE_SYS_TYPES_H
996 #include <sys/types.h>
997 #endif
998 #ifdef HAVE_SYS_SOCKET_H
999 #include <sys/socket.h>
1000 #endif
1001 ], [socklen_t len;],
1002                 ol_cv_type_socklen_t=yes, ol_cv_type_socklen_t=no)])
1003   if test $ol_cv_type_socklen_t = no; then
1004     AC_DEFINE(socklen_t, int,
1005                 [define to int if socklen_t is not available])
1006   fi
1007  ])dnl
1008 dnl
1009 dnl ====================================================================
1010 dnl Define inet_aton is available
1011 AC_DEFUN(OL_FUNC_INET_ATON,
1012  [AC_CACHE_CHECK([for inet_aton()], ol_cv_func_inet_aton,
1013     [AC_TRY_LINK([
1014 #ifdef HAVE_SYS_TYPES_H
1015 #       include <sys/types.h>
1016 #endif
1017 #ifdef HAVE_SYS_SOCKET_H
1018 #       include <sys/socket.h>
1019 #       ifdef HAVE_SYS_SELECT_H
1020 #               include <sys/select.h>
1021 #       endif
1022 #       include <netinet/in.h>
1023 #       ifdef HAVE_ARPA_INET_H
1024 #               include <arpa/inet.h>
1025 #       endif
1026 #endif
1027 ], [struct in_addr in;
1028 int rc = inet_aton( "255.255.255.255", &in );],
1029                 ol_cv_func_inet_aton=yes, ol_cv_func_inet_aton=no)])
1030   if test $ol_cv_func_inet_aton != no; then
1031     AC_DEFINE(HAVE_INET_ATON, 1,
1032                 [define to you inet_aton(3) is available])
1033   fi
1034  ])dnl
1035 dnl
1036 dnl ====================================================================
1037 dnl check no of arguments for ctime_r
1038 AC_DEFUN(OL_FUNC_CTIME_R_NARGS,
1039  [AC_CACHE_CHECK(number of arguments of ctime_r, ol_cv_func_ctime_r_nargs,
1040    [AC_TRY_COMPILE([#include <time.h>],
1041                 [time_t ti; char *buffer; ctime_r(&ti,buffer,32);],
1042                         ol_cv_func_ctime_r_nargs3=yes,
1043                         ol_cv_func_ctime_r_nargs3=no)
1044
1045         AC_TRY_COMPILE([#include <time.h>],
1046                 [time_t ti; char *buffer; ctime_r(&ti,buffer);],
1047                         ol_cv_func_ctime_r_nargs2=yes,
1048                         ol_cv_func_ctime_r_nargs2=no)
1049
1050         if test $ol_cv_func_ctime_r_nargs3 = yes -a \
1051                 $ol_cv_func_ctime_r_nargs2 = no ; then
1052
1053                 ol_cv_func_ctime_r_nargs=3
1054
1055         elif test $ol_cv_func_ctime_r_nargs3 = no -a \
1056                 $ol_cv_func_ctime_r_nargs2 = yes ; then
1057
1058                 ol_cv_func_ctime_r_nargs=2
1059
1060         else
1061                 ol_cv_func_ctime_r_nargs=0
1062         fi
1063   ])
1064
1065   if test $ol_cv_func_ctime_r_nargs -gt 1 ; then
1066         AC_DEFINE_UNQUOTED(CTIME_R_NARGS, $ol_cv_func_ctime_r_nargs,
1067                 [set to the number of arguments ctime_r() expects])
1068   fi
1069 ])dnl
1070 dnl
1071 dnl --------------------------------------------------------------------
1072 dnl check return type of ctime_r()
1073 AC_DEFUN(OL_FUNC_CTIME_R_TYPE,
1074  [AC_CACHE_CHECK(return type of ctime_r, ol_cv_func_ctime_r_type,
1075    [AC_TRY_COMPILE([#include <time.h>],
1076                 [extern int (ctime_r)();],
1077                         ol_cv_func_ctime_r_type="int", ol_cv_func_ctime_r_type="charp")
1078         ])
1079   if test $ol_cv_func_ctime_r_type = "int" ; then
1080         AC_DEFINE(CTIME_R_RETURNS_INT,1, [define if ctime_r() returns int])
1081   fi
1082 ])dnl
1083 dnl ====================================================================
1084 dnl check no of arguments for gethostbyname_r
1085 AC_DEFUN(OL_FUNC_GETHOSTBYNAME_R_NARGS,
1086  [AC_CACHE_CHECK(number of arguments of gethostbyname_r,
1087         ol_cv_func_gethostbyname_r_nargs,
1088         [AC_TRY_COMPILE([#include <sys/types.h>
1089 #include <sys/socket.h>
1090 #include <netinet/in.h>
1091 #include <netdb.h>
1092 #define BUFSIZE (sizeof(struct hostent)+10)],
1093                 [struct hostent hent; char buffer[BUFSIZE];
1094                 int bufsize=BUFSIZE;int h_errno;
1095                 (void)gethostbyname_r("segovia.cs.purdue.edu", &hent,
1096                         buffer, bufsize, &h_errno);],
1097                 ol_cv_func_gethostbyname_r_nargs5=yes, 
1098                 ol_cv_func_gethostbyname_r_nargs5=no)
1099
1100         AC_TRY_COMPILE([#include <sys/types.h>
1101 #include <sys/socket.h>
1102 #include <netinet/in.h>
1103 #include <netdb.h>
1104 #define BUFSIZE (sizeof(struct hostent)+10)],
1105                 [struct hostent hent;struct hostent *rhent;
1106                 char buffer[BUFSIZE];
1107                 int bufsize=BUFSIZE;int h_errno;
1108                 (void)gethostbyname_r("localhost", &hent, buffer, bufsize,
1109                         &rhent, &h_errno);],
1110                 ol_cv_func_gethostbyname_r_nargs6=yes,
1111                 ol_cv_func_gethostbyname_r_nargs6=no)
1112
1113         if test $ol_cv_func_gethostbyname_r_nargs5 = yes -a \
1114                 $ol_cv_func_gethostbyname_r_nargs6 = no ; then
1115
1116                 ol_cv_func_gethostbyname_r_nargs=5
1117
1118         elif test $ol_cv_func_gethostbyname_r_nargs5 = no -a \
1119                 $ol_cv_func_gethostbyname_r_nargs6 = yes ; then
1120
1121                 ol_cv_func_gethostbyname_r_nargs=6
1122
1123         else
1124                 ol_cv_func_gethostbyname_r_nargs=0
1125         fi
1126   ])
1127   if test $ol_cv_func_gethostbyname_r_nargs -gt 1 ; then
1128         AC_DEFINE_UNQUOTED(GETHOSTBYNAME_R_NARGS,
1129                 $ol_cv_func_gethostbyname_r_nargs,
1130                 [set to the number of arguments gethostbyname_r() expects])
1131   fi
1132 ])dnl
1133 dnl
1134 dnl check no of arguments for gethostbyaddr_r
1135 AC_DEFUN(OL_FUNC_GETHOSTBYADDR_R_NARGS,
1136  [AC_CACHE_CHECK(number of arguments of gethostbyaddr_r,
1137         [ol_cv_func_gethostbyaddr_r_nargs],
1138         [AC_TRY_COMPILE([#include <sys/types.h>
1139 #include <sys/socket.h>
1140 #include <netinet/in.h>
1141 #include <netdb.h>
1142 #define BUFSIZE (sizeof(struct hostent)+10)],
1143            [struct hostent hent; char buffer[BUFSIZE]; 
1144             struct in_addr add;
1145             size_t alen=sizeof(struct in_addr);
1146             int bufsize=BUFSIZE;int h_errno;
1147                 (void)gethostbyaddr_r( (void *)&(add.s_addr),
1148                         alen, AF_INET, &hent, buffer, bufsize, &h_errno);],
1149                 ol_cv_func_gethostbyaddr_r_nargs7=yes,
1150                 ol_cv_func_gethostbyaddr_r_nargs7=no)
1151
1152         AC_TRY_COMPILE([#include <sys/types.h>
1153 #include <sys/socket.h>
1154 #include <netinet/in.h>
1155 #include <netdb.h>
1156 #define BUFSIZE (sizeof(struct hostent)+10)],
1157                 [struct hostent hent;
1158                 struct hostent *rhent; char buffer[BUFSIZE]; 
1159                 struct in_addr add;
1160                 size_t alen=sizeof(struct in_addr);
1161                 int bufsize=BUFSIZE;int h_errno;
1162                 (void)gethostbyaddr_r( (void *)&(add.s_addr),
1163                         alen, AF_INET, &hent, buffer, bufsize, 
1164                         &rhent, &h_errno);],
1165                 ol_cv_func_gethostbyaddr_r_nargs8=yes,
1166                 ol_cv_func_gethostbyaddr_r_nargs8=no)
1167
1168         if test $ol_cv_func_gethostbyaddr_r_nargs7 = yes -a \
1169                 $ol_cv_func_gethostbyaddr_r_nargs8 = no ; then
1170
1171                 ol_cv_func_gethostbyaddr_r_nargs=7
1172
1173         elif test $ol_cv_func_gethostbyaddr_r_nargs7 = no -a \
1174                 $ol_cv_func_gethostbyaddr_r_nargs8 = yes ; then
1175
1176                 ol_cv_func_gethostbyaddr_r_nargs=8
1177
1178         else
1179                 ol_cv_func_gethostbyaddr_r_nargs=0
1180         fi
1181   ])
1182   if test $ol_cv_func_gethostbyaddr_r_nargs -gt 1 ; then
1183     AC_DEFINE_UNQUOTED(GETHOSTBYADDR_R_NARGS,
1184                 $ol_cv_func_gethostbyaddr_r_nargs,
1185                 [set to the number of arguments gethostbyaddr_r() expects])
1186   fi
1187 ])dnl
1188 dnl
1189 dnl --------------------------------------------------------------------
1190 dnl Check for Cyrus SASL version compatility, need 2.1.3 or newer
1191 AC_DEFUN([OL_SASL_COMPAT],
1192 [AC_CACHE_CHECK([Cyrus SASL library version], [ol_cv_sasl_compat],[
1193         AC_EGREP_CPP(__sasl_compat,[
1194 #ifdef HAVE_SASL_SASL_H
1195 #include <sasl/sasl.h>
1196 #else
1197 #include <sasl.h>
1198 #endif
1199
1200 /* require 2.1.3 or later */
1201 #if SASL_VERSION_MAJOR == 1  && SASL_VERSION_MINOR >= 5
1202         char *__sasl_compat = "1.5.x okay";
1203 #elif SASL_VERSION_MAJOR == 2  && SASL_VERSION_MINOR > 1
1204         __sasl_compat "2.2+ or better okay (we guess)";
1205 #elif SASL_VERSION_MAJOR == 2  && SASL_VERSION_MINOR == 1 \
1206         && SASL_VERSION_STEP >=3
1207         __sasl_compat = "2.1.3+ or better okay";
1208 #endif
1209         ],      [ol_cv_sasl_compat=yes], [ol_cv_sasl_compat=no])])
1210 ])