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