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