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