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