]> git.sur5r.net Git - openldap/blob - build/openldap.m4
ITS#4949 make config_syslog accumulate across multiple values
[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-2007 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 = 5 ; then
490                 OL_BERKELEY_DB_TRY(ol_cv_db_db45,[-ldb45])
491                 OL_BERKELEY_DB_TRY(ol_cv_db_db_45,[-ldb-45])
492                 OL_BERKELEY_DB_TRY(ol_cv_db_db_4_dot_5,[-ldb-4.5])
493                 OL_BERKELEY_DB_TRY(ol_cv_db_db_4_5,[-ldb-4-5])
494         elif test $ol_cv_bdb_minor = 4 ; then
495                 OL_BERKELEY_DB_TRY(ol_cv_db_db44,[-ldb44])
496                 OL_BERKELEY_DB_TRY(ol_cv_db_db_44,[-ldb-44])
497                 OL_BERKELEY_DB_TRY(ol_cv_db_db_4_dot_4,[-ldb-4.4])
498                 OL_BERKELEY_DB_TRY(ol_cv_db_db_4_4,[-ldb-4-4])
499         elif test $ol_cv_bdb_minor = 3 ; then
500                 OL_BERKELEY_DB_TRY(ol_cv_db_db43,[-ldb43])
501                 OL_BERKELEY_DB_TRY(ol_cv_db_db_43,[-ldb-43])
502                 OL_BERKELEY_DB_TRY(ol_cv_db_db_4_dot_3,[-ldb-4.3])
503                 OL_BERKELEY_DB_TRY(ol_cv_db_db_4_3,[-ldb-4-3])
504         elif test $ol_cv_bdb_minor = 2 ; then
505                 OL_BERKELEY_DB_TRY(ol_cv_db_db42,[-ldb42])
506                 OL_BERKELEY_DB_TRY(ol_cv_db_db_42,[-ldb-42])
507                 OL_BERKELEY_DB_TRY(ol_cv_db_db_4_dot_2,[-ldb-4.2])
508                 OL_BERKELEY_DB_TRY(ol_cv_db_db_4_2,[-ldb-4-2])
509         elif test $ol_cv_bdb_minor = 1 ; then
510                 OL_BERKELEY_DB_TRY(ol_cv_db_db41,[-ldb41])
511                 OL_BERKELEY_DB_TRY(ol_cv_db_db_41,[-ldb-41])
512                 OL_BERKELEY_DB_TRY(ol_cv_db_db_4_dot_1,[-ldb-4.1])
513                 OL_BERKELEY_DB_TRY(ol_cv_db_db_4_1,[-ldb-4-1])
514         fi
515         OL_BERKELEY_DB_TRY(ol_cv_db_db_4,[-ldb-4])
516         OL_BERKELEY_DB_TRY(ol_cv_db_db4,[-ldb4])
517         OL_BERKELEY_DB_TRY(ol_cv_db_db,[-ldb])
518
519 elif test $ol_cv_bdb_major = 3 ; then
520         OL_BERKELEY_DB_TRY(ol_cv_db_db3,[-ldb3])
521         OL_BERKELEY_DB_TRY(ol_cv_db_db_3,[-ldb-3])
522
523 elif test $ol_cv_bdb_major = 2 ; then
524         OL_BERKELEY_DB_TRY(ol_cv_db_db2,[-ldb2])
525         OL_BERKELEY_DB_TRY(ol_cv_db_db_2,[-ldb-2])
526
527 elif test $ol_cv_bdb_major = 1 ; then
528         OL_BERKELEY_DB_TRY(ol_cv_db_db1,[-ldb1])
529         OL_BERKELEY_DB_TRY(ol_cv_db_db_1,[-ldb-1])
530 fi
531 OL_BERKELEY_DB_TRY(ol_cv_db_none)
532 ])
533 dnl
534 dnl --------------------------------------------------------------------
535 dnl Check if Berkeley DB version
536 AC_DEFUN([OL_BERKELEY_DB_VERSION],
537 [AC_CACHE_CHECK([for Berkeley DB version match], [ol_cv_berkeley_db_version], [
538         ol_LIBS="$LIBS"
539         LIBS="$LTHREAD_LIBS $LIBS"
540         if test $ol_cv_lib_db != yes ; then
541                 LIBS="$ol_cv_lib_db $LIBS"
542         fi
543
544         AC_RUN_IFELSE([AC_LANG_SOURCE([[
545 #ifdef HAVE_DB_185_H
546         choke me;
547 #else
548 #include <db.h>
549 #endif
550 #ifndef DB_VERSION_MAJOR
551 # define DB_VERSION_MAJOR 1
552 #endif
553 #ifndef NULL
554 #define NULL ((void *)0)
555 #endif
556 main()
557 {
558 #if DB_VERSION_MAJOR > 1
559         char *version;
560         int major, minor, patch;
561
562         version = db_version( &major, &minor, &patch );
563
564         if( major != DB_VERSION_MAJOR ||
565                 minor != DB_VERSION_MINOR ||
566                 patch != DB_VERSION_PATCH )
567         {
568                 printf("Berkeley DB version mismatch\n"
569                         "\theader: %s\n\tlibrary: %s\n",
570                         DB_VERSION_STRING, version);
571                 return 1;
572         }
573 #endif
574
575         return 0;
576 }]])],[ol_cv_berkeley_db_version=yes],[ol_cv_berkeley_db_version=no],[ol_cv_berkeley_db_version=cross])
577
578         LIBS="$ol_LIBS"
579 ])
580
581         if test $ol_cv_berkeley_db_version = no ; then
582                 AC_MSG_ERROR([Berkeley DB version mismatch])
583         fi
584 ])dnl
585 dnl
586 dnl --------------------------------------------------------------------
587 dnl Check if Berkeley DB supports DB_THREAD
588 AC_DEFUN([OL_BERKELEY_DB_THREAD],
589 [AC_CACHE_CHECK([for Berkeley DB thread support], [ol_cv_berkeley_db_thread], [
590         ol_LIBS="$LIBS"
591         LIBS="$LTHREAD_LIBS $LIBS"
592         if test $ol_cv_lib_db != yes ; then
593                 LIBS="$ol_cv_lib_db $LIBS"
594         fi
595
596         AC_RUN_IFELSE([AC_LANG_SOURCE([[
597 #ifdef HAVE_DB_185_H
598         choke me;
599 #else
600 #include <db.h>
601 #endif
602 #ifndef NULL
603 #define NULL ((void *)0)
604 #endif
605 main()
606 {
607         int rc;
608         u_int32_t flags = DB_CREATE |
609 #ifdef DB_PRIVATE
610                 DB_PRIVATE |
611 #endif
612                 DB_THREAD;
613
614 #if DB_VERSION_MAJOR > 2
615         DB_ENV *env = NULL;
616
617         rc = db_env_create( &env, 0 );
618
619         flags |= DB_INIT_MPOOL;
620 #ifdef DB_MPOOL_PRIVATE
621         flags |= DB_MPOOL_PRIVATE;
622 #endif
623
624         if( rc ) {
625                 printf("BerkeleyDB: %s\n", db_strerror(rc) );
626                 return rc;
627         }
628
629 #if (DB_VERSION_MAJOR > 3) || (DB_VERSION_MINOR >= 1)
630         rc = env->open( env, NULL, flags, 0 );
631 #else
632         rc = env->open( env, NULL, NULL, flags, 0 );
633 #endif
634
635         if ( rc == 0 ) {
636                 rc = env->close( env, 0 );
637         }
638
639         if( rc ) {
640                 printf("BerkeleyDB: %s\n", db_strerror(rc) );
641                 return rc;
642         }
643
644 #else
645         DB_ENV env;
646         memset( &env, '\0', sizeof(env) );
647
648         rc = db_appinit( NULL, NULL, &env, flags );
649
650         if( rc == 0 ) {
651                 db_appexit( &env );
652         }
653
654         unlink("__db_mpool.share");
655         unlink("__db_lock.share");
656 #endif
657
658         return rc;
659 }]])],[ol_cv_berkeley_db_thread=yes],[ol_cv_berkeley_db_thread=no],[ol_cv_berkeley_db_thread=cross])
660
661         LIBS="$ol_LIBS"
662 ])
663
664         if test $ol_cv_berkeley_db_thread != no ; then
665                 AC_DEFINE(HAVE_BERKELEY_DB_THREAD, 1,
666                         [define if Berkeley DB has DB_THREAD support])
667         fi
668 ])dnl
669 dnl
670 dnl --------------------------------------------------------------------
671 dnl Find any DB
672 AC_DEFUN([OL_BERKELEY_DB],
673 [ol_cv_berkeley_db=no
674 AC_CHECK_HEADERS(db.h)
675 if test $ac_cv_header_db_h = yes; then
676         OL_BERKELEY_DB_LINK
677         if test "$ol_cv_lib_db" != no ; then
678                 ol_cv_berkeley_db=yes
679                 OL_BERKELEY_DB_VERSION
680                 OL_BERKELEY_DB_THREAD
681         fi
682 fi
683 ])
684 dnl --------------------------------------------------------------------
685 dnl Check for version compatility with back-bdb
686 AC_DEFUN([OL_BDB_COMPAT],
687 [AC_CACHE_CHECK([Berkeley DB version for BDB/HDB backends], [ol_cv_bdb_compat],[
688         AC_EGREP_CPP(__db_version_compat,[
689 #include <db.h>
690
691  /* this check could be improved */
692 #ifndef DB_VERSION_MAJOR
693 #       define DB_VERSION_MAJOR 1
694 #endif
695 #ifndef DB_VERSION_MINOR
696 #       define DB_VERSION_MINOR 0
697 #endif
698
699 /* require 4.2 or later, but exclude 4.3 */
700 #if (DB_VERSION_MAJOR >= 4) && (DB_VERSION_MINOR >= 2) && (DB_VERSION_MINOR !=3)
701         __db_version_compat
702 #endif
703         ], [ol_cv_bdb_compat=yes], [ol_cv_bdb_compat=no])])
704 ])
705
706 dnl --------------------------------------------------------------------
707 dnl Find old Berkeley DB 1.85/1.86
708 AC_DEFUN([OL_BERKELEY_COMPAT_DB],
709 [AC_CHECK_HEADERS(db_185.h db.h)
710 if test $ac_cv_header_db_185_h = yes || test $ac_cv_header_db_h = yes; then
711         AC_CACHE_CHECK([if Berkeley DB header compatibility], [ol_cv_header_db1],[
712                 AC_EGREP_CPP(__db_version_1,[
713 #if HAVE_DB_185_H
714 #       include <db_185.h>
715 #else
716 #       include <db.h>
717 #endif
718
719  /* this check could be improved */
720 #ifndef DB_VERSION_MAJOR
721 #       define DB_VERSION_MAJOR 1
722 #endif
723
724 #if DB_VERSION_MAJOR == 1 
725         __db_version_1
726 #endif
727 ],      [ol_cv_header_db1=yes], [ol_cv_header_db1=no])])
728
729         if test $ol_cv_header_db1 = yes ; then
730                 OL_BERKELEY_DB_LINK
731                 if test "$ol_cv_lib_db" != no ; then
732                         ol_cv_berkeley_db=yes
733                 fi
734         fi
735 fi
736 ])
737 dnl
738 dnl ====================================================================
739 dnl Check if GDBM library exists
740 dnl Check for gdbm_open in standard libraries or -lgdbm
741 dnl
742 dnl defines ol_cv_lib_gdbm to 'yes' or '-lgdbm' or 'no'
743 dnl             'yes' implies gdbm_open is in $LIBS
744 dnl
745 dnl uses:
746 dnl             AC_CHECK_FUNC(gdbm_open)
747 dnl             AC_CHECK_LIB(gdbm,gdbm_open)
748 dnl
749 AC_DEFUN([OL_LIB_GDBM],
750 [AC_CACHE_CHECK(for GDBM library, [ol_cv_lib_gdbm],
751 [       ol_LIBS="$LIBS"
752         AC_CHECK_FUNC(gdbm_open,[ol_cv_lib_gdbm=yes], [
753                 AC_CHECK_LIB(gdbm,gdbm_open,[ol_cv_lib_gdbm=-lgdbm],[ol_cv_lib_gdbm=no])
754         ])
755         LIBS="$ol_LIBS"
756 ])
757 ])dnl
758 dnl
759 dnl --------------------------------------------------------------------
760 dnl Check if GDBM exists
761 dnl
762 dnl defines ol_cv_gdbm to 'yes' or 'no'
763 dnl 
764 dnl uses:
765 dnl             OL_LIB_GDBM
766 dnl             AC_CHECK_HEADERS(gdbm.h)
767 dnl
768 AC_DEFUN([OL_GDBM],
769 [AC_REQUIRE([OL_LIB_GDBM])
770  AC_CHECK_HEADERS(gdbm.h)
771  AC_CACHE_CHECK(for db, [ol_cv_gdbm], [
772         if test $ol_cv_lib_gdbm = no || test $ac_cv_header_gdbm_h = no ; then
773                 ol_cv_gdbm=no
774         else
775                 ol_cv_gdbm=yes
776         fi
777 ])
778  if test $ol_cv_gdbm = yes ; then
779         AC_DEFINE(HAVE_GDBM,1, [define if GNU DBM is available])
780  fi
781 ])dnl
782 dnl
783 dnl ====================================================================
784 dnl Check if MDBM library exists
785 dnl Check for mdbm_open in standard libraries or -lmdbm
786 dnl
787 dnl defines ol_cv_lib_mdbm to 'yes' or '-lmdbm' or 'no'
788 dnl             'yes' implies mdbm_open is in $LIBS
789 dnl
790 dnl uses:
791 dnl             AC_CHECK_FUNC(mdbm_set_chain)
792 dnl             AC_CHECK_LIB(mdbm,mdbm_set_chain)
793 dnl
794 AC_DEFUN([OL_LIB_MDBM],
795 [AC_CACHE_CHECK(for MDBM library, [ol_cv_lib_mdbm],
796 [       ol_LIBS="$LIBS"
797         AC_CHECK_FUNC(mdbm_set_chain,[ol_cv_lib_mdbm=yes], [
798                 AC_CHECK_LIB(mdbm,mdbm_set_chain,[ol_cv_lib_mdbm=-lmdbm],[ol_cv_lib_mdbm=no])
799         ])
800         LIBS="$ol_LIBS"
801 ])
802 ])dnl
803 dnl
804 dnl --------------------------------------------------------------------
805 dnl Check if MDBM exists
806 dnl
807 dnl defines ol_cv_mdbm to 'yes' or 'no'
808 dnl 
809 dnl uses:
810 dnl             OL_LIB_MDBM
811 dnl             AC_CHECK_HEADERS(mdbm.h)
812 dnl
813 AC_DEFUN([OL_MDBM],
814 [AC_REQUIRE([OL_LIB_MDBM])
815  AC_CHECK_HEADERS(mdbm.h)
816  AC_CACHE_CHECK(for db, [ol_cv_mdbm], [
817         if test $ol_cv_lib_mdbm = no || test $ac_cv_header_mdbm_h = no ; then
818                 ol_cv_mdbm=no
819         else
820                 ol_cv_mdbm=yes
821         fi
822 ])
823  if test $ol_cv_mdbm = yes ; then
824         AC_DEFINE(HAVE_MDBM,1, [define if MDBM is available])
825  fi
826 ])dnl
827 dnl
828 dnl ====================================================================
829 dnl Check if NDBM library exists
830 dnl Check for dbm_open in standard libraries or -lndbm or -ldbm
831 dnl
832 dnl defines ol_cv_lib_ndbm to 'yes' or '-lndbm' or -ldbm or 'no'
833 dnl             'yes' implies ndbm_open is in $LIBS
834 dnl
835 dnl uses:
836 dnl             AC_CHECK_FUNC(dbm_open)
837 dnl             AC_CHECK_LIB(ndbm,dbm_open)
838 dnl             AC_CHECK_LIB(dbm,dbm_open)
839 dnl
840 dnl restrictions:
841 dnl             should also check SVR4 case: dbm_open() in -lucb but that
842 dnl             would requiring dealing with -L/usr/ucblib
843 dnl
844 AC_DEFUN([OL_LIB_NDBM],
845 [AC_CACHE_CHECK(for NDBM library, [ol_cv_lib_ndbm],
846 [       ol_LIBS="$LIBS"
847         AC_CHECK_FUNC(dbm_open,[ol_cv_lib_ndbm=yes], [
848                 AC_CHECK_LIB(ndbm,dbm_open,[ol_cv_lib_ndbm=-lndbm], [
849                         AC_CHECK_LIB(dbm,dbm_open,[ol_cv_lib_ndbm=-ldbm],
850                                 [ol_cv_lib_ndbm=no])dnl
851                 ])
852         ])
853         LIBS="$ol_LIBS"
854 ])
855 ])dnl
856 dnl
857 dnl --------------------------------------------------------------------
858 dnl Check if NDBM exists
859 dnl
860 dnl defines ol_cv_ndbm to 'yes' or 'no'
861 dnl 
862 dnl uses:
863 dnl             OL_LIB_NDBM
864 dnl             AC_CHECK_HEADERS(ndbm.h)
865 dnl
866 dnl restrictions:
867 dnl             Doesn't handle SVR4 case (see above)
868 dnl
869 AC_DEFUN([OL_NDBM],
870 [AC_REQUIRE([OL_LIB_NDBM])
871  AC_CHECK_HEADERS(ndbm.h)
872  AC_CACHE_CHECK(for db, [ol_cv_ndbm], [
873         if test $ol_cv_lib_ndbm = no || test $ac_cv_header_ndbm_h = no ; then
874                 ol_cv_ndbm=no
875         else
876                 ol_cv_ndbm=yes
877         fi
878 ])
879  if test $ol_cv_ndbm = yes ; then
880         AC_DEFINE(HAVE_NDBM,1, [define if NDBM is available])
881  fi
882 ])dnl
883 dnl
884 dnl ====================================================================
885 dnl Check POSIX Thread version 
886 dnl
887 dnl defines ol_cv_pthread_version to 4, 5, 6, 7, 8, 10, depending on the
888 dnl     version of the POSIX.4a Draft that is implemented.
889 dnl     10 == POSIX.4a Final == POSIX.1c-1996 for our purposes.
890 dnl     Existence of pthread.h should be tested separately.
891 dnl
892 dnl tests:
893 dnl     pthread_detach() was dropped in Draft 8, it is present
894 dnl             in every other version
895 dnl     PTHREAD_CREATE_UNDETACHED is only in Draft 7, it was called
896 dnl             PTHREAD_CREATE_JOINABLE after that
897 dnl     pthread_attr_create was renamed to pthread_attr_init in Draft 6.
898 dnl             Draft 6-10 has _init, Draft 4-5 has _create.
899 dnl     pthread_attr_default was dropped in Draft 6, only 4 and 5 have it
900 dnl     PTHREAD_MUTEX_INITIALIZER was introduced in Draft 5. It's not
901 dnl             interesting to us because we don't try to statically
902 dnl             initialize mutexes. 5-10 has it.
903 dnl
904 dnl Draft 9 and 10 are equivalent for our purposes.
905 dnl
906 AC_DEFUN([OL_POSIX_THREAD_VERSION],
907 [AC_CACHE_CHECK([POSIX thread version],[ol_cv_pthread_version],[
908         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
909 #               include <pthread.h>
910         ]], [[
911                 int i = PTHREAD_CREATE_JOINABLE;
912         ]])],[
913         AC_EGREP_HEADER(pthread_detach,pthread.h,
914         ol_cv_pthread_version=10, ol_cv_pthread_version=8)],[
915         AC_EGREP_CPP(draft7,[
916 #               include <pthread.h>
917 #               ifdef PTHREAD_CREATE_UNDETACHED
918                 draft7
919 #               endif
920         ], ol_cv_pthread_version=7, [
921         AC_EGREP_HEADER(pthread_attr_init,pthread.h,
922         ol_cv_pthread_version=6, [
923         AC_EGREP_CPP(draft5,[
924 #               include <pthread.h>
925 #ifdef          PTHREAD_MUTEX_INITIALIZER
926                 draft5
927 #endif
928         ], ol_cv_pthread_version=5, ol_cv_pthread_version=4) ]) ]) ])
929 ])
930 ])dnl
931 dnl
932 dnl --------------------------------------------------------------------
933 AC_DEFUN([OL_PTHREAD_TEST_INCLUDES], [[
934 /* pthread test headers */
935 #include <pthread.h>
936 #if HAVE_PTHREADS < 7
937 #include <errno.h>
938 #endif
939 #ifndef NULL
940 #define NULL (void*)0
941 #endif
942
943 static void *task(p)
944         void *p;
945 {
946         return (void *) (p == NULL);
947 }
948 ]])
949 AC_DEFUN([OL_PTHREAD_TEST_FUNCTION],[[
950         /* pthread test function */
951 #ifndef PTHREAD_CREATE_DETACHED
952 #define PTHREAD_CREATE_DETACHED 1
953 #endif
954         pthread_t t;
955         int status;
956         int detach = PTHREAD_CREATE_DETACHED;
957
958 #if HAVE_PTHREADS > 4
959         /* Final pthreads */
960         pthread_attr_t attr;
961
962         status = pthread_attr_init(&attr);
963         if( status ) return status;
964
965 #if HAVE_PTHREADS < 7
966         status = pthread_attr_setdetachstate(&attr, &detach);
967         if( status < 0 ) status = errno;
968 #else
969         status = pthread_attr_setdetachstate(&attr, detach);
970 #endif
971         if( status ) return status;
972         status = pthread_create( &t, &attr, task, NULL );
973 #if HAVE_PTHREADS < 7
974         if( status < 0 ) status = errno;
975 #endif
976         if( status ) return status;
977 #else
978         /* Draft 4 pthreads */
979         status = pthread_create( &t, pthread_attr_default, task, NULL );
980         if( status ) return errno;
981
982         /* give thread a chance to complete */
983         /* it should remain joinable and hence detachable */
984         sleep( 1 );
985
986         status = pthread_detach( &t );
987         if( status ) return errno;
988 #endif
989
990 #ifdef HAVE_LINUX_THREADS
991         pthread_kill_other_threads_np();
992 #endif
993
994         return 0;
995 ]])
996
997 AC_DEFUN([OL_PTHREAD_TEST_PROGRAM],
998 AC_LANG_SOURCE([OL_PTHREAD_TEST_INCLUDES
999
1000 int main(argc, argv)
1001         int argc;
1002         char **argv;
1003 {
1004 OL_PTHREAD_TEST_FUNCTION
1005 }
1006 ]))
1007 dnl --------------------------------------------------------------------
1008 AC_DEFUN([OL_PTHREAD_TRY], [# Pthread try link: $1 ($2)
1009 if test "$ol_link_threads" = no ; then
1010         # try $1
1011         AC_CACHE_CHECK([for pthread link with $1], [$2], [
1012                 # save the flags
1013                 ol_LIBS="$LIBS"
1014                 LIBS="$1 $LIBS"
1015
1016                 AC_RUN_IFELSE([OL_PTHREAD_TEST_PROGRAM],
1017                         [$2=yes],
1018                         [$2=no],
1019                         [AC_LINK_IFELSE([AC_LANG_PROGRAM(OL_PTHREAD_TEST_INCLUDES,
1020                                 OL_PTHREAD_TEST_FUNCTION)],
1021                                 [$2=yes], [$2=no])])
1022
1023                 # restore the LIBS
1024                 LIBS="$ol_LIBS"
1025         ])
1026
1027         if test $$2 = yes ; then
1028                 ol_link_pthreads="$1"
1029                 ol_link_threads=posix
1030         fi
1031 fi
1032 ])
1033 dnl
1034 dnl ====================================================================
1035 dnl Check GNU Pth pthread Header
1036 dnl
1037 dnl defines ol_cv_header linux_threads to 'yes' or 'no'
1038 dnl             'no' implies pthreads.h is not LinuxThreads or pthreads.h
1039 dnl             doesn't exists.  Existance of pthread.h should separately
1040 dnl             checked.
1041 dnl 
1042 AC_DEFUN([OL_HEADER_GNU_PTH_PTHREAD_H], [
1043         AC_CACHE_CHECK([for GNU Pth pthread.h],
1044                 [ol_cv_header_gnu_pth_pthread_h],
1045                 [AC_EGREP_CPP(__gnu_pth__,
1046                         [#include <pthread.h>
1047 #ifdef _POSIX_THREAD_IS_GNU_PTH
1048         __gnu_pth__;
1049 #endif
1050 ],
1051                         [ol_cv_header_gnu_pth_pthread_h=yes],
1052                         [ol_cv_header_gnu_pth_pthread_h=no])
1053                 ])
1054 ])dnl
1055 dnl ====================================================================
1056 dnl Check for NT Threads
1057 AC_DEFUN([OL_NT_THREADS], [
1058         AC_CHECK_FUNC(_beginthread)
1059
1060         if test $ac_cv_func__beginthread = yes ; then
1061                 AC_DEFINE(HAVE_NT_THREADS,1,[if you have NT Threads])
1062                 ol_cv_nt_threads=yes
1063         fi
1064 ])
1065 dnl ====================================================================
1066 dnl Check LinuxThreads Header
1067 dnl
1068 dnl defines ol_cv_header linux_threads to 'yes' or 'no'
1069 dnl             'no' implies pthreads.h is not LinuxThreads or pthreads.h
1070 dnl             doesn't exists.  Existance of pthread.h should separately
1071 dnl             checked.
1072 dnl 
1073 AC_DEFUN([OL_HEADER_LINUX_THREADS], [
1074         AC_CACHE_CHECK([for LinuxThreads pthread.h],
1075                 [ol_cv_header_linux_threads],
1076                 [AC_EGREP_CPP(pthread_kill_other_threads_np,
1077                         [#include <pthread.h>],
1078                         [ol_cv_header_linux_threads=yes],
1079                         [ol_cv_header_linux_threads=no])
1080                 ])
1081         if test $ol_cv_header_linux_threads = yes; then
1082                 AC_DEFINE(HAVE_LINUX_THREADS,1,[if you have LinuxThreads])
1083         fi
1084 ])dnl
1085 dnl --------------------------------------------------------------------
1086 dnl     Check LinuxThreads Implementation
1087 dnl
1088 dnl     defines ol_cv_sys_linux_threads to 'yes' or 'no'
1089 dnl     'no' implies pthreads implementation is not LinuxThreads.
1090 dnl 
1091 AC_DEFUN([OL_SYS_LINUX_THREADS], [
1092         AC_CHECK_FUNCS(pthread_kill_other_threads_np)
1093         AC_CACHE_CHECK([for LinuxThreads implementation],
1094                 [ol_cv_sys_linux_threads],
1095                 [ol_cv_sys_linux_threads=$ac_cv_func_pthread_kill_other_threads_np])
1096 ])dnl
1097 dnl
1098 dnl --------------------------------------------------------------------
1099 dnl Check LinuxThreads consistency
1100 AC_DEFUN([OL_LINUX_THREADS], [
1101         AC_REQUIRE([OL_HEADER_LINUX_THREADS])
1102         AC_REQUIRE([OL_SYS_LINUX_THREADS])
1103         AC_CACHE_CHECK([for LinuxThreads consistency], [ol_cv_linux_threads], [
1104                 if test $ol_cv_header_linux_threads = yes &&
1105                    test $ol_cv_sys_linux_threads = yes; then
1106                         ol_cv_linux_threads=yes
1107                 elif test $ol_cv_header_linux_threads = no &&
1108                      test $ol_cv_sys_linux_threads = no; then
1109                         ol_cv_linux_threads=no
1110                 else
1111                         ol_cv_linux_threads=error
1112                 fi
1113         ])
1114 ])dnl
1115 dnl
1116 dnl ====================================================================
1117 dnl Check for POSIX Regex
1118 AC_DEFUN([OL_POSIX_REGEX], [
1119 AC_CACHE_CHECK([for compatible POSIX regex],ol_cv_c_posix_regex,[
1120         AC_RUN_IFELSE([AC_LANG_SOURCE([[
1121 #include <sys/types.h>
1122 #include <regex.h>
1123 static char *pattern, *string;
1124 main()
1125 {
1126         int rc;
1127         regex_t re;
1128
1129         pattern = "^A";
1130
1131         if(regcomp(&re, pattern, 0)) {
1132                 return -1;
1133         }
1134         
1135         string = "ALL MATCH";
1136         
1137         rc = regexec(&re, string, 0, (void*)0, 0);
1138
1139         regfree(&re);
1140
1141         return rc;
1142 }]])],[ol_cv_c_posix_regex=yes],[ol_cv_c_posix_regex=no],[ol_cv_c_posix_regex=cross])])
1143 ])
1144 dnl
1145 dnl ====================================================================
1146 dnl Check if toupper() requires islower() to be called first
1147 AC_DEFUN([OL_C_UPPER_LOWER],
1148 [AC_CACHE_CHECK([if toupper() requires islower()],ol_cv_c_upper_lower,[
1149         AC_RUN_IFELSE([AC_LANG_SOURCE([[
1150 #include <ctype.h>
1151 main()
1152 {
1153         if ('C' == toupper('C'))
1154                 exit(0);
1155         else
1156                 exit(1);
1157 }]])],[ol_cv_c_upper_lower=no],[ol_cv_c_upper_lower=yes],[ol_cv_c_upper_lower=safe])])
1158 if test $ol_cv_c_upper_lower != no ; then
1159         AC_DEFINE(C_UPPER_LOWER,1, [define if toupper() requires islower()])
1160 fi
1161 ])
1162 dnl
1163 dnl ====================================================================
1164 dnl Error string checks
1165 dnl
1166 dnl Check for declaration of sys_errlist in one of stdio.h and errno.h.
1167 dnl Declaration of sys_errlist on BSD4.4 interferes with our declaration.
1168 dnl Reported by Keith Bostic.
1169 AC_DEFUN([OL_SYS_ERRLIST],
1170 [AC_CACHE_CHECK([declaration of sys_errlist],ol_cv_dcl_sys_errlist,[
1171         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1172 #include <stdio.h>
1173 #include <sys/types.h>
1174 #include <errno.h>
1175 #ifdef _WIN32
1176 #include <stdlib.h>
1177 #endif ]], [[char *c = (char *) *sys_errlist]])],[ol_cv_dcl_sys_errlist=yes
1178         ol_cv_have_sys_errlist=yes],[ol_cv_dcl_sys_errlist=no])])
1179 #
1180 # It's possible (for near-UNIX clones) that sys_errlist doesn't exist
1181 if test $ol_cv_dcl_sys_errlist = no ; then
1182         AC_DEFINE(DECL_SYS_ERRLIST,1,
1183                 [define if sys_errlist is not declared in stdio.h or errno.h])
1184
1185         AC_CACHE_CHECK([existence of sys_errlist],ol_cv_have_sys_errlist,[
1186                 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])])
1187 fi
1188 if test $ol_cv_have_sys_errlist = yes ; then
1189         AC_DEFINE(HAVE_SYS_ERRLIST,1,
1190                 [define if you actually have sys_errlist in your libs])
1191 fi
1192 ])dnl
1193 AC_DEFUN([OL_NONPOSIX_STRERROR_R],
1194 [AC_CACHE_CHECK([non-posix strerror_r],ol_cv_nonposix_strerror_r,[
1195         AC_EGREP_CPP(strerror_r,[#include <string.h>],
1196                 ol_decl_strerror_r=yes, ol_decl_strerror_r=no)dnl
1197
1198         if test $ol_decl_strerror_r = yes ; then
1199                 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <string.h>]], [[   /* from autoconf 2.59 */
1200                                 char buf[100];
1201                                 char x = *strerror_r (0, buf, sizeof buf);
1202                                 char *p = strerror_r (0, buf, sizeof buf);
1203                         ]])],[ol_cv_nonposix_strerror_r=yes],[ol_cv_nonposix_strerror_r=no])
1204         else
1205                 AC_RUN_IFELSE([AC_LANG_SOURCE([[
1206                         main() {
1207                                 char buf[100];
1208                                 buf[0] = 0;
1209                                 strerror_r( 1, buf, sizeof buf );
1210                                 exit( buf[0] == 0 );
1211                         }
1212                         ]])],[ol_cv_nonposix_strerror_r=yes],[ol_cv_nonposix_strerror=no],[ol_cv_nonposix_strerror=no])
1213         fi
1214         ])
1215 if test $ol_cv_nonposix_strerror_r = yes ; then
1216         AC_DEFINE(HAVE_NONPOSIX_STRERROR_R,1,
1217                 [define if strerror_r returns char* instead of int])
1218 fi
1219 ])dnl
1220 dnl
1221 AC_DEFUN([OL_STRERROR],
1222 [OL_SYS_ERRLIST dnl TEMPORARY
1223 AC_CHECK_FUNCS(strerror strerror_r)
1224 ol_cv_func_strerror_r=no
1225 if test "${ac_cv_func_strerror_r}" = yes ; then
1226         OL_NONPOSIX_STRERROR_R
1227 elif test "${ac_cv_func_strerror}" = no ; then
1228         OL_SYS_ERRLIST
1229 fi
1230 ])dnl
1231 dnl ====================================================================
1232 dnl Early MIPS compilers (used in Ultrix 4.2) don't like
1233 dnl "int x; int *volatile a = &x; *a = 0;"
1234 dnl     -- borrowed from PDKSH
1235 AC_DEFUN([OL_C_VOLATILE],
1236  [AC_CACHE_CHECK(if compiler understands volatile, ol_cv_c_volatile,
1237     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x, y, z;]], [[volatile int a; int * volatile b = x ? &y : &z;
1238       /* Older MIPS compilers (eg., in Ultrix 4.2) don't like *b = 0 */
1239       *b = 0;]])],[ol_cv_c_volatile=yes],[ol_cv_c_volatile=no])])
1240   if test $ol_cv_c_volatile = yes; then
1241     : 
1242   else
1243     AC_DEFINE(volatile,,[define as empty if volatile is not supported])
1244   fi
1245  ])dnl
1246 dnl
1247 dnl ====================================================================
1248 dnl Look for fetch(3)
1249 AC_DEFUN([OL_LIB_FETCH],
1250 [ol_LIBS=$LIBS
1251 LIBS="-lfetch -lcom_err $LIBS"
1252 AC_CACHE_CHECK([fetch(3) library],ol_cv_lib_fetch,[
1253         AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1254 #include <sys/param.h>
1255 #include <stdio.h>
1256 #include <fetch.h>]], [[struct url *u = fetchParseURL("file:///"); ]])],[ol_cv_lib_fetch=yes],[ol_cv_lib_fetch=no])])
1257 LIBS=$ol_LIBS
1258 if test $ol_cv_lib_fetch != no ; then
1259         ol_link_fetch="-lfetch -lcom_err"
1260         AC_DEFINE(HAVE_FETCH,1,
1261                 [define if you actually have FreeBSD fetch(3)])
1262 fi
1263 ])dnl
1264 dnl
1265 dnl ====================================================================
1266 dnl Define inet_aton is available
1267 AC_DEFUN([OL_FUNC_INET_ATON],
1268  [AC_CACHE_CHECK([for inet_aton()], ol_cv_func_inet_aton,
1269     [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1270 #ifdef HAVE_SYS_TYPES_H
1271 #       include <sys/types.h>
1272 #endif
1273 #ifdef HAVE_SYS_SOCKET_H
1274 #       include <sys/socket.h>
1275 #       ifdef HAVE_SYS_SELECT_H
1276 #               include <sys/select.h>
1277 #       endif
1278 #       include <netinet/in.h>
1279 #       ifdef HAVE_ARPA_INET_H
1280 #               include <arpa/inet.h>
1281 #       endif
1282 #endif
1283 ]], [[struct in_addr in;
1284 int rc = inet_aton( "255.255.255.255", &in );]])],[ol_cv_func_inet_aton=yes],[ol_cv_func_inet_aton=no])])
1285   if test $ol_cv_func_inet_aton != no; then
1286     AC_DEFINE(HAVE_INET_ATON, 1,
1287                 [define to you inet_aton(3) is available])
1288   fi
1289  ])dnl
1290 dnl
1291 dnl ====================================================================
1292 dnl check no of arguments for ctime_r
1293 AC_DEFUN([OL_FUNC_CTIME_R_NARGS],
1294  [AC_CACHE_CHECK(number of arguments of ctime_r, ol_cv_func_ctime_r_nargs,
1295    [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])
1296
1297         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])
1298
1299         if test $ol_cv_func_ctime_r_nargs3 = yes &&
1300            test $ol_cv_func_ctime_r_nargs2 = no ; then
1301
1302                 ol_cv_func_ctime_r_nargs=3
1303
1304         elif test $ol_cv_func_ctime_r_nargs3 = no &&
1305              test $ol_cv_func_ctime_r_nargs2 = yes ; then
1306
1307                 ol_cv_func_ctime_r_nargs=2
1308
1309         else
1310                 ol_cv_func_ctime_r_nargs=0
1311         fi
1312   ])
1313
1314   if test $ol_cv_func_ctime_r_nargs -gt 1 ; then
1315         AC_DEFINE_UNQUOTED(CTIME_R_NARGS, $ol_cv_func_ctime_r_nargs,
1316                 [set to the number of arguments ctime_r() expects])
1317   fi
1318 ])dnl
1319 dnl
1320 dnl --------------------------------------------------------------------
1321 dnl check return type of ctime_r()
1322 AC_DEFUN([OL_FUNC_CTIME_R_TYPE],
1323  [AC_CACHE_CHECK(return type of ctime_r, ol_cv_func_ctime_r_type,
1324    [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"])
1325         ])
1326   if test $ol_cv_func_ctime_r_type = "int" ; then
1327         AC_DEFINE(CTIME_R_RETURNS_INT,1, [define if ctime_r() returns int])
1328   fi
1329 ])dnl
1330 dnl ====================================================================
1331 dnl check no of arguments for gethostbyname_r
1332 AC_DEFUN([OL_FUNC_GETHOSTBYNAME_R_NARGS],
1333  [AC_CACHE_CHECK(number of arguments of gethostbyname_r,
1334         ol_cv_func_gethostbyname_r_nargs,
1335         [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
1336 #include <sys/socket.h>
1337 #include <netinet/in.h>
1338 #include <netdb.h>
1339 #define BUFSIZE (sizeof(struct hostent)+10)]], [[struct hostent hent; char buffer[BUFSIZE];
1340                 int bufsize=BUFSIZE;int h_errno;
1341                 (void)gethostbyname_r("segovia.cs.purdue.edu", &hent,
1342                         buffer, bufsize, &h_errno);]])],[ol_cv_func_gethostbyname_r_nargs5=yes],[ol_cv_func_gethostbyname_r_nargs5=no])
1343
1344         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
1345 #include <sys/socket.h>
1346 #include <netinet/in.h>
1347 #include <netdb.h>
1348 #define BUFSIZE (sizeof(struct hostent)+10)]], [[struct hostent hent;struct hostent *rhent;
1349                 char buffer[BUFSIZE];
1350                 int bufsize=BUFSIZE;int h_errno;
1351                 (void)gethostbyname_r("localhost", &hent, buffer, bufsize,
1352                         &rhent, &h_errno);]])],[ol_cv_func_gethostbyname_r_nargs6=yes],[ol_cv_func_gethostbyname_r_nargs6=no])
1353
1354         if test $ol_cv_func_gethostbyname_r_nargs5 = yes &&
1355            test $ol_cv_func_gethostbyname_r_nargs6 = no ; then
1356
1357                 ol_cv_func_gethostbyname_r_nargs=5
1358
1359         elif test $ol_cv_func_gethostbyname_r_nargs5 = no &&
1360              test $ol_cv_func_gethostbyname_r_nargs6 = yes ; then
1361
1362                 ol_cv_func_gethostbyname_r_nargs=6
1363
1364         else
1365                 ol_cv_func_gethostbyname_r_nargs=0
1366         fi
1367   ])
1368   if test $ol_cv_func_gethostbyname_r_nargs -gt 1 ; then
1369         AC_DEFINE_UNQUOTED(GETHOSTBYNAME_R_NARGS,
1370                 $ol_cv_func_gethostbyname_r_nargs,
1371                 [set to the number of arguments gethostbyname_r() expects])
1372   fi
1373 ])dnl
1374 dnl
1375 dnl check no of arguments for gethostbyaddr_r
1376 AC_DEFUN([OL_FUNC_GETHOSTBYADDR_R_NARGS],
1377  [AC_CACHE_CHECK(number of arguments of gethostbyaddr_r,
1378         [ol_cv_func_gethostbyaddr_r_nargs],
1379         [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
1380 #include <sys/socket.h>
1381 #include <netinet/in.h>
1382 #include <netdb.h>
1383 #define BUFSIZE (sizeof(struct hostent)+10)]], [[struct hostent hent; char buffer[BUFSIZE]; 
1384             struct in_addr add;
1385             size_t alen=sizeof(struct in_addr);
1386             int bufsize=BUFSIZE;int h_errno;
1387                 (void)gethostbyaddr_r( (void *)&(add.s_addr),
1388                         alen, AF_INET, &hent, buffer, bufsize, &h_errno);]])],[ol_cv_func_gethostbyaddr_r_nargs7=yes],[ol_cv_func_gethostbyaddr_r_nargs7=no])
1389
1390         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
1391 #include <sys/socket.h>
1392 #include <netinet/in.h>
1393 #include <netdb.h>
1394 #define BUFSIZE (sizeof(struct hostent)+10)]], [[struct hostent hent;
1395                 struct hostent *rhent; char buffer[BUFSIZE]; 
1396                 struct in_addr add;
1397                 size_t alen=sizeof(struct in_addr);
1398                 int bufsize=BUFSIZE;int h_errno;
1399                 (void)gethostbyaddr_r( (void *)&(add.s_addr),
1400                         alen, AF_INET, &hent, buffer, bufsize, 
1401                         &rhent, &h_errno);]])],[ol_cv_func_gethostbyaddr_r_nargs8=yes],[ol_cv_func_gethostbyaddr_r_nargs8=no])
1402
1403         if test $ol_cv_func_gethostbyaddr_r_nargs7 = yes &&
1404            test $ol_cv_func_gethostbyaddr_r_nargs8 = no ; then
1405
1406                 ol_cv_func_gethostbyaddr_r_nargs=7
1407
1408         elif test $ol_cv_func_gethostbyaddr_r_nargs7 = no &&
1409              test $ol_cv_func_gethostbyaddr_r_nargs8 = yes ; then
1410
1411                 ol_cv_func_gethostbyaddr_r_nargs=8
1412
1413         else
1414                 ol_cv_func_gethostbyaddr_r_nargs=0
1415         fi
1416   ])
1417   if test $ol_cv_func_gethostbyaddr_r_nargs -gt 1 ; then
1418     AC_DEFINE_UNQUOTED(GETHOSTBYADDR_R_NARGS,
1419                 $ol_cv_func_gethostbyaddr_r_nargs,
1420                 [set to the number of arguments gethostbyaddr_r() expects])
1421   fi
1422 ])dnl
1423 dnl
1424 dnl --------------------------------------------------------------------
1425 dnl Check for Cyrus SASL version compatility
1426 AC_DEFUN([OL_SASL_COMPAT],
1427 [AC_CACHE_CHECK([Cyrus SASL library version], [ol_cv_sasl_compat],[
1428         AC_EGREP_CPP(__sasl_compat,[
1429 #ifdef HAVE_SASL_SASL_H
1430 #include <sasl/sasl.h>
1431 #else
1432 #include <sasl.h>
1433 #endif
1434
1435 /* Require 2.1.15+ */
1436 #if SASL_VERSION_MAJOR == 2  && SASL_VERSION_MINOR > 1
1437         char *__sasl_compat = "2.2+ or better okay (we guess)";
1438 #elif SASL_VERSION_MAJOR == 2  && SASL_VERSION_MINOR == 1 \
1439         && SASL_VERSION_STEP >=15
1440         char *__sasl_compat = "2.1.15+ or better okay";
1441 #endif
1442         ],      [ol_cv_sasl_compat=yes], [ol_cv_sasl_compat=no])])
1443 ])
1444 dnl ====================================================================
1445 dnl check for SSL compatibility
1446 AC_DEFUN([OL_SSL_COMPAT],
1447 [AC_CACHE_CHECK([OpenSSL library version (CRL checking capability)],
1448         [ol_cv_ssl_crl_compat],[
1449                 AC_EGREP_CPP(__ssl_compat,[
1450 #ifdef HAVE_OPENSSL_SSL_H
1451 #include <openssl/ssl.h>
1452 #endif
1453
1454 /* Require 0.9.7d+ */
1455 #if OPENSSL_VERSION_NUMBER >= 0x0090704fL
1456         char *__ssl_compat = "0.9.7d";
1457 #endif
1458         ], [ol_cv_ssl_crl_compat=yes], [ol_cv_ssl_crl_compat=no])])
1459 ])