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