1 dnl OpenLDAP Autoconf Macros
3 dnl This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 dnl Copyright 1998-2004 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)
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([,]),[
26 for ol_val in ifelse($4,,[auto yes no],[$4]) ; do
27 if test "$enableval" = "$ol_val" ; then
31 if test "$ol_arg" = "invalid" ; then
32 AC_MSG_ERROR(bad value $enableval for --enable-$1)
34 ol_enable_$1="$ol_arg"
36 [ ol_enable_$1=ifelse($3,,"auto","$3")])dnl
37 dnl AC_VERBOSE(OpenLDAP -enable-$1 $ol_enable_$1)
41 dnl --------------------------------------------------------------------
42 dnl Restricted form of AC_ARG_WITH that limits user options
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([,]),[
51 for ol_val in ifelse($4,,[yes no],[$4]) ; do
52 if test "$withval" = "$ol_val" ; then
56 if test "$ol_arg" = "invalid" ; then
57 AC_MSG_ERROR(bad value $withval for --with-$1)
61 [ ol_with_$1=ifelse($3,,"no","$3")])dnl
62 dnl AC_VERBOSE(OpenLDAP --with-$1 $ol_with_$1)
66 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
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"
80 #include <sys/types.h>
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
86 if test x$AC_CV_NAME = x ; then
87 AC_MSG_ERROR([cannot determine a size for $1])
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
94 dnl ====================================================================
95 dnl check if hard links are supported.
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
108 rm -f conftest.src conftest.dst
110 LN_H="$ol_cv_prog_LN_H"
111 if test "$ol_cv_prog_LN_H" = "ln"; then
119 dnl ====================================================================
120 dnl Check for dependency generation flag
121 AC_DEFUN([OL_MKDEPEND], [# test for make depend flag
124 if test -z "${MKDEP}"; then
126 if test -z "${MKDEP_FLAGS}"; then
127 AC_CACHE_CHECK([for ${OL_MKDEP} depend flag], ol_cv_mkdep, [
129 for flag in "-M" "-xM"; do
130 cat > conftest.c <<EOF
133 if AC_TRY_COMMAND($OL_MKDEP $flag conftest.c) \
134 | egrep '^conftest\.'"${ac_objext}" >/dev/null 2>&1
136 if test ! -f conftest."${ac_object}" ; then
138 OL_MKDEP_FLAGS="$flag"
147 OL_MKDEP_FLAGS="${MKDEP_FLAGS}"
152 OL_MKDEP_FLAGS="${MKDEP_FLAGS}"
155 AC_SUBST(OL_MKDEP_FLAGS)
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,[
164 #include <__ASCII__/generate_error.h>
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])
174 dnl --------------------------------------------------------------------
175 dnl OpenLDAP version of STDC header check w/ EBCDIC support
176 AC_DEFUN(OL_HEADER_STDC,
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>
183 #include <float.h>], ol_cv_header_stdc=yes, ol_cv_header_stdc=no)
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)
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)
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>
199 # define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
200 # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
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))
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);
211 ], , ol_cv_header_stdc=no, :)
213 if test $ol_cv_header_stdc = yes; then
214 AC_DEFINE(STDC_HEADERS)
216 ac_cv_header_stdc=disable
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>],[
225 pwd.pw_gecos = pwd.pw_name;
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])
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>],[
240 pwd.pw_passwd = pwd.pw_name;
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])
249 dnl ====================================================================
250 dnl Berkeley DB macros
252 dnl --------------------------------------------------------------------
254 AC_DEFUN([OL_BERKELEY_DB_TRY],
255 [if test $ol_cv_lib_db = no ; then
256 AC_CACHE_CHECK([for Berkeley DB link (]ifelse($2,,default,$2)[)],[$1],
258 ol_DB_LIB=ifelse($2,,,$2)
260 LIBS="$ol_DB_LIB $LTHREAD_LIBS $LIBS"
269 #ifndef DB_VERSION_MAJOR
270 # define DB_VERSION_MAJOR 1
274 #define NULL ((void*)0)
277 #if DB_VERSION_MAJOR > 1
280 int major, minor, patch;
282 version = db_version( &major, &minor, &patch );
284 if( major != DB_VERSION_MAJOR ||
285 minor < DB_VERSION_MINOR )
287 printf("Berkeley DB version mismatch\n"
288 "\theader: %s\n\tlibrary: %s\n",
289 DB_VERSION_STRING, version);
295 #if DB_VERSION_MAJOR > 2
296 db_env_create( NULL, 0 );
297 #elif DB_VERSION_MAJOR > 1
300 (void) dbopen( NULL, 0, 0, 0, NULL);
307 if test $$1 = yes ; then
308 ol_cv_lib_db=ifelse($2,,yes,$2)
313 dnl --------------------------------------------------------------------
314 dnl Try to locate appropriate library
315 AC_DEFUN([OL_BERKELEY_DB_LINK],
317 OL_BERKELEY_DB_TRY(ol_cv_db_none)
318 OL_BERKELEY_DB_TRY(ol_cv_db_db42,[-ldb42])
319 OL_BERKELEY_DB_TRY(ol_cv_db_db_42,[-ldb-42])
320 OL_BERKELEY_DB_TRY(ol_cv_db_db_4_dot_2,[-ldb-4.2])
321 OL_BERKELEY_DB_TRY(ol_cv_db_db_4_2,[-ldb-4-2])
322 OL_BERKELEY_DB_TRY(ol_cv_db_db_4,[-ldb-4])
323 OL_BERKELEY_DB_TRY(ol_cv_db_db4,[-ldb4])
324 OL_BERKELEY_DB_TRY(ol_cv_db_db,[-ldb])
325 OL_BERKELEY_DB_TRY(ol_cv_db_db41,[-ldb41])
326 OL_BERKELEY_DB_TRY(ol_cv_db_db_41,[-ldb-41])
327 OL_BERKELEY_DB_TRY(ol_cv_db_db_4_dot_1,[-ldb-4.1])
328 OL_BERKELEY_DB_TRY(ol_cv_db_db_4_1,[-ldb-4-1])
329 OL_BERKELEY_DB_TRY(ol_cv_db_db3,[-ldb3])
330 OL_BERKELEY_DB_TRY(ol_cv_db_db_3,[-ldb-3])
331 OL_BERKELEY_DB_TRY(ol_cv_db_db2,[-ldb2])
332 OL_BERKELEY_DB_TRY(ol_cv_db_db_2,[-ldb-2])
333 OL_BERKELEY_DB_TRY(ol_cv_db_db1,[-ldb1])
334 OL_BERKELEY_DB_TRY(ol_cv_db_db_1,[-ldb-1])
337 dnl --------------------------------------------------------------------
338 dnl Check if Berkeley DB version
339 AC_DEFUN([OL_BERKELEY_DB_VERSION],
340 [AC_CACHE_CHECK([for Berkeley DB version match], [ol_cv_berkeley_db_version], [
342 LIBS="$LTHREAD_LIBS $LIBS"
343 if test $ol_cv_lib_db != yes ; then
344 LIBS="$ol_cv_lib_db $LIBS"
353 #ifndef DB_VERSION_MAJOR
354 # define DB_VERSION_MAJOR 1
357 #define NULL ((void *)0)
361 #if DB_VERSION_MAJOR > 1
363 int major, minor, patch;
365 version = db_version( &major, &minor, &patch );
367 if( major != DB_VERSION_MAJOR || minor < DB_VERSION_MINOR ) {
368 printf("Berkeley DB version mismatch\n"
369 "\theader: %s\n\tlibrary: %s\n",
370 DB_VERSION_STRING, version);
377 [ol_cv_berkeley_db_version=yes],
378 [ol_cv_berkeley_db_version=no],
379 [ol_cv_berkeley_db_version=cross])
384 if test $ol_cv_berkeley_db_version = no ; then
385 AC_MSG_ERROR([Berkeley DB version mismatch])
389 dnl --------------------------------------------------------------------
390 dnl Check if Berkeley DB supports DB_THREAD
391 AC_DEFUN([OL_BERKELEY_DB_THREAD],
392 [AC_CACHE_CHECK([for Berkeley DB thread support], [ol_cv_berkeley_db_thread], [
394 LIBS="$LTHREAD_LIBS $LIBS"
395 if test $ol_cv_lib_db != yes ; then
396 LIBS="$ol_cv_lib_db $LIBS"
406 #define NULL ((void *)0)
411 u_int32_t flags = DB_CREATE |
417 #if DB_VERSION_MAJOR > 2
420 rc = db_env_create( &env, 0 );
422 flags |= DB_INIT_MPOOL;
423 #ifdef DB_MPOOL_PRIVATE
424 flags |= DB_MPOOL_PRIVATE;
428 printf("BerkeleyDB: %s\n", db_strerror(rc) );
432 #if (DB_VERSION_MAJOR > 3) || (DB_VERSION_MINOR >= 1)
433 rc = env->open( env, NULL, flags, 0 );
435 rc = env->open( env, NULL, NULL, flags, 0 );
439 rc = env->close( env, 0 );
443 printf("BerkeleyDB: %s\n", db_strerror(rc) );
449 memset( &env, '\0', sizeof(env) );
451 rc = db_appinit( NULL, NULL, &env, flags );
457 unlink("__db_mpool.share");
458 unlink("__db_lock.share");
463 [ol_cv_berkeley_db_thread=yes],
464 [ol_cv_berkeley_db_thread=no],
465 [ol_cv_berkeley_db_thread=cross])
470 if test $ol_cv_berkeley_db_thread != no ; then
471 AC_DEFINE(HAVE_BERKELEY_DB_THREAD, 1,
472 [define if Berkeley DB has DB_THREAD support])
476 dnl --------------------------------------------------------------------
478 AC_DEFUN([OL_BERKELEY_DB],
479 [ol_cv_berkeley_db=no
480 AC_CHECK_HEADERS(db.h)
481 if test $ac_cv_header_db_h = yes; then
483 if test "$ol_cv_lib_db" != no ; then
484 ol_cv_berkeley_db=yes
485 OL_BERKELEY_DB_VERSION
486 OL_BERKELEY_DB_THREAD
490 dnl --------------------------------------------------------------------
491 dnl Check for version compatility with back-bdb
492 AC_DEFUN([OL_BDB_COMPAT],
493 [AC_CACHE_CHECK([Berkeley DB version for BDB backend], [ol_cv_bdb_compat],[
494 AC_EGREP_CPP(__db_version_compat,[
497 /* this check could be improved */
498 #ifndef DB_VERSION_MAJOR
499 # define DB_VERSION_MAJOR 1
501 #ifndef DB_VERSION_MINOR
502 # define DB_VERSION_MINOR 0
505 /* require 4.2 or later */
506 #if (DB_VERSION_MAJOR >= 4) && (DB_VERSION_MINOR >= 2)
509 ], [ol_cv_bdb_compat=yes], [ol_cv_bdb_compat=no])])
512 dnl --------------------------------------------------------------------
513 dnl Find old Berkeley DB 1.85/1.86
514 AC_DEFUN([OL_BERKELEY_COMPAT_DB],
515 [AC_CHECK_HEADERS(db_185.h db.h)
516 if test $ac_cv_header_db_185_h = yes -o $ac_cv_header_db_h = yes; then
517 AC_CACHE_CHECK([if Berkeley DB header compatibility], [ol_cv_header_db1],[
518 AC_EGREP_CPP(__db_version_1,[
525 /* this check could be improved */
526 #ifndef DB_VERSION_MAJOR
527 # define DB_VERSION_MAJOR 1
530 #if DB_VERSION_MAJOR == 1
533 ], [ol_cv_header_db1=yes], [ol_cv_header_db1=no])])
535 if test $ol_cv_header_db1 = yes ; then
537 if test "$ol_cv_lib_db" != no ; then
538 ol_cv_berkeley_db=yes
544 dnl ====================================================================
545 dnl Check if GDBM library exists
546 dnl Check for gdbm_open in standard libraries or -lgdbm
548 dnl defines ol_cv_lib_gdbm to 'yes' or '-lgdbm' or 'no'
549 dnl 'yes' implies gdbm_open is in $LIBS
552 dnl AC_CHECK_FUNC(gdbm_open)
553 dnl AC_CHECK_LIB(gdbm,gdbm_open)
555 AC_DEFUN([OL_LIB_GDBM],
556 [AC_CACHE_CHECK(for GDBM library, [ol_cv_lib_gdbm],
558 AC_CHECK_FUNC(gdbm_open,[ol_cv_lib_gdbm=yes], [
559 AC_CHECK_LIB(gdbm,gdbm_open,[ol_cv_lib_gdbm=-lgdbm],[ol_cv_lib_gdbm=no])
565 dnl --------------------------------------------------------------------
566 dnl Check if GDBM exists
568 dnl defines ol_cv_gdbm to 'yes' or 'no'
572 dnl AC_CHECK_HEADERS(gdbm.h)
575 [AC_REQUIRE([OL_LIB_GDBM])
576 AC_CHECK_HEADERS(gdbm.h)
577 AC_CACHE_CHECK(for db, [ol_cv_gdbm], [
578 if test $ol_cv_lib_gdbm = no -o $ac_cv_header_gdbm_h = no ; then
584 if test $ol_cv_gdbm = yes ; then
585 AC_DEFINE(HAVE_GDBM,1, [define if GNU DBM is available])
589 dnl ====================================================================
590 dnl Check if MDBM library exists
591 dnl Check for mdbm_open in standard libraries or -lmdbm
593 dnl defines ol_cv_lib_mdbm to 'yes' or '-lmdbm' or 'no'
594 dnl 'yes' implies mdbm_open is in $LIBS
597 dnl AC_CHECK_FUNC(mdbm_set_chain)
598 dnl AC_CHECK_LIB(mdbm,mdbm_set_chain)
600 AC_DEFUN([OL_LIB_MDBM],
601 [AC_CACHE_CHECK(for MDBM library, [ol_cv_lib_mdbm],
603 AC_CHECK_FUNC(mdbm_set_chain,[ol_cv_lib_mdbm=yes], [
604 AC_CHECK_LIB(mdbm,mdbm_set_chain,[ol_cv_lib_mdbm=-lmdbm],[ol_cv_lib_mdbm=no])
610 dnl --------------------------------------------------------------------
611 dnl Check if MDBM exists
613 dnl defines ol_cv_mdbm to 'yes' or 'no'
617 dnl AC_CHECK_HEADERS(mdbm.h)
620 [AC_REQUIRE([OL_LIB_MDBM])
621 AC_CHECK_HEADERS(mdbm.h)
622 AC_CACHE_CHECK(for db, [ol_cv_mdbm], [
623 if test $ol_cv_lib_mdbm = no -o $ac_cv_header_mdbm_h = no ; then
629 if test $ol_cv_mdbm = yes ; then
630 AC_DEFINE(HAVE_MDBM,1, [define if MDBM is available])
634 dnl ====================================================================
635 dnl Check if NDBM library exists
636 dnl Check for dbm_open in standard libraries or -lndbm or -ldbm
638 dnl defines ol_cv_lib_ndbm to 'yes' or '-lndbm' or -ldbm or 'no'
639 dnl 'yes' implies ndbm_open is in $LIBS
642 dnl AC_CHECK_FUNC(dbm_open)
643 dnl AC_CHECK_LIB(ndbm,dbm_open)
644 dnl AC_CHECK_LIB(dbm,dbm_open)
647 dnl should also check SVR4 case: dbm_open() in -lucb but that
648 dnl would requiring dealing with -L/usr/ucblib
650 AC_DEFUN([OL_LIB_NDBM],
651 [AC_CACHE_CHECK(for NDBM library, [ol_cv_lib_ndbm],
653 AC_CHECK_FUNC(dbm_open,[ol_cv_lib_ndbm=yes], [
654 AC_CHECK_LIB(ndbm,dbm_open,[ol_cv_lib_ndbm=-lndbm], [
655 AC_CHECK_LIB(dbm,dbm_open,[ol_cv_lib_ndbm=-ldbm],
656 [ol_cv_lib_ndbm=no])dnl
663 dnl --------------------------------------------------------------------
664 dnl Check if NDBM exists
666 dnl defines ol_cv_ndbm to 'yes' or 'no'
670 dnl AC_CHECK_HEADERS(ndbm.h)
673 dnl Doesn't handle SVR4 case (see above)
676 [AC_REQUIRE([OL_LIB_NDBM])
677 AC_CHECK_HEADERS(ndbm.h)
678 AC_CACHE_CHECK(for db, [ol_cv_ndbm], [
679 if test $ol_cv_lib_ndbm = no -o $ac_cv_header_ndbm_h = no ; then
685 if test $ol_cv_ndbm = yes ; then
686 AC_DEFINE(HAVE_NDBM,1, [define if NDBM is available])
690 dnl ====================================================================
691 dnl Check POSIX Thread version
693 dnl defines ol_cv_pthread_version to 4, 5, 6, 7, 8, 10, depending on the
694 dnl version of the POSIX.4a Draft that is implemented.
695 dnl 10 == POSIX.4a Final == POSIX.1c-1996 for our purposes.
696 dnl Existence of pthread.h should be tested separately.
699 dnl pthread_detach() was dropped in Draft 8, it is present
700 dnl in every other version
701 dnl PTHREAD_CREATE_UNDETACHED is only in Draft 7, it was called
702 dnl PTHREAD_CREATE_JOINABLE after that
703 dnl pthread_attr_create was renamed to pthread_attr_init in Draft 6.
704 dnl Draft 6-10 has _init, Draft 4-5 has _create.
705 dnl pthread_attr_default was dropped in Draft 6, only 4 and 5 have it
706 dnl PTHREAD_MUTEX_INITIALIZER was introduced in Draft 5. It's not
707 dnl interesting to us because we don't try to statically
708 dnl initialize mutexes. 5-10 has it.
710 dnl Draft 9 and 10 are equivalent for our purposes.
712 AC_DEFUN([OL_POSIX_THREAD_VERSION],
713 [AC_CACHE_CHECK([POSIX thread version],[ol_cv_pthread_version],[
715 # include <pthread.h>
717 int i = PTHREAD_CREATE_JOINABLE;
719 AC_EGREP_HEADER(pthread_detach,pthread.h,
720 ol_cv_pthread_version=10, ol_cv_pthread_version=8)],[
721 AC_EGREP_CPP(draft7,[
722 # include <pthread.h>
723 # ifdef PTHREAD_CREATE_UNDETACHED
726 ], ol_cv_pthread_version=7, [
727 AC_EGREP_HEADER(pthread_attr_init,pthread.h,
728 ol_cv_pthread_version=6, [
729 AC_EGREP_CPP(draft5,[
730 # include <pthread.h>
731 #ifdef PTHREAD_MUTEX_INITIALIZER
734 ], ol_cv_pthread_version=5, ol_cv_pthread_version=4) ]) ]) ])
738 dnl --------------------------------------------------------------------
739 AC_DEFUN([OL_PTHREAD_TEST_INCLUDES],
740 [/* pthread test headers */
742 #if HAVE_PTHREADS < 7
746 #define NULL (void*)0
752 return (void *) (p == NULL);
755 AC_DEFUN([OL_PTHREAD_TEST_FUNCTION],[
756 /* pthread test function */
757 #ifndef PTHREAD_CREATE_DETACHED
758 #define PTHREAD_CREATE_DETACHED 1
762 int detach = PTHREAD_CREATE_DETACHED;
764 #if HAVE_PTHREADS > 4
768 status = pthread_attr_init(&attr);
769 if( status ) return status;
771 #if HAVE_PTHREADS < 7
772 status = pthread_attr_setdetachstate(&attr, &detach);
773 if( status < 0 ) status = errno;
775 status = pthread_attr_setdetachstate(&attr, detach);
777 if( status ) return status;
778 status = pthread_create( &t, &attr, task, NULL );
779 #if HAVE_PTHREADS < 7
780 if( status < 0 ) status = errno;
782 if( status ) return status;
784 /* Draft 4 pthreads */
785 status = pthread_create( &t, pthread_attr_default, task, NULL );
786 if( status ) return errno;
788 /* give thread a chance to complete */
789 /* it should remain joinable and hence detachable */
792 status = pthread_detach( &t );
793 if( status ) return errno;
796 #ifdef HAVE_LINUX_THREADS
797 pthread_kill_other_threads_np();
803 AC_DEFUN([OL_PTHREAD_TEST_PROGRAM],
804 [OL_PTHREAD_TEST_INCLUDES
810 OL_PTHREAD_TEST_FUNCTION
813 dnl --------------------------------------------------------------------
814 AC_DEFUN([OL_PTHREAD_TRY], [# Pthread try link: $1 ($2)
815 if test "$ol_link_threads" = no ; then
817 AC_CACHE_CHECK([for pthread link with $1], [$2], [
822 AC_TRY_RUN(OL_PTHREAD_TEST_PROGRAM,
824 [AC_TRY_LINK(OL_PTHREAD_TEST_INCLUDES,OL_PTHREAD_TEST_FUNCTION,
831 if test $$2 = yes ; then
832 ol_link_pthreads="$1"
833 ol_link_threads=posix
838 dnl ====================================================================
839 dnl Check GNU Pth pthread Header
841 dnl defines ol_cv_header linux_threads to 'yes' or 'no'
842 dnl 'no' implies pthreads.h is not LinuxThreads or pthreads.h
843 dnl doesn't exists. Existance of pthread.h should separately
846 AC_DEFUN([OL_HEADER_GNU_PTH_PTHREAD_H], [
847 AC_CACHE_CHECK([for GNU Pth pthread.h],
848 [ol_cv_header_gnu_pth_pthread_h],
849 [AC_EGREP_CPP(__gnu_pth__,
850 [#include <pthread.h>
851 #ifdef _POSIX_THREAD_IS_GNU_PTH
855 [ol_cv_header_gnu_pth_pthread_h=yes],
856 [ol_cv_header_gnu_pth_pthread_h=no])
859 dnl ====================================================================
860 dnl Check for NT Threads
861 AC_DEFUN([OL_NT_THREADS], [
862 AC_CHECK_FUNC(_beginthread)
864 if test $ac_cv_func__beginthread = yes ; then
865 AC_DEFINE(HAVE_NT_THREADS,1,[if you have NT Threads])
869 dnl ====================================================================
870 dnl Check LinuxThreads Header
872 dnl defines ol_cv_header linux_threads to 'yes' or 'no'
873 dnl 'no' implies pthreads.h is not LinuxThreads or pthreads.h
874 dnl doesn't exists. Existance of pthread.h should separately
877 AC_DEFUN([OL_HEADER_LINUX_THREADS], [
878 AC_CACHE_CHECK([for LinuxThreads pthread.h],
879 [ol_cv_header_linux_threads],
880 [AC_EGREP_CPP(pthread_kill_other_threads_np,
881 [#include <pthread.h>],
882 [ol_cv_header_linux_threads=yes],
883 [ol_cv_header_linux_threads=no])
885 if test $ol_cv_header_linux_threads = yes; then
886 AC_DEFINE(HAVE_LINUX_THREADS,1,[if you have LinuxThreads])
889 dnl --------------------------------------------------------------------
890 dnl Check LinuxThreads Implementation
892 dnl defines ol_cv_sys_linux_threads to 'yes' or 'no'
893 dnl 'no' implies pthreads implementation is not LinuxThreads.
895 AC_DEFUN([OL_SYS_LINUX_THREADS], [
896 AC_CHECK_FUNCS(pthread_kill_other_threads_np)
897 AC_CACHE_CHECK([for LinuxThreads implementation],
898 [ol_cv_sys_linux_threads],
899 [ol_cv_sys_linux_threads=$ac_cv_func_pthread_kill_other_threads_np])
902 dnl --------------------------------------------------------------------
903 dnl Check LinuxThreads consistency
904 AC_DEFUN([OL_LINUX_THREADS], [
905 AC_REQUIRE([OL_HEADER_LINUX_THREADS])
906 AC_REQUIRE([OL_SYS_LINUX_THREADS])
907 AC_CACHE_CHECK([for LinuxThreads consistency], [ol_cv_linux_threads], [
908 if test $ol_cv_header_linux_threads = yes -a \
909 $ol_cv_sys_linux_threads = yes; then
910 ol_cv_linux_threads=yes
911 elif test $ol_cv_header_linux_threads = no -a \
912 $ol_cv_sys_linux_threads = no; then
913 ol_cv_linux_threads=no
915 ol_cv_linux_threads=error
920 dnl ====================================================================
921 dnl Check for POSIX Regex
922 AC_DEFUN([OL_POSIX_REGEX], [
923 AC_CACHE_CHECK([for compatible POSIX regex],ol_cv_c_posix_regex,[
925 #include <sys/types.h>
927 static char *pattern, *string;
935 if(regcomp(&re, pattern, 0)) {
939 string = "ALL MATCH";
941 rc = regexec(&re, string, 0, (void*)0, 0);
947 [ol_cv_c_posix_regex=yes],
948 [ol_cv_c_posix_regex=no],
949 [ol_cv_c_posix_regex=cross])])
952 dnl ====================================================================
953 dnl Check if toupper() requires islower() to be called first
954 AC_DEFUN([OL_C_UPPER_LOWER],
955 [AC_CACHE_CHECK([if toupper() requires islower()],ol_cv_c_upper_lower,[
960 if ('C' == toupper('C'))
965 [ol_cv_c_upper_lower=no],
966 [ol_cv_c_upper_lower=yes],
967 [ol_cv_c_upper_lower=safe])])
968 if test $ol_cv_c_upper_lower != no ; then
969 AC_DEFINE(C_UPPER_LOWER,1, [define if toupper() requires islower()])
973 dnl ====================================================================
974 dnl Error string checks
976 dnl Check for declaration of sys_errlist in one of stdio.h and errno.h.
977 dnl Declaration of sys_errlist on BSD4.4 interferes with our declaration.
978 dnl Reported by Keith Bostic.
979 AC_DEFUN([OL_SYS_ERRLIST],
980 [AC_CACHE_CHECK([declaration of sys_errlist],ol_cv_dcl_sys_errlist,[
983 #include <sys/types.h>
988 [char *c = (char *) *sys_errlist],
989 [ol_cv_dcl_sys_errlist=yes
990 ol_cv_have_sys_errlist=yes],
991 [ol_cv_dcl_sys_errlist=no])])
993 # It's possible (for near-UNIX clones) that sys_errlist doesn't exist
994 if test $ol_cv_dcl_sys_errlist = no ; then
995 AC_DEFINE(DECL_SYS_ERRLIST,1,
996 [define if sys_errlist is not declared in stdio.h or errno.h])
998 AC_CACHE_CHECK([existence of sys_errlist],ol_cv_have_sys_errlist,[
999 AC_TRY_LINK([#include <errno.h>],
1000 [char *c = (char *) *sys_errlist],
1001 [ol_cv_have_sys_errlist=yes],
1002 [ol_cv_have_sys_errlist=no])])
1004 if test $ol_cv_have_sys_errlist = yes ; then
1005 AC_DEFINE(HAVE_SYS_ERRLIST,1,
1006 [define if you actually have sys_errlist in your libs])
1009 AC_DEFUN([OL_NONPOSIX_STRERROR_R],
1010 [AC_CACHE_CHECK([non-posix strerror_r],ol_cv_nonposix_strerror_r,[
1011 AC_EGREP_CPP(strerror_r,[#include <string.h>],
1012 ol_decl_strerror_r=yes, ol_decl_strerror_r=no)dnl
1014 if test $ol_decl_strerror_r = yes ; then
1015 AC_TRY_COMPILE([#include <string.h>],
1016 [ /* from autoconf 2.59 */
1018 char x = *strerror_r (0, buf, sizeof buf);
1019 char *p = strerror_r (0, buf, sizeof buf);
1020 ], ol_cv_nonposix_strerror_r=yes, ol_cv_nonposix_strerror_r=no)
1026 strerror_r( 1, buf, sizeof buf );
1027 exit( buf[0] == 0 );
1029 ], ol_cv_nonposix_strerror_r=yes, ol_cv_nonposix_strerror=no)
1032 if test $ol_cv_nonposix_strerror_r = yes ; then
1033 AC_DEFINE(HAVE_NONPOSIX_STRERROR_R,1,
1034 [define if strerror_r returns char* instead of int])
1038 AC_DEFUN([OL_STRERROR],
1039 [OL_SYS_ERRLIST dnl TEMPORARY
1040 AC_CHECK_FUNCS(strerror strerror_r)
1041 ol_cv_func_strerror_r=no
1042 if test "${ac_cv_func_strerror_r}" = yes ; then
1043 OL_NONPOSIX_STRERROR_R
1044 elif test "${ac_cv_func_strerror}" = no ; then
1048 dnl ====================================================================
1049 dnl Early MIPS compilers (used in Ultrix 4.2) don't like
1050 dnl "int x; int *volatile a = &x; *a = 0;"
1051 dnl -- borrowed from PDKSH
1052 AC_DEFUN(OL_C_VOLATILE,
1053 [AC_CACHE_CHECK(if compiler understands volatile, ol_cv_c_volatile,
1054 [AC_TRY_COMPILE([int x, y, z;],
1055 [volatile int a; int * volatile b = x ? &y : &z;
1056 /* Older MIPS compilers (eg., in Ultrix 4.2) don't like *b = 0 */
1057 *b = 0;], ol_cv_c_volatile=yes, ol_cv_c_volatile=no)])
1058 if test $ol_cv_c_volatile = yes; then
1061 AC_DEFINE(volatile,,[define as empty if volatile is not supported])
1065 dnl ====================================================================
1066 dnl Look for fetch(3)
1067 AC_DEFUN([OL_LIB_FETCH],
1069 LIBS="-lfetch -lcom_err $LIBS"
1070 AC_CACHE_CHECK([fetch(3) library],ol_cv_lib_fetch,[
1072 #include <sys/param.h>
1074 #include <fetch.h>],
1075 [struct url *u = fetchParseURL("file:///"); ],
1076 [ol_cv_lib_fetch=yes],
1077 [ol_cv_lib_fetch=no])])
1079 if test $ol_cv_lib_fetch != no ; then
1080 ol_link_fetch="-lfetch -lcom_err"
1081 AC_DEFINE(HAVE_FETCH,1,
1082 [define if you actually have FreeBSD fetch(3)])
1086 dnl ====================================================================
1087 dnl Define sig_atomic_t if not defined in signal.h
1088 AC_DEFUN(OL_TYPE_SIG_ATOMIC_T,
1089 [AC_CACHE_CHECK(for sig_atomic_t, ol_cv_type_sig_atomic_t,
1090 [AC_TRY_COMPILE([#include <signal.h>], [sig_atomic_t atomic;],
1091 ol_cv_type_sig_atomic_t=yes, ol_cv_type_sig_atomic_t=no)])
1092 if test $ol_cv_type_sig_atomic_t = no; then
1093 AC_DEFINE(sig_atomic_t,int,
1094 [define to atomic type if sig_atomic_t is not available])
1098 dnl ====================================================================
1099 dnl Define socklen_t if not defined in sys/types.h or sys/socket.h
1100 AC_DEFUN(OL_TYPE_SOCKLEN_T,
1101 [AC_CACHE_CHECK(for socklen_t, ol_cv_type_socklen_t,
1103 #ifdef HAVE_SYS_TYPES_H
1104 #include <sys/types.h>
1106 #ifdef HAVE_SYS_SOCKET_H
1107 #include <sys/socket.h>
1109 ], [socklen_t len;],
1110 ol_cv_type_socklen_t=yes, ol_cv_type_socklen_t=no)])
1111 if test $ol_cv_type_socklen_t = no; then
1112 AC_DEFINE(socklen_t, int,
1113 [define to int if socklen_t is not available])
1117 dnl ====================================================================
1118 dnl Define inet_aton is available
1119 AC_DEFUN(OL_FUNC_INET_ATON,
1120 [AC_CACHE_CHECK([for inet_aton()], ol_cv_func_inet_aton,
1122 #ifdef HAVE_SYS_TYPES_H
1123 # include <sys/types.h>
1125 #ifdef HAVE_SYS_SOCKET_H
1126 # include <sys/socket.h>
1127 # ifdef HAVE_SYS_SELECT_H
1128 # include <sys/select.h>
1130 # include <netinet/in.h>
1131 # ifdef HAVE_ARPA_INET_H
1132 # include <arpa/inet.h>
1135 ], [struct in_addr in;
1136 int rc = inet_aton( "255.255.255.255", &in );],
1137 ol_cv_func_inet_aton=yes, ol_cv_func_inet_aton=no)])
1138 if test $ol_cv_func_inet_aton != no; then
1139 AC_DEFINE(HAVE_INET_ATON, 1,
1140 [define to you inet_aton(3) is available])
1144 dnl ====================================================================
1145 dnl check no of arguments for ctime_r
1146 AC_DEFUN(OL_FUNC_CTIME_R_NARGS,
1147 [AC_CACHE_CHECK(number of arguments of ctime_r, ol_cv_func_ctime_r_nargs,
1148 [AC_TRY_COMPILE([#include <time.h>],
1149 [time_t ti; char *buffer; ctime_r(&ti,buffer,32);],
1150 ol_cv_func_ctime_r_nargs3=yes,
1151 ol_cv_func_ctime_r_nargs3=no)
1153 AC_TRY_COMPILE([#include <time.h>],
1154 [time_t ti; char *buffer; ctime_r(&ti,buffer);],
1155 ol_cv_func_ctime_r_nargs2=yes,
1156 ol_cv_func_ctime_r_nargs2=no)
1158 if test $ol_cv_func_ctime_r_nargs3 = yes -a \
1159 $ol_cv_func_ctime_r_nargs2 = no ; then
1161 ol_cv_func_ctime_r_nargs=3
1163 elif test $ol_cv_func_ctime_r_nargs3 = no -a \
1164 $ol_cv_func_ctime_r_nargs2 = yes ; then
1166 ol_cv_func_ctime_r_nargs=2
1169 ol_cv_func_ctime_r_nargs=0
1173 if test $ol_cv_func_ctime_r_nargs -gt 1 ; then
1174 AC_DEFINE_UNQUOTED(CTIME_R_NARGS, $ol_cv_func_ctime_r_nargs,
1175 [set to the number of arguments ctime_r() expects])
1179 dnl --------------------------------------------------------------------
1180 dnl check return type of ctime_r()
1181 AC_DEFUN(OL_FUNC_CTIME_R_TYPE,
1182 [AC_CACHE_CHECK(return type of ctime_r, ol_cv_func_ctime_r_type,
1183 [AC_TRY_COMPILE([#include <time.h>],
1184 [extern int (ctime_r)();],
1185 ol_cv_func_ctime_r_type="int", ol_cv_func_ctime_r_type="charp")
1187 if test $ol_cv_func_ctime_r_type = "int" ; then
1188 AC_DEFINE(CTIME_R_RETURNS_INT,1, [define if ctime_r() returns int])
1191 dnl ====================================================================
1192 dnl check no of arguments for gethostbyname_r
1193 AC_DEFUN(OL_FUNC_GETHOSTBYNAME_R_NARGS,
1194 [AC_CACHE_CHECK(number of arguments of gethostbyname_r,
1195 ol_cv_func_gethostbyname_r_nargs,
1196 [AC_TRY_COMPILE([#include <sys/types.h>
1197 #include <sys/socket.h>
1198 #include <netinet/in.h>
1200 #define BUFSIZE (sizeof(struct hostent)+10)],
1201 [struct hostent hent; char buffer[BUFSIZE];
1202 int bufsize=BUFSIZE;int h_errno;
1203 (void)gethostbyname_r("segovia.cs.purdue.edu", &hent,
1204 buffer, bufsize, &h_errno);],
1205 ol_cv_func_gethostbyname_r_nargs5=yes,
1206 ol_cv_func_gethostbyname_r_nargs5=no)
1208 AC_TRY_COMPILE([#include <sys/types.h>
1209 #include <sys/socket.h>
1210 #include <netinet/in.h>
1212 #define BUFSIZE (sizeof(struct hostent)+10)],
1213 [struct hostent hent;struct hostent *rhent;
1214 char buffer[BUFSIZE];
1215 int bufsize=BUFSIZE;int h_errno;
1216 (void)gethostbyname_r("localhost", &hent, buffer, bufsize,
1217 &rhent, &h_errno);],
1218 ol_cv_func_gethostbyname_r_nargs6=yes,
1219 ol_cv_func_gethostbyname_r_nargs6=no)
1221 if test $ol_cv_func_gethostbyname_r_nargs5 = yes -a \
1222 $ol_cv_func_gethostbyname_r_nargs6 = no ; then
1224 ol_cv_func_gethostbyname_r_nargs=5
1226 elif test $ol_cv_func_gethostbyname_r_nargs5 = no -a \
1227 $ol_cv_func_gethostbyname_r_nargs6 = yes ; then
1229 ol_cv_func_gethostbyname_r_nargs=6
1232 ol_cv_func_gethostbyname_r_nargs=0
1235 if test $ol_cv_func_gethostbyname_r_nargs -gt 1 ; then
1236 AC_DEFINE_UNQUOTED(GETHOSTBYNAME_R_NARGS,
1237 $ol_cv_func_gethostbyname_r_nargs,
1238 [set to the number of arguments gethostbyname_r() expects])
1242 dnl check no of arguments for gethostbyaddr_r
1243 AC_DEFUN(OL_FUNC_GETHOSTBYADDR_R_NARGS,
1244 [AC_CACHE_CHECK(number of arguments of gethostbyaddr_r,
1245 [ol_cv_func_gethostbyaddr_r_nargs],
1246 [AC_TRY_COMPILE([#include <sys/types.h>
1247 #include <sys/socket.h>
1248 #include <netinet/in.h>
1250 #define BUFSIZE (sizeof(struct hostent)+10)],
1251 [struct hostent hent; char buffer[BUFSIZE];
1253 size_t alen=sizeof(struct in_addr);
1254 int bufsize=BUFSIZE;int h_errno;
1255 (void)gethostbyaddr_r( (void *)&(add.s_addr),
1256 alen, AF_INET, &hent, buffer, bufsize, &h_errno);],
1257 ol_cv_func_gethostbyaddr_r_nargs7=yes,
1258 ol_cv_func_gethostbyaddr_r_nargs7=no)
1260 AC_TRY_COMPILE([#include <sys/types.h>
1261 #include <sys/socket.h>
1262 #include <netinet/in.h>
1264 #define BUFSIZE (sizeof(struct hostent)+10)],
1265 [struct hostent hent;
1266 struct hostent *rhent; char buffer[BUFSIZE];
1268 size_t alen=sizeof(struct in_addr);
1269 int bufsize=BUFSIZE;int h_errno;
1270 (void)gethostbyaddr_r( (void *)&(add.s_addr),
1271 alen, AF_INET, &hent, buffer, bufsize,
1272 &rhent, &h_errno);],
1273 ol_cv_func_gethostbyaddr_r_nargs8=yes,
1274 ol_cv_func_gethostbyaddr_r_nargs8=no)
1276 if test $ol_cv_func_gethostbyaddr_r_nargs7 = yes -a \
1277 $ol_cv_func_gethostbyaddr_r_nargs8 = no ; then
1279 ol_cv_func_gethostbyaddr_r_nargs=7
1281 elif test $ol_cv_func_gethostbyaddr_r_nargs7 = no -a \
1282 $ol_cv_func_gethostbyaddr_r_nargs8 = yes ; then
1284 ol_cv_func_gethostbyaddr_r_nargs=8
1287 ol_cv_func_gethostbyaddr_r_nargs=0
1290 if test $ol_cv_func_gethostbyaddr_r_nargs -gt 1 ; then
1291 AC_DEFINE_UNQUOTED(GETHOSTBYADDR_R_NARGS,
1292 $ol_cv_func_gethostbyaddr_r_nargs,
1293 [set to the number of arguments gethostbyaddr_r() expects])
1297 dnl --------------------------------------------------------------------
1298 dnl Check for Cyrus SASL version compatility
1299 AC_DEFUN([OL_SASL_COMPAT],
1300 [AC_CACHE_CHECK([Cyrus SASL library version], [ol_cv_sasl_compat],[
1301 AC_EGREP_CPP(__sasl_compat,[
1302 #ifdef HAVE_SASL_SASL_H
1303 #include <sasl/sasl.h>
1308 /* Require 2.1.15+ */
1309 #if SASL_VERSION_MAJOR == 2 && SASL_VERSION_MINOR > 1
1310 char *__sasl_compat = "2.2+ or better okay (we guess)";
1311 #elif SASL_VERSION_MAJOR == 2 && SASL_VERSION_MINOR == 1 \
1312 && SASL_VERSION_STEP >=15
1313 char *__sasl_compat = "2.1.15+ or better okay";
1315 ], [ol_cv_sasl_compat=yes], [ol_cv_sasl_compat=no])])
1317 dnl ====================================================================
1318 dnl check for msg_accrights in msghdr
1319 AC_DEFUN(OL_MSGHDR_MSG_ACCRIGHTS,
1320 [AC_CACHE_CHECK(for msg_accrights in msghdr, ol_cv_msghdr_msg_accrights,
1321 [AC_TRY_COMPILE([#include <sys/socket.h>],
1322 [struct msghdr m; m.msg_accrightslen=0],
1323 ol_cv_msghdr_msg_accrights=yes, ol_cv_msghdr_msg_accrights=no)
1325 if test $ol_cv_msghdr_msg_accrights = "yes" ; then
1326 AC_DEFINE(HAVE_MSGHDR_MSG_ACCRIGHTS,1,
1327 [define if struct msghdr has msg_accrights])