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