1 dnl OpenLDAP Autoconf Macros
3 dnl This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 dnl Copyright 1998-2005 The OpenLDAP Foundation.
6 dnl All rights reserved.
8 dnl Redistribution and use in source and binary forms, with or without
9 dnl modification, are permitted only as authorized by the OpenLDAP
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>.
16 dnl --------------------------------------------------------------------
17 dnl Restricted form of AC_ARG_ENABLE that limits user options
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([,])]),[
27 for ol_val in ifelse($4,,[auto yes no],[$4]) ; do
28 if test "$enableval" = "$ol_val" ; then
32 if test "$ol_arg" = "invalid" ; then
33 AC_MSG_ERROR(bad value $enableval for --enable-$1)
35 ol_enable_$1="$ol_arg"
37 [ ol_enable_$1=ifelse($3,,"auto","$3")]]))dnl
38 dnl AC_MSG_RESULT([OpenLDAP -enable-$1 $ol_enable_$1])
42 dnl --------------------------------------------------------------------
43 dnl Restricted form of AC_ARG_WITH that limits user options
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([,]),[
52 for ol_val in ifelse($4,,[yes no],[$4]) ; do
53 if test "$withval" = "$ol_val" ; then
57 if test "$ol_arg" = "invalid" ; then
58 AC_MSG_ERROR(bad value $withval for --with-$1)
62 [ ol_with_$1=ifelse($3,,"no","$3")])dnl
63 dnl AC_MSG_RESULT([OpenLDAP --with-$1 $ol_with_$1])
66 dnl ====================================================================
67 dnl Check for dependency generation flag
68 AC_DEFUN([OL_MKDEPEND], [# test for make depend flag
71 if test -z "${MKDEP}"; then
73 if test -z "${MKDEP_FLAGS}"; then
74 AC_CACHE_CHECK([for ${OL_MKDEP} depend flag], ol_cv_mkdep, [
76 for flag in "-M" "-xM"; do
77 cat > conftest.c <<EOF
80 if AC_TRY_COMMAND($OL_MKDEP $flag conftest.c) \
81 | egrep '^conftest\.'"${ac_objext}" >/dev/null 2>&1
83 if test ! -f conftest."${ac_object}" ; then
85 OL_MKDEP_FLAGS="$flag"
94 OL_MKDEP_FLAGS="${MKDEP_FLAGS}"
99 OL_MKDEP_FLAGS="${MKDEP_FLAGS}"
102 AC_SUBST(OL_MKDEP_FLAGS)
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([[
111 #include <__ASCII__/generate_error.h>
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])
119 dnl --------------------------------------------------------------------
120 dnl OpenLDAP version of STDC header check w/ EBCDIC support
121 AC_DEFUN([OL_HEADER_STDC],
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>
128 #include <float.h>]])],[ol_cv_header_stdc=yes],[ol_cv_header_stdc=no])
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)
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)
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>
144 # define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
145 # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
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))
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);
156 ]])],[],[ol_cv_header_stdc=no],[:])
158 if test $ol_cv_header_stdc = yes; then
159 AC_DEFINE(STDC_HEADERS)
161 ac_cv_header_stdc=disable
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],
170 ol_RESOLVER_LIB=ifelse($2,,,$2)
172 LIBS="$ol_RESOLVER_LIB $LIBS"
174 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
175 #ifdef HAVE_SYS_TYPES_H
176 # include <sys/types.h>
178 #include <netinet/in.h>
179 #ifdef HAVE_ARPA_NAMESER_H
180 # include <arpa/nameser.h>
187 char *request = NULL;
188 unsigned char reply[64*1024];
189 unsigned char host[64*1024];
193 /* Bind 8/9 interface */
194 len = res_query(request, ns_c_in, ns_t_srv, reply, sizeof(reply));
196 /* Bind 4 interface */
200 len = res_query(request, C_IN, T_SRV, reply, sizeof(reply));
204 /* Bind 8/9 interface */
206 #elif defined(HFIXEDSZ)
207 /* Bind 4 interface w/ HFIXEDSZ */
210 /* Bind 4 interface w/o HFIXEDSZ */
213 status = dn_expand( reply, reply+len, p, host, sizeof(host));
214 }]])],[$1=yes],[$1=no])
219 if test $$1 = yes ; then
220 ol_cv_lib_resolver=ifelse($2,,yes,$2)
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])
233 dnl ====================================================================
234 dnl Berkeley DB macros
236 dnl --------------------------------------------------------------------
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],
242 ol_DB_LIB=ifelse($2,,,$2)
244 LIBS="$ol_DB_LIB $LTHREAD_LIBS $LIBS"
246 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
253 #ifndef DB_VERSION_MAJOR
254 # define DB_VERSION_MAJOR 1
258 #define NULL ((void*)0)
261 #if DB_VERSION_MAJOR > 1
264 int major, minor, patch;
266 version = db_version( &major, &minor, &patch );
268 if( major != DB_VERSION_MAJOR ||
269 minor < DB_VERSION_MINOR )
271 printf("Berkeley DB version mismatch\n"
272 "\theader: %s\n\tlibrary: %s\n",
273 DB_VERSION_STRING, version);
279 #if DB_VERSION_MAJOR > 2
280 db_env_create( NULL, 0 );
281 #elif DB_VERSION_MAJOR > 1
284 (void) dbopen( NULL, 0, 0, 0, NULL);
286 ]])],[$1=yes],[$1=no])
291 if test $$1 = yes ; then
292 ol_cv_lib_db=ifelse($2,,yes,$2)
297 dnl --------------------------------------------------------------------
298 dnl Try to locate appropriate library
299 AC_DEFUN([OL_BERKELEY_DB_LINK],
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])
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], [
330 LIBS="$LTHREAD_LIBS $LIBS"
331 if test $ol_cv_lib_db != yes ; then
332 LIBS="$ol_cv_lib_db $LIBS"
335 AC_RUN_IFELSE([AC_LANG_SOURCE([[
341 #ifndef DB_VERSION_MAJOR
342 # define DB_VERSION_MAJOR 1
345 #define NULL ((void *)0)
349 #if DB_VERSION_MAJOR > 1
351 int major, minor, patch;
353 version = db_version( &major, &minor, &patch );
355 if( major != DB_VERSION_MAJOR ||
356 minor != DB_VERSION_MINOR ||
357 patch != DB_VERSION_PATCH )
359 printf("Berkeley DB version mismatch\n"
360 "\theader: %s\n\tlibrary: %s\n",
361 DB_VERSION_STRING, version);
367 }]])],[ol_cv_berkeley_db_version=yes],[ol_cv_berkeley_db_version=no],[ol_cv_berkeley_db_version=cross])
372 if test $ol_cv_berkeley_db_version = no ; then
373 AC_MSG_ERROR([Berkeley DB version mismatch])
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], [
382 LIBS="$LTHREAD_LIBS $LIBS"
383 if test $ol_cv_lib_db != yes ; then
384 LIBS="$ol_cv_lib_db $LIBS"
387 AC_RUN_IFELSE([AC_LANG_SOURCE([[
394 #define NULL ((void *)0)
399 u_int32_t flags = DB_CREATE |
405 #if DB_VERSION_MAJOR > 2
408 rc = db_env_create( &env, 0 );
410 flags |= DB_INIT_MPOOL;
411 #ifdef DB_MPOOL_PRIVATE
412 flags |= DB_MPOOL_PRIVATE;
416 printf("BerkeleyDB: %s\n", db_strerror(rc) );
420 #if (DB_VERSION_MAJOR > 3) || (DB_VERSION_MINOR >= 1)
421 rc = env->open( env, NULL, flags, 0 );
423 rc = env->open( env, NULL, NULL, flags, 0 );
427 rc = env->close( env, 0 );
431 printf("BerkeleyDB: %s\n", db_strerror(rc) );
437 memset( &env, '\0', sizeof(env) );
439 rc = db_appinit( NULL, NULL, &env, flags );
445 unlink("__db_mpool.share");
446 unlink("__db_lock.share");
450 }]])],[ol_cv_berkeley_db_thread=yes],[ol_cv_berkeley_db_thread=no],[ol_cv_berkeley_db_thread=cross])
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])
461 dnl --------------------------------------------------------------------
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
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
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,[
482 /* this check could be improved */
483 #ifndef DB_VERSION_MAJOR
484 # define DB_VERSION_MAJOR 1
486 #ifndef DB_VERSION_MINOR
487 # define DB_VERSION_MINOR 0
490 /* require 4.2 or later */
491 #if (DB_VERSION_MAJOR >= 4) && (DB_VERSION_MINOR >= 2)
494 ], [ol_cv_bdb_compat=yes], [ol_cv_bdb_compat=no])])
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,[
510 /* this check could be improved */
511 #ifndef DB_VERSION_MAJOR
512 # define DB_VERSION_MAJOR 1
515 #if DB_VERSION_MAJOR == 1
518 ], [ol_cv_header_db1=yes], [ol_cv_header_db1=no])])
520 if test $ol_cv_header_db1 = yes ; then
522 if test "$ol_cv_lib_db" != no ; then
523 ol_cv_berkeley_db=yes
529 dnl ====================================================================
530 dnl Check if GDBM library exists
531 dnl Check for gdbm_open in standard libraries or -lgdbm
533 dnl defines ol_cv_lib_gdbm to 'yes' or '-lgdbm' or 'no'
534 dnl 'yes' implies gdbm_open is in $LIBS
537 dnl AC_CHECK_FUNC(gdbm_open)
538 dnl AC_CHECK_LIB(gdbm,gdbm_open)
540 AC_DEFUN([OL_LIB_GDBM],
541 [AC_CACHE_CHECK(for GDBM library, [ol_cv_lib_gdbm],
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])
550 dnl --------------------------------------------------------------------
551 dnl Check if GDBM exists
553 dnl defines ol_cv_gdbm to 'yes' or 'no'
557 dnl AC_CHECK_HEADERS(gdbm.h)
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
569 if test $ol_cv_gdbm = yes ; then
570 AC_DEFINE(HAVE_GDBM,1, [define if GNU DBM is available])
574 dnl ====================================================================
575 dnl Check if MDBM library exists
576 dnl Check for mdbm_open in standard libraries or -lmdbm
578 dnl defines ol_cv_lib_mdbm to 'yes' or '-lmdbm' or 'no'
579 dnl 'yes' implies mdbm_open is in $LIBS
582 dnl AC_CHECK_FUNC(mdbm_set_chain)
583 dnl AC_CHECK_LIB(mdbm,mdbm_set_chain)
585 AC_DEFUN([OL_LIB_MDBM],
586 [AC_CACHE_CHECK(for MDBM library, [ol_cv_lib_mdbm],
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])
595 dnl --------------------------------------------------------------------
596 dnl Check if MDBM exists
598 dnl defines ol_cv_mdbm to 'yes' or 'no'
602 dnl AC_CHECK_HEADERS(mdbm.h)
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
614 if test $ol_cv_mdbm = yes ; then
615 AC_DEFINE(HAVE_MDBM,1, [define if MDBM is available])
619 dnl ====================================================================
620 dnl Check if NDBM library exists
621 dnl Check for dbm_open in standard libraries or -lndbm or -ldbm
623 dnl defines ol_cv_lib_ndbm to 'yes' or '-lndbm' or -ldbm or 'no'
624 dnl 'yes' implies ndbm_open is in $LIBS
627 dnl AC_CHECK_FUNC(dbm_open)
628 dnl AC_CHECK_LIB(ndbm,dbm_open)
629 dnl AC_CHECK_LIB(dbm,dbm_open)
632 dnl should also check SVR4 case: dbm_open() in -lucb but that
633 dnl would requiring dealing with -L/usr/ucblib
635 AC_DEFUN([OL_LIB_NDBM],
636 [AC_CACHE_CHECK(for NDBM library, [ol_cv_lib_ndbm],
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
648 dnl --------------------------------------------------------------------
649 dnl Check if NDBM exists
651 dnl defines ol_cv_ndbm to 'yes' or 'no'
655 dnl AC_CHECK_HEADERS(ndbm.h)
658 dnl Doesn't handle SVR4 case (see above)
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
670 if test $ol_cv_ndbm = yes ; then
671 AC_DEFINE(HAVE_NDBM,1, [define if NDBM is available])
675 dnl ====================================================================
676 dnl Check POSIX Thread version
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.
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.
695 dnl Draft 9 and 10 are equivalent for our purposes.
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>
702 int i = PTHREAD_CREATE_JOINABLE;
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
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
719 ], ol_cv_pthread_version=5, ol_cv_pthread_version=4) ]) ]) ])
723 dnl --------------------------------------------------------------------
724 AC_DEFUN([OL_PTHREAD_TEST_INCLUDES], [[
725 /* pthread test headers */
727 #if HAVE_PTHREADS < 7
731 #define NULL (void*)0
737 return (void *) (p == NULL);
740 AC_DEFUN([OL_PTHREAD_TEST_FUNCTION],[[
741 /* pthread test function */
742 #ifndef PTHREAD_CREATE_DETACHED
743 #define PTHREAD_CREATE_DETACHED 1
747 int detach = PTHREAD_CREATE_DETACHED;
749 #if HAVE_PTHREADS > 4
753 status = pthread_attr_init(&attr);
754 if( status ) return status;
756 #if HAVE_PTHREADS < 7
757 status = pthread_attr_setdetachstate(&attr, &detach);
758 if( status < 0 ) status = errno;
760 status = pthread_attr_setdetachstate(&attr, detach);
762 if( status ) return status;
763 status = pthread_create( &t, &attr, task, NULL );
764 #if HAVE_PTHREADS < 7
765 if( status < 0 ) status = errno;
767 if( status ) return status;
769 /* Draft 4 pthreads */
770 status = pthread_create( &t, pthread_attr_default, task, NULL );
771 if( status ) return errno;
773 /* give thread a chance to complete */
774 /* it should remain joinable and hence detachable */
777 status = pthread_detach( &t );
778 if( status ) return errno;
781 #ifdef HAVE_LINUX_THREADS
782 pthread_kill_other_threads_np();
788 AC_DEFUN([OL_PTHREAD_TEST_PROGRAM],
789 [OL_PTHREAD_TEST_INCLUDES
795 OL_PTHREAD_TEST_FUNCTION
798 dnl --------------------------------------------------------------------
799 AC_DEFUN([OL_PTHREAD_TRY], [# Pthread try link: $1 ($2)
800 if test "$ol_link_threads" = no ; then
802 AC_CACHE_CHECK([for pthread link with $1], [$2], [
807 AC_RUN_IFELSE([OL_PTHREAD_TEST_PROGRAM],
810 [AC_TRY_LINK(OL_PTHREAD_TEST_INCLUDES,OL_PTHREAD_TEST_FUNCTION,
817 if test $$2 = yes ; then
818 ol_link_pthreads="$1"
819 ol_link_threads=posix
824 dnl ====================================================================
825 dnl Check GNU Pth pthread Header
827 dnl defines ol_cv_header linux_threads to 'yes' or 'no'
828 dnl 'no' implies pthreads.h is not LinuxThreads or pthreads.h
829 dnl doesn't exists. Existance of pthread.h should separately
832 AC_DEFUN([OL_HEADER_GNU_PTH_PTHREAD_H], [
833 AC_CACHE_CHECK([for GNU Pth pthread.h],
834 [ol_cv_header_gnu_pth_pthread_h],
835 [AC_EGREP_CPP(__gnu_pth__,
836 [#include <pthread.h>
837 #ifdef _POSIX_THREAD_IS_GNU_PTH
841 [ol_cv_header_gnu_pth_pthread_h=yes],
842 [ol_cv_header_gnu_pth_pthread_h=no])
845 dnl ====================================================================
846 dnl Check for NT Threads
847 AC_DEFUN([OL_NT_THREADS], [
848 AC_CHECK_FUNC(_beginthread)
850 if test $ac_cv_func__beginthread = yes ; then
851 AC_DEFINE(HAVE_NT_THREADS,1,[if you have NT Threads])
855 dnl ====================================================================
856 dnl Check LinuxThreads Header
858 dnl defines ol_cv_header linux_threads to 'yes' or 'no'
859 dnl 'no' implies pthreads.h is not LinuxThreads or pthreads.h
860 dnl doesn't exists. Existance of pthread.h should separately
863 AC_DEFUN([OL_HEADER_LINUX_THREADS], [
864 AC_CACHE_CHECK([for LinuxThreads pthread.h],
865 [ol_cv_header_linux_threads],
866 [AC_EGREP_CPP(pthread_kill_other_threads_np,
867 [#include <pthread.h>],
868 [ol_cv_header_linux_threads=yes],
869 [ol_cv_header_linux_threads=no])
871 if test $ol_cv_header_linux_threads = yes; then
872 AC_DEFINE(HAVE_LINUX_THREADS,1,[if you have LinuxThreads])
875 dnl --------------------------------------------------------------------
876 dnl Check LinuxThreads Implementation
878 dnl defines ol_cv_sys_linux_threads to 'yes' or 'no'
879 dnl 'no' implies pthreads implementation is not LinuxThreads.
881 AC_DEFUN([OL_SYS_LINUX_THREADS], [
882 AC_CHECK_FUNCS(pthread_kill_other_threads_np)
883 AC_CACHE_CHECK([for LinuxThreads implementation],
884 [ol_cv_sys_linux_threads],
885 [ol_cv_sys_linux_threads=$ac_cv_func_pthread_kill_other_threads_np])
888 dnl --------------------------------------------------------------------
889 dnl Check LinuxThreads consistency
890 AC_DEFUN([OL_LINUX_THREADS], [
891 AC_REQUIRE([OL_HEADER_LINUX_THREADS])
892 AC_REQUIRE([OL_SYS_LINUX_THREADS])
893 AC_CACHE_CHECK([for LinuxThreads consistency], [ol_cv_linux_threads], [
894 if test $ol_cv_header_linux_threads = yes -a \
895 $ol_cv_sys_linux_threads = yes; then
896 ol_cv_linux_threads=yes
897 elif test $ol_cv_header_linux_threads = no -a \
898 $ol_cv_sys_linux_threads = no; then
899 ol_cv_linux_threads=no
901 ol_cv_linux_threads=error
906 dnl ====================================================================
907 dnl Check for POSIX Regex
908 AC_DEFUN([OL_POSIX_REGEX], [
909 AC_CACHE_CHECK([for compatible POSIX regex],ol_cv_c_posix_regex,[
910 AC_RUN_IFELSE([AC_LANG_SOURCE([[
911 #include <sys/types.h>
913 static char *pattern, *string;
921 if(regcomp(&re, pattern, 0)) {
925 string = "ALL MATCH";
927 rc = regexec(&re, string, 0, (void*)0, 0);
932 }]])],[ol_cv_c_posix_regex=yes],[ol_cv_c_posix_regex=no],[ol_cv_c_posix_regex=cross])])
935 dnl ====================================================================
936 dnl Check if toupper() requires islower() to be called first
937 AC_DEFUN([OL_C_UPPER_LOWER],
938 [AC_CACHE_CHECK([if toupper() requires islower()],ol_cv_c_upper_lower,[
939 AC_RUN_IFELSE([AC_LANG_SOURCE([[
943 if ('C' == toupper('C'))
947 }]])],[ol_cv_c_upper_lower=no],[ol_cv_c_upper_lower=yes],[ol_cv_c_upper_lower=safe])])
948 if test $ol_cv_c_upper_lower != no ; then
949 AC_DEFINE(C_UPPER_LOWER,1, [define if toupper() requires islower()])
953 dnl ====================================================================
954 dnl Error string checks
956 dnl Check for declaration of sys_errlist in one of stdio.h and errno.h.
957 dnl Declaration of sys_errlist on BSD4.4 interferes with our declaration.
958 dnl Reported by Keith Bostic.
959 AC_DEFUN([OL_SYS_ERRLIST],
960 [AC_CACHE_CHECK([declaration of sys_errlist],ol_cv_dcl_sys_errlist,[
961 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
963 #include <sys/types.h>
967 #endif ]], [[char *c = (char *) *sys_errlist]])],[ol_cv_dcl_sys_errlist=yes
968 ol_cv_have_sys_errlist=yes],[ol_cv_dcl_sys_errlist=no])])
970 # It's possible (for near-UNIX clones) that sys_errlist doesn't exist
971 if test $ol_cv_dcl_sys_errlist = no ; then
972 AC_DEFINE(DECL_SYS_ERRLIST,1,
973 [define if sys_errlist is not declared in stdio.h or errno.h])
975 AC_CACHE_CHECK([existence of sys_errlist],ol_cv_have_sys_errlist,[
976 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 if test $ol_cv_have_sys_errlist = yes ; then
979 AC_DEFINE(HAVE_SYS_ERRLIST,1,
980 [define if you actually have sys_errlist in your libs])
983 AC_DEFUN([OL_NONPOSIX_STRERROR_R],
984 [AC_CACHE_CHECK([non-posix strerror_r],ol_cv_nonposix_strerror_r,[
985 AC_EGREP_CPP(strerror_r,[#include <string.h>],
986 ol_decl_strerror_r=yes, ol_decl_strerror_r=no)dnl
988 if test $ol_decl_strerror_r = yes ; then
989 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <string.h>]], [[ /* from autoconf 2.59 */
991 char x = *strerror_r (0, buf, sizeof buf);
992 char *p = strerror_r (0, buf, sizeof buf);
993 ]])],[ol_cv_nonposix_strerror_r=yes],[ol_cv_nonposix_strerror_r=no])
995 AC_RUN_IFELSE([AC_LANG_SOURCE([[
999 strerror_r( 1, buf, sizeof buf );
1000 exit( buf[0] == 0 );
1002 ]])],[ol_cv_nonposix_strerror_r=yes],[ol_cv_nonposix_strerror=no],[ol_cv_nonposix_strerror=no])
1005 if test $ol_cv_nonposix_strerror_r = yes ; then
1006 AC_DEFINE(HAVE_NONPOSIX_STRERROR_R,1,
1007 [define if strerror_r returns char* instead of int])
1011 AC_DEFUN([OL_STRERROR],
1012 [OL_SYS_ERRLIST dnl TEMPORARY
1013 AC_CHECK_FUNCS(strerror strerror_r)
1014 ol_cv_func_strerror_r=no
1015 if test "${ac_cv_func_strerror_r}" = yes ; then
1016 OL_NONPOSIX_STRERROR_R
1017 elif test "${ac_cv_func_strerror}" = no ; then
1021 dnl ====================================================================
1022 dnl Early MIPS compilers (used in Ultrix 4.2) don't like
1023 dnl "int x; int *volatile a = &x; *a = 0;"
1024 dnl -- borrowed from PDKSH
1025 AC_DEFUN([OL_C_VOLATILE],
1026 [AC_CACHE_CHECK(if compiler understands volatile, ol_cv_c_volatile,
1027 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x, y, z;]], [[volatile int a; int * volatile b = x ? &y : &z;
1028 /* Older MIPS compilers (eg., in Ultrix 4.2) don't like *b = 0 */
1029 *b = 0;]])],[ol_cv_c_volatile=yes],[ol_cv_c_volatile=no])])
1030 if test $ol_cv_c_volatile = yes; then
1033 AC_DEFINE(volatile,,[define as empty if volatile is not supported])
1037 dnl ====================================================================
1038 dnl Look for fetch(3)
1039 AC_DEFUN([OL_LIB_FETCH],
1041 LIBS="-lfetch -lcom_err $LIBS"
1042 AC_CACHE_CHECK([fetch(3) library],ol_cv_lib_fetch,[
1043 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1044 #include <sys/param.h>
1046 #include <fetch.h>]], [[struct url *u = fetchParseURL("file:///"); ]])],[ol_cv_lib_fetch=yes],[ol_cv_lib_fetch=no])])
1048 if test $ol_cv_lib_fetch != no ; then
1049 ol_link_fetch="-lfetch -lcom_err"
1050 AC_DEFINE(HAVE_FETCH,1,
1051 [define if you actually have FreeBSD fetch(3)])
1055 dnl ====================================================================
1056 dnl Define sig_atomic_t if not defined in signal.h
1057 AC_DEFUN([OL_TYPE_SIG_ATOMIC_T],
1058 [AC_CACHE_CHECK(for sig_atomic_t, ol_cv_type_sig_atomic_t,
1059 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <signal.h>]], [[sig_atomic_t atomic;]])],[ol_cv_type_sig_atomic_t=yes],[ol_cv_type_sig_atomic_t=no])])
1060 if test $ol_cv_type_sig_atomic_t = no; then
1061 AC_DEFINE(sig_atomic_t,int,
1062 [define to atomic type if sig_atomic_t is not available])
1066 dnl ====================================================================
1067 dnl Define socklen_t if not defined in sys/types.h or sys/socket.h
1068 AC_DEFUN([OL_TYPE_SOCKLEN_T],
1069 [AC_CACHE_CHECK(for socklen_t, ol_cv_type_socklen_t,
1070 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1071 #ifdef HAVE_SYS_TYPES_H
1072 #include <sys/types.h>
1074 #ifdef HAVE_SYS_SOCKET_H
1075 #include <sys/socket.h>
1077 ]], [[socklen_t len;]])],[ol_cv_type_socklen_t=yes],[ol_cv_type_socklen_t=no])])
1078 if test $ol_cv_type_socklen_t = no; then
1079 AC_DEFINE(socklen_t, int,
1080 [define to int if socklen_t is not available])
1084 dnl ====================================================================
1085 dnl Define inet_aton is available
1086 AC_DEFUN([OL_FUNC_INET_ATON],
1087 [AC_CACHE_CHECK([for inet_aton()], ol_cv_func_inet_aton,
1088 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1089 #ifdef HAVE_SYS_TYPES_H
1090 # include <sys/types.h>
1092 #ifdef HAVE_SYS_SOCKET_H
1093 # include <sys/socket.h>
1094 # ifdef HAVE_SYS_SELECT_H
1095 # include <sys/select.h>
1097 # include <netinet/in.h>
1098 # ifdef HAVE_ARPA_INET_H
1099 # include <arpa/inet.h>
1102 ]], [[struct in_addr in;
1103 int rc = inet_aton( "255.255.255.255", &in );]])],[ol_cv_func_inet_aton=yes],[ol_cv_func_inet_aton=no])])
1104 if test $ol_cv_func_inet_aton != no; then
1105 AC_DEFINE(HAVE_INET_ATON, 1,
1106 [define to you inet_aton(3) is available])
1110 dnl ====================================================================
1111 dnl check no of arguments for ctime_r
1112 AC_DEFUN([OL_FUNC_CTIME_R_NARGS],
1113 [AC_CACHE_CHECK(number of arguments of ctime_r, ol_cv_func_ctime_r_nargs,
1114 [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])
1116 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])
1118 if test $ol_cv_func_ctime_r_nargs3 = yes -a \
1119 $ol_cv_func_ctime_r_nargs2 = no ; then
1121 ol_cv_func_ctime_r_nargs=3
1123 elif test $ol_cv_func_ctime_r_nargs3 = no -a \
1124 $ol_cv_func_ctime_r_nargs2 = yes ; then
1126 ol_cv_func_ctime_r_nargs=2
1129 ol_cv_func_ctime_r_nargs=0
1133 if test $ol_cv_func_ctime_r_nargs -gt 1 ; then
1134 AC_DEFINE_UNQUOTED(CTIME_R_NARGS, $ol_cv_func_ctime_r_nargs,
1135 [set to the number of arguments ctime_r() expects])
1139 dnl --------------------------------------------------------------------
1140 dnl check return type of ctime_r()
1141 AC_DEFUN([OL_FUNC_CTIME_R_TYPE],
1142 [AC_CACHE_CHECK(return type of ctime_r, ol_cv_func_ctime_r_type,
1143 [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"])
1145 if test $ol_cv_func_ctime_r_type = "int" ; then
1146 AC_DEFINE(CTIME_R_RETURNS_INT,1, [define if ctime_r() returns int])
1149 dnl ====================================================================
1150 dnl check no of arguments for gethostbyname_r
1151 AC_DEFUN([OL_FUNC_GETHOSTBYNAME_R_NARGS],
1152 [AC_CACHE_CHECK(number of arguments of gethostbyname_r,
1153 ol_cv_func_gethostbyname_r_nargs,
1154 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
1155 #include <sys/socket.h>
1156 #include <netinet/in.h>
1158 #define BUFSIZE (sizeof(struct hostent)+10)]], [[struct hostent hent; char buffer[BUFSIZE];
1159 int bufsize=BUFSIZE;int h_errno;
1160 (void)gethostbyname_r("segovia.cs.purdue.edu", &hent,
1161 buffer, bufsize, &h_errno);]])],[ol_cv_func_gethostbyname_r_nargs5=yes],[ol_cv_func_gethostbyname_r_nargs5=no])
1163 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
1164 #include <sys/socket.h>
1165 #include <netinet/in.h>
1167 #define BUFSIZE (sizeof(struct hostent)+10)]], [[struct hostent hent;struct hostent *rhent;
1168 char buffer[BUFSIZE];
1169 int bufsize=BUFSIZE;int h_errno;
1170 (void)gethostbyname_r("localhost", &hent, buffer, bufsize,
1171 &rhent, &h_errno);]])],[ol_cv_func_gethostbyname_r_nargs6=yes],[ol_cv_func_gethostbyname_r_nargs6=no])
1173 if test $ol_cv_func_gethostbyname_r_nargs5 = yes -a \
1174 $ol_cv_func_gethostbyname_r_nargs6 = no ; then
1176 ol_cv_func_gethostbyname_r_nargs=5
1178 elif test $ol_cv_func_gethostbyname_r_nargs5 = no -a \
1179 $ol_cv_func_gethostbyname_r_nargs6 = yes ; then
1181 ol_cv_func_gethostbyname_r_nargs=6
1184 ol_cv_func_gethostbyname_r_nargs=0
1187 if test $ol_cv_func_gethostbyname_r_nargs -gt 1 ; then
1188 AC_DEFINE_UNQUOTED(GETHOSTBYNAME_R_NARGS,
1189 $ol_cv_func_gethostbyname_r_nargs,
1190 [set to the number of arguments gethostbyname_r() expects])
1194 dnl check no of arguments for gethostbyaddr_r
1195 AC_DEFUN([OL_FUNC_GETHOSTBYADDR_R_NARGS],
1196 [AC_CACHE_CHECK(number of arguments of gethostbyaddr_r,
1197 [ol_cv_func_gethostbyaddr_r_nargs],
1198 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
1199 #include <sys/socket.h>
1200 #include <netinet/in.h>
1202 #define BUFSIZE (sizeof(struct hostent)+10)]], [[struct hostent hent; char buffer[BUFSIZE];
1204 size_t alen=sizeof(struct in_addr);
1205 int bufsize=BUFSIZE;int h_errno;
1206 (void)gethostbyaddr_r( (void *)&(add.s_addr),
1207 alen, AF_INET, &hent, buffer, bufsize, &h_errno);]])],[ol_cv_func_gethostbyaddr_r_nargs7=yes],[ol_cv_func_gethostbyaddr_r_nargs7=no])
1209 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
1210 #include <sys/socket.h>
1211 #include <netinet/in.h>
1213 #define BUFSIZE (sizeof(struct hostent)+10)]], [[struct hostent hent;
1214 struct hostent *rhent; char buffer[BUFSIZE];
1216 size_t alen=sizeof(struct in_addr);
1217 int bufsize=BUFSIZE;int h_errno;
1218 (void)gethostbyaddr_r( (void *)&(add.s_addr),
1219 alen, AF_INET, &hent, buffer, bufsize,
1220 &rhent, &h_errno);]])],[ol_cv_func_gethostbyaddr_r_nargs8=yes],[ol_cv_func_gethostbyaddr_r_nargs8=no])
1222 if test $ol_cv_func_gethostbyaddr_r_nargs7 = yes -a \
1223 $ol_cv_func_gethostbyaddr_r_nargs8 = no ; then
1225 ol_cv_func_gethostbyaddr_r_nargs=7
1227 elif test $ol_cv_func_gethostbyaddr_r_nargs7 = no -a \
1228 $ol_cv_func_gethostbyaddr_r_nargs8 = yes ; then
1230 ol_cv_func_gethostbyaddr_r_nargs=8
1233 ol_cv_func_gethostbyaddr_r_nargs=0
1236 if test $ol_cv_func_gethostbyaddr_r_nargs -gt 1 ; then
1237 AC_DEFINE_UNQUOTED(GETHOSTBYADDR_R_NARGS,
1238 $ol_cv_func_gethostbyaddr_r_nargs,
1239 [set to the number of arguments gethostbyaddr_r() expects])
1243 dnl --------------------------------------------------------------------
1244 dnl Check for Cyrus SASL version compatility
1245 AC_DEFUN([OL_SASL_COMPAT],
1246 [AC_CACHE_CHECK([Cyrus SASL library version], [ol_cv_sasl_compat],[
1247 AC_EGREP_CPP(__sasl_compat,[
1248 #ifdef HAVE_SASL_SASL_H
1249 #include <sasl/sasl.h>
1254 /* Require 2.1.15+ */
1255 #if SASL_VERSION_MAJOR == 2 && SASL_VERSION_MINOR > 1
1256 char *__sasl_compat = "2.2+ or better okay (we guess)";
1257 #elif SASL_VERSION_MAJOR == 2 && SASL_VERSION_MINOR == 1 \
1258 && SASL_VERSION_STEP >=15
1259 char *__sasl_compat = "2.1.15+ or better okay";
1261 ], [ol_cv_sasl_compat=yes], [ol_cv_sasl_compat=no])])
1263 dnl ====================================================================
1264 dnl check for SSL compatibility
1265 AC_DEFUN([OL_SSL_COMPAT],
1266 [AC_CACHE_CHECK([OpenSSL library version (CRL checking capability)], [ol_cv_ssl_crl_compat],[
1267 AC_EGREP_CPP(__ssl_compat,[
1268 #ifdef HAVE_OPENSSL_SSL_H
1269 #include <openssl/ssl.h>
1274 /* Require 0.9.7d+ */
1275 #if OPENSSL_VERSION_NUMBER >= 0x0090704fL
1276 char *__ssl_compat = "0.9.7d";
1278 ], [ol_cv_ssl_crl_compat=yes], [ol_cv_ssl_crl_compat=no])])