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