]> git.sur5r.net Git - openldap/blob - configure.in
Update to latest devel codes
[openldap] / configure.in
1 dnl $OpenLDAP$
2 dnl
3 dnl Copyright 1998-2000 The OpenLDAP Foundation.  All Rights Reserved.
4 dnl 
5 dnl Redistribution and use in source and binary forms are permitted only
6 dnl as authorized by the OpenLDAP Public License.  A copy of this
7 dnl license is available at http://www.OpenLDAP.org/license.html or
8 dnl in file LICENSE in the top-level directory of the distribution.
9 dnl
10 dnl ----------------------------------------------------------------
11 dnl Redefine AC_INIT_BINSH to provide RCS IDs and copyright notice
12 dnl at top of generated configure script.  Prints simple copyright.
13 define([AC_INIT_BINSH],
14 [[#! /bin/sh
15 # $]OpenLDAP[$
16 # from] translit([$OpenLDAP$], $")] [
17
18 # Copyright 1998-2000 The OpenLDAP Foundation.  All Rights Reserved.
19
20 # Redistribution and use in source and binary forms are permitted only
21 # as authorized by the OpenLDAP Public License.  A copy of this
22 # license is available at http://www.OpenLDAP.org/license.html or
23 # in file LICENSE in the top-level directory of the distribution.
24
25 echo "Copyright 1998-2000 The OpenLDAP Foundation,  All Rights Reserved."
26 echo "Copying restrictions apply, see COPYRIGHT file."
27 ])dnl
28 dnl ----------------------------------------------------------------
29 dnl Disable config.cache!
30 define([AC_CACHE_LOAD], )dnl
31 define([AC_CACHE_SAVE], )dnl
32 dnl ================================================================
33 dnl Configure.in for OpenLDAP
34 AC_INIT(build/version)dnl
35
36 # set unset (borrowed from autoconf 2.14a)
37 if (unset FOO) >/dev/null 2>&1; then
38   ol_unset=unset
39 else
40   ol_unset=false
41 fi
42 # unset CDPATH
43 $ol_unset CDPATH || test "${CDPATH+set}" != set || CDPATH=: && export CDPATH
44
45 AC_CONFIG_AUX_DIR(build)dnl
46
47 OL_VERSION=`cat $ac_aux_dir/version`
48 if test -z "$OL_VERSION"; then
49         AC_MSG_ERROR([could not determine version])
50 fi
51
52 echo "Configuring OpenLDAP $OL_VERSION ..."
53
54 dnl Determine host platform
55 dnl             we try not to use this for much
56 AC_CANONICAL_SYSTEM
57
58 AM_INIT_AUTOMAKE(OpenLDAP,[$OL_VERSION], [no defines])dnl
59 AC_SUBST(PACKAGE)
60 AC_SUBST(VERSION)
61 AC_DEFINE_UNQUOTED(OPENLDAP_PACKAGE,"$PACKAGE",Package)
62 AC_DEFINE_UNQUOTED(OPENLDAP_VERSION,"$VERSION",Version)
63
64 dnl We use autoconf features new to 2.13.
65 dnl aclocal.m4 should be built using aclocal from automake 1.4
66 dnl libtool 1.3.3 should be installed.
67 AC_PREREQ(2.13)dnl Required Autoconf version
68
69 AC_CONFIG_HEADER(include/portable.h include/ldap_features.h include/lber_types.h)dnl
70
71 dnl ================================================================
72 dnl Start Args
73 AC_MSG_CHECKING(configure arguments)
74 AC_PREFIX_DEFAULT(/usr/local)
75
76 top_builddir=`pwd`
77 AC_SUBST(top_builddir)dnl
78
79 dnl ----------------------------------------------------------------
80 dnl --with-subdir
81 ldap_subdir="/openldap"
82
83 AC_ARG_WITH(subdir,
84 [  --with-subdir=DIR change default subdirectory used for installs],
85 [case "$withval" in
86         no) ldap_subdir=""
87                 ;;
88         yes)
89                 ;;
90         /*|\\*)
91                 ldap_subdir="$withval"
92                 ;;
93         *)
94                 ldap_subdir="/$withval"
95                 ;;
96 esac
97 ])dnl
98
99 AC_SUBST(ldap_subdir)dnl
100
101 dnl ----------------------------------------------------------------
102 dnl General "enable" options
103 OL_ARG_ENABLE(debug,[  --enable-debug   enable debugging], yes)dnl
104 OL_ARG_ENABLE(syslog,[  --enable-syslog enable syslog support], auto)dnl
105 OL_ARG_ENABLE(proctitle,[  --enable-proctitle   enable proctitle support], yes)dnl
106 OL_ARG_ENABLE(cache,[  --enable-cache   enable caching], yes)dnl
107 OL_ARG_ENABLE(referrals,[  --enable-referrals   enable V2 Referrals extension], yes)dnl
108 OL_ARG_ENABLE(kbind,[  --enable-kbind   enable V2 Kerberos IV bind], auto)dnl
109 OL_ARG_ENABLE(cldap,[  --enable-cldap   enable connectionless ldap], no)dnl
110 OL_ARG_ENABLE(ipv6,[  --enable-ipv6     enable IPv6 support], auto)dnl
111 OL_ARG_ENABLE(unix,[  --enable-unix             enable UNIX domain socket support], auto)dnl
112 OL_ARG_ENABLE(x_compile,[  --enable-x-compile   enable cross compiling],
113         no, [yes no])dnl
114
115 dnl ----------------------------------------------------------------
116 dnl General "with" options
117 dnl OL_ARG_ENABLE(dmalloc,[  --enable-dmalloc   enable debug malloc support], no)dnl
118
119 OL_ARG_WITH(cyrus_sasl,[  --with-cyrus-sasl     with Cyrus SASL support],
120         auto, [auto yes no] )
121 OL_ARG_WITH(fetch,[  --with-fetch               with fetch URL support],
122         auto, [auto yes no] )
123 OL_ARG_WITH(kerberos,[  --with-kerberos with support],
124         auto, [auto k5 k5only k425 kth k4 afs yes no])
125 OL_ARG_WITH(readline,[  --with-readline with readline support],
126         auto, [auto yes no] )
127 OL_ARG_WITH(threads,[  --with-threads   use threads],
128         auto, [auto nt posix mach pth lwp yes no manual] )
129 OL_ARG_WITH(tls,[  --with-tls           with TLS/SSL support],
130         auto, [auto ssleay openssl yes no] )
131 OL_ARG_WITH(yielding_select,[  --with-yielding-select   with implicitly yielding select],
132         auto, [auto yes no manual] )
133
134 dnl ----------------------------------------------------------------
135 dnl Server options
136 dnl ----------------------------------------------------------------
137
138 dnl ----------------------------------------------------------------
139 dnl SLAPD OPTIONS
140 AC_ARG_WITH(xxslapdoptions,[SLAPD (Standalone LDAP Daemon) Options:])
141 OL_ARG_ENABLE(slapd,[  --enable-slapd   enable building slapd], yes)dnl
142 OL_ARG_ENABLE(cleartext,[    --enable-cleartext enable cleartext passwords], yes)dnl
143 OL_ARG_ENABLE(crypt,[    --enable-crypt enable crypt(3) passwords], auto)dnl
144 OL_ARG_ENABLE(kpasswd,[    --enable-kpasswd     enable kerberos password verification], no)dnl
145 OL_ARG_ENABLE(spasswd,[    --enable-spasswd     enable (Cyrus) SASL password verification], no)dnl
146 OL_ARG_ENABLE(modules,[    --enable-modules     enable dynamic module support], no)dnl
147 OL_ARG_ENABLE(multimaster,[    --enable-multimaster     enable multimaster replication], no)dnl
148 OL_ARG_ENABLE(phonetic,[    --enable-phonetic   enable phonetic/soundex], no)dnl
149 OL_ARG_ENABLE(quipu,[    --enable-quipu build quipu migration tools], no)dnl
150 OL_ARG_ENABLE(rlookups,[    --enable-rlookups   enable reverse lookups], auto)dnl
151 OL_ARG_ENABLE(aci,[    --enable-aci     enable per-object ACIs], no)dnl
152 OL_ARG_ENABLE(wrappers,[    --enable-wrappers   enable tcp wrapper support], no)dnl
153 OL_ARG_ENABLE(dynamic,[    --enable-dynamic     enable linking built binaries with dynamic libs], no)dnl
154
155 dnl SLAPD Backend options
156 OL_ARG_ENABLE(dnssrv,[    --enable-dnssrv       enable dnssrv backend], no)dnl
157 OL_ARG_WITH(dnssrv_module,[      --with-dnssrv-module   module type], static,
158         [static dynamic])
159 OL_ARG_ENABLE(ldap,[    --enable-ldap   enable ldap backend], no)dnl
160 OL_ARG_WITH(ldap_module,[      --with-ldap-module       module type], static,
161         [static dynamic])
162 OL_ARG_ENABLE(ldbm,[    --enable-ldbm   enable ldbm backend], yes)dnl
163 OL_ARG_WITH(ldbm_api,[      --with-ldbm-api     use LDBM API], auto,
164         [auto berkeley bcompat mdbm gdbm])
165 OL_ARG_WITH(ldbm_module,[      --with-ldbm-module       module type], static,
166         [static dynamic])
167 OL_ARG_WITH(ldbm_type,[      --with-ldbm-type   use LDBM type], auto,
168         [auto btree hash])
169 OL_ARG_ENABLE(passwd,[    --enable-passwd       enable passwd backend], no)dnl
170 OL_ARG_WITH(passwd_module,[      --with-passwd-module   module type], static,
171         [static dynamic])
172 OL_ARG_ENABLE(shell,[    --enable-shell enable shell backend], no)dnl
173 OL_ARG_WITH(shell_module,[      --with-shell-module     module type], static,
174         [static dynamic])
175
176 dnl ----------------------------------------------------------------
177 dnl SLURPD OPTIONS
178 AC_ARG_WITH(xxslurpdoptions,[SLURPD (Replication Daemon) Options:])
179 OL_ARG_ENABLE(slurpd,[  --enable-slurpd enable building slurpd], auto)dnl
180
181 dnl ----------------------------------------------------------------
182 AC_ARG_WITH(xxliboptions,[Library Generation & Linking Options])
183 AC_ENABLE_STATIC
184 dnl AC_DISABLE_SHARED
185 AC_ENABLE_SHARED
186
187 dnl ----------------------------------------------------------------
188
189 dnl General "enable" options
190 # validate options
191 if test $ol_enable_slapd = no ; then
192         dnl SLAPD was specificallly disabled
193         if test $ol_enable_dnssrv = yes ; then
194                 AC_MSG_WARN([slapd disabled, ignoring --enable-dnssrv argument])
195         fi
196         if test $ol_enable_ldap = yes ; then
197                 AC_MSG_WARN([slapd disabled, ignoring --enable-ldap argument])
198         fi
199         if test $ol_enable_ldbm = yes ; then
200                 AC_MSG_WARN([slapd disabled, ignoring --enable-ldbm argument])
201         fi
202         if test $ol_enable_passwd = yes ; then
203                 AC_MSG_WARN([slapd disabled, ignoring --enable-passwd argument])
204         fi
205         if test $ol_enable_shell = yes ; then
206                 AC_MSG_WARN([slapd disabled, ignoring --enable-shell argument])
207         fi
208         if test $ol_enable_modules = yes ; then
209                 AC_MSG_WARN([slapd disabled, ignoring --enable-modules argument])
210         fi
211         if test $ol_enable_multimaster = yes ; then
212                 AC_MSG_WARN([slapd disabled, ignoring --enable-multimaster argument])
213         fi
214         if test $ol_enable_wrappers = yes ; then
215                 AC_MSG_WARN([slapd disabled, ignoring --enable-wrappers argument])
216         fi
217         if test $ol_enable_phonetic = yes ; then
218                 AC_MSG_WARN([slapd disabled, ignoring --enable-phonetic argument])
219         fi
220         if test $ol_enable_quipu = yes ; then
221                 AC_MSG_WARN([slapd disabled, ignoring --enable-quipu argument])
222         fi
223         if test $ol_enable_rlookups = yes ; then
224                 AC_MSG_WARN([slapd disabled, ignoring --enable-rlookups argument])
225         fi
226         if test $ol_enable_aci = yes ; then
227                 AC_MSG_WARN([slapd disabled, ignoring --enable-aci argument])
228         fi
229         if test $ol_with_ldbm_api != auto ; then
230                 AC_MSG_WARN([slapd disabled, ignoring --with-ldbm-api argument])
231         fi
232         if test $ol_with_ldbm_type != auto ; then
233                 AC_MSG_WARN([slapd disabled, ignoring --with-ldbm-type argument])
234         fi
235         if test $ol_with_dnssrv_module != static ; then
236                 AC_MSG_WARN([slapd disabled, ignoring --with-dnssrv-module argument])
237         fi
238         if test $ol_with_ldap_module != static ; then
239                 AC_MSG_WARN([slapd disabled, ignoring --with-ldap-module argument])
240         fi
241         if test $ol_with_ldbm_module != static ; then
242                 AC_MSG_WARN([slapd disabled, ignoring --with-ldbm-module argument])
243         fi
244         if test $ol_with_passwd_module != static ; then
245                 AC_MSG_WARN([slapd disabled, ignoring --with-passwd-module argument])
246         fi
247         if test $ol_with_shell_module != static ; then
248                 AC_MSG_WARN([slapd disabled, ignoring --with-shell-module argument])
249         fi
250         if test $ol_enable_slurpd = yes ; then
251                 AC_MSG_ERROR([slurpd requires slapd])
252         fi
253
254         # force settings to no
255         ol_enable_dnssrv=no
256         ol_enable_ldap=no
257         ol_enable_ldbm=no
258         ol_enable_passwd=no
259         ol_enable_shell=no
260
261         ol_enable_modules=no
262         ol_enable_multimaster=no
263         ol_enable_phonetic=no
264         ol_enable_quipu=no
265         ol_enable_rlookups=no
266         ol_enable_aci=no
267         ol_enable_wrappers=no
268         ol_enable_dynamic=no
269
270         ol_with_ldbm_api=no
271         ol_with_ldbm_type=no
272
273         ol_with_dnssrv_module=static
274         ol_with_ldap_module=static
275         ol_with_ldbm_module=static
276         ol_with_passwd_module=static
277         ol_with_shell_module=static
278
279         ol_enable_slurpd=no
280
281 elif test $ol_enable_ldbm = no ; then
282         dnl SLAPD without LDBM
283
284         if test $ol_with_ldbm_api != auto ; then
285                 AC_MSG_WARN([LDBM disabled, ignoring --with-ldbm-api argument])
286         fi
287
288         if test $ol_with_ldbm_type != auto ; then
289                 AC_MSG_WARN([LDBM disabled, ignoring --with-ldbm-type argument])
290         fi
291
292         if test $ol_with_ldbm_module != static ; then
293                 AC_MSG_WARN([LDBM disabled, ignoring --with-ldbm-module argument])
294         fi
295
296         if test $ol_enable_modules != yes -a \
297                 $ol_enable_dnssrv = no -a \
298                 $ol_enable_ldap = no -a \
299                 $ol_enable_passwd = no -a \
300                 $ol_enable_shell = no ; then
301                 AC_MSG_ERROR([slapd requires a backend])
302         fi
303
304         ol_with_ldbm_api=no
305         ol_with_ldbm_type=no
306         ol_with_ldbm_module=static
307
308 else
309         dnl SLAPD with LDBM
310         if test $ol_with_ldbm_api = gdbm -a \
311                 $ol_with_ldbm_type = btree ; then
312                 AC_MSG_ERROR([GDBM only supports LDBM type hash])
313         fi
314         if test $ol_with_ldbm_api = mdbm -a \
315                 $ol_with_ldbm_type = btree ; then
316                 AC_MSG_ERROR([MDBM only supports LDBM type hash])
317         fi
318         if test $ol_with_ldbm_api = ndbm -a \
319                 $ol_with_ldbm_type = btree ; then
320                 AC_MSG_ERROR([NDBM only supports LDBM type hash])
321         fi
322 fi
323
324 if test $ol_enable_slurpd = yes ; then
325         dnl SLURPD was specifically enabled
326         if test $ol_with_threads = no ; then
327                 AC_MSG_ERROR([slurpd requires threads])
328         fi
329 fi
330
331 if test $ol_enable_kbind = yes -o $ol_enable_kpasswd = yes ; then
332         if test $ol_with_kerberos = no ; then
333                 AC_MSG_ERROR([options require --with-kerberos])
334         fi
335 elif test $ol_enable_kbind = no -o $ol_enable_kpasswd = no ; then
336         if test $ol_with_kerberos != auto ; then
337                 AC_MSG_WARN([Kerberos detection enabled unnecessarily]);
338         else
339                 ol_with_kerberos=no
340         fi
341 fi
342
343 if test $ol_enable_spasswd = yes ; then
344         if test $ol_with_cyrus_sasl = no ; then
345                 AC_MSG_ERROR([options require --with-cyrus-sasl])
346         fi
347         ol_link_spasswd=yes
348 fi
349
350 AC_MSG_RESULT(done)
351
352 dnl ----------------------------------------------------------------
353 dnl Initialize vars
354 LDAP_LIBS=
355 LDIF_LIBS=
356 LDBM_LIBS=
357 LTHREAD_LIBS=
358 LUTIL_LIBS=
359
360 QUIPU_LIBS=
361 SLAPD_LIBS=
362 SLURPD_LIBS=
363
364 BUILD_SLAPD=no
365 BUILD_SLURPD=no
366
367 BUILD_QUIPU=no
368 BUILD_THREAD=no
369
370 BUILD_DNSSRV=no
371 BUILD_LDAP=no
372 BUILD_LDBM=no
373 BUILD_PASSWD=no
374 BUILD_SHELL=no
375
376 BUILD_DNSSRV_DYNAMIC=static
377 BUILD_LDAP_DYNAMIC=static
378 BUILD_LDBM_DYNAMIC=static
379 BUILD_PASSWD_DYNAMIC=static
380 BUILD_SHELL_DYNAMIC=static
381
382 SLAPD_MODULES_LDFLAGS=
383 SLAPD_MODULES_CPPFLAGS=
384 SLAPD_MODULES_LIST=
385
386 KRB4_LIBS=
387 KRB5_LIBS=
388 READLINE_LIBS=
389 SASL_LIBS=
390 TERMCAP_LIBS=
391 TLS_LIBS=
392 MODULES_LIBS=
393 AUTH_LIBS=
394
395 dnl ================================================================
396 dnl Checks for programs
397
398 dnl AC_PROG_INSTALL
399
400 AC_DEFINE(HAVE_MKVERSION, 1, [define this if you have mkversion])
401
402 dnl ----------------------------------------------------------------
403 dnl
404 dnl Determine which C translator to use
405 dnl
406
407 dnl AIX Thread requires we use cc_r or xlc_r.
408 dnl But only do this IF AIX and CC is not set
409 dnl and threads are auto|yes|posix.
410 dnl
411 dnl If we find cc_r|xlc_r, force pthreads and assume
412 dnl             pthread_create is in $LIBS (ie: don't bring in
413 dnl             any additional thread libraries)
414 dnl If we do not find cc_r|xlc_r, disable threads
415
416 ol_aix_threads=no
417 case "$target" in
418 *-*-aix*) dnl all AIX is not a good idea.
419         if test -z "$CC" ; then
420                 case "$ol_with_threads" in
421                 auto | yes |  posix) ol_aix_threads=yes ;;
422                 esac
423         fi
424 ;;
425 esac
426
427 if test $ol_aix_threads = yes ; then
428         if test -z "${CC}" ; then
429                 AC_CHECK_PROGS(CC,cc_r xlc_r cc)
430
431                 if test "$CC" = cc ; then
432                         dnl no CC! don't allow --with-threads
433                         if test $ol_with_threads != auto ; then
434                                 AC_MSG_ERROR([--with-threads requires cc_r (or other suitable compiler) on AIX])
435                         else
436                                 AC_MSG_WARN([disabling threads, no cc_r on AIX])
437                         fi
438                         ol_with_threads=no
439                 fi
440         fi
441
442         if test "${CC}" = "cc_r" -o "${CC}" = "xlc_r" ; then
443                 ol_with_threads=posix
444                 ol_cv_pthread_create=yes
445         fi
446 fi
447
448 if test -z "${CC}"; then
449         AC_CHECK_PROGS(CC,cc)
450 fi
451
452 dnl The default CFLAGS is empty NOT whatever AC_PROG_CC sets.
453 dnl (for now, let autoconf sort this out)
454 dnl CFLAGS=${CFLAGS-""}
455
456 AC_LIBTOOL_WIN32_DLL
457 AC_LIBTOOL_DLOPEN
458 AC_PROG_LIBTOOL
459
460 AC_PROG_AWK
461 OL_PROG_LN_H
462 AC_PROG_LN_S
463
464 if test "$LN_H" = "cp" -a "$LN_S" = "ln"; then
465         LN_S="$LN_H"
466 fi
467
468 AC_PATH_PROG(SENDMAIL, sendmail, /usr/lib/sendmail,
469         $PATH:/usr/libexec:/usr/lib:/usr/sbin:/usr/etc:/etc)
470 AC_PATH_PROG(EDITOR, vi, /usr/ucb/vi, $PATH:/usr/ucb)
471 AC_PATH_PROG(FINGER, finger, /usr/ucb/finger, $PATH:/usr/ucb)
472
473 AC_PROG_CPP
474
475 dnl ----------------------------------------------------------------
476 dnl Cross compiling checks
477 if test $cross_compiling = yes -a $ol_enable_x_compile = yes; then
478         AC_MSG_WARN([cross compiling....  some functionality will be removed.])
479
480 elif test $cross_compiling = no -a $ol_enable_x_compile = yes; then
481         AC_MSG_WARN([programs compiled here do run here...])
482         AC_MSG_ERROR([  if not cross compiling, use --disable-x-compile.])
483
484 elif test $cross_compiling = yes -a $ol_enable_x_compile = no; then
485         AC_MSG_WARN([programs compiled here do not run here...])
486         AC_MSG_ERROR([  if cross compiling,  add --enable-x-compile.])
487 fi
488
489 dnl ----------------------------------------------------------------
490 dnl Checks for UNIX Variants
491 AC_AIX
492 AC_ISC_POSIX
493 AC_MINIX
494
495 dnl ----------------------------------------------------------------
496 dnl Checks for system services
497 AC_CYGWIN
498 AC_MINGW32
499 AC_EXEEXT
500 AC_OBJEXT
501
502 AC_DEFINE_UNQUOTED( EXEEXT, "${EXEEXT}", [defined to be the EXE extension])
503
504 dnl ----------------------------------------------------------------
505 dnl BeOS requires -lbe -lroot -lnet
506 AC_CHECK_LIB(be, be_app, [LIBS="$LIBS -lbe -lroot -lnet"], :, [-lroot -lnet])
507
508 dnl ----------------------------------------------------------------
509 dnl OpenLDAP requires STDC features
510 AM_PROG_CC_STDC
511 if test "X${am_cv_prog_cc_stdc}" = "Xno" ; then
512         AC_MSG_ERROR([OpenLDAP requires compiler to support STDC constructs.])
513 fi
514
515 dnl ----------------------------------------------------------------
516 dnl Check cc depend flags
517 OL_MKDEPEND
518 if test "${ol_cv_mkdep}" = no ; then
519         # this will soon become an error
520         AC_MSG_WARN([do not know how to generate dependencies])
521 fi
522
523 dnl ----------------------------------------------------------------
524 dnl Check for AIX security library
525 AC_CHECK_LIB(s, afopen, [
526         AUTH_LIBS=-ls
527         AC_DEFINE(HAVE_AIX_SECURITY,1,[define if you have AIX security lib])
528 ])
529
530
531 dnl ----------------------------------------------------------------
532 dnl PF_INET6 support requires getaddrinfo
533 dnl PF_UNIX may use getaddrinfo in available
534 AC_CHECK_FUNCS( getaddrinfo )
535
536 if test $ac_cv_func_getaddrinfo = no ; then
537         if test $ol_enable_ipv6 = yes ; then
538                 AC_MSG_ERROR([IPv6 support requires getaddrinfo()])
539         fi
540         ol_enable_ipv6=no
541 fi
542
543 if test $ol_enable_unix != no ; then
544         AC_CHECK_HEADERS( sys/un.h )
545
546         if test $ol_enable_unix = auto ; then
547                 ol_enable_unix=$ac_cv_header_sys_un_h
548         elif test $ac_cv_header_sys_un_h = no ; then
549                 AC_MSG_ERROR([UNIX domain support requires sys/un.h])
550         fi
551 fi
552
553 dnl ----------------------------------------------------------------
554 dnl Check for module support
555 ol_link_modules=no
556 if test $ol_enable_modules != no ; then
557         AC_CHECK_HEADERS(ltdl.h)
558
559         if test $ac_cv_header_ltdl_h = no ; then
560                 AC_MSG_ERROR([could not locate libtool ltdl.h])
561         fi
562
563         AC_CHECK_LIB(ltdl, lt_dlinit, [
564             MODULES_LIBS=-lltdl
565             AC_DEFINE(HAVE_LIBLTDL,1,[define if you have libtool -ltdl])
566         ])
567
568         if test "$ac_cv_lib_ltdl_lt_dlinit" = no ; then
569                 AC_MSG_ERROR([could not locate libtool -lltdl])
570         fi
571         ol_link_modules=yes
572 else
573         ol_with_dnssrv_module=static
574         ol_with_ldap_module=static
575         ol_with_ldbm_module=static
576         ol_with_passwd_module=static
577         ol_with_shell_module=static
578 fi
579
580 dnl ----------------------------------------------------------------
581 dnl Checks for header files.
582 OL_HEADER_STDC
583
584 if test $ol_cv_header_stdc != yes; then
585         AC_MSG_WARN([could not locate Standard C compliant headers])
586 fi
587
588 AC_HEADER_DIRENT
589 AC_HEADER_SYS_WAIT
590 AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
591 if test $am_cv_sys_posix_termios = yes ; then
592         AC_DEFINE(HAVE_POSIX_TERMIOS,1,
593                 [define if you have POSIX termios])
594 fi
595
596 AC_CHECK_HEADERS(       \
597         arpa/inet.h             \
598         arpa/nameser.h  \
599         assert.h                \
600         conio.h                 \
601         crypt.h                 \
602         direct.h                \
603         errno.h                 \
604         fcntl.h                 \
605         filio.h                 \
606         getopt.h                \
607         grp.h                   \
608         io.h                    \
609         libutil.h               \
610         limits.h                \
611         locale.h                \
612         netinet/tcp.h   \
613         malloc.h                \
614         memory.h                \
615         psap.h                  \
616         pwd.h                   \
617         process.h               \
618         resolv.h                \
619         sgtty.h                 \
620         shadow.h                \
621         stddef.h                \
622         string.h                \
623         strings.h               \
624         sysexits.h              \
625         sys/file.h              \
626         sys/filio.h             \
627         sys/errno.h             \
628         sys/ioctl.h             \
629         sys/param.h             \
630         sys/resource.h  \
631         sys/select.h    \
632         sys/socket.h    \
633         sys/syslog.h    \
634         sys/time.h              \
635         sys/types.h             \
636         syslog.h                \
637         termios.h               \
638         unistd.h                \
639         winsock.h               \
640 )
641
642
643 dnl ----------------------------------------------------------------
644 dnl Checks for libraries
645
646 dnl HP-UX requires -lV3
647 AC_CHECK_LIB(V3, sigset)
648
649 dnl Gotta check for winsock manually
650 if test $ac_cv_header_winsock_h = yes; then
651         AC_CACHE_CHECK([for winsock], [ol_cv_winsock], 
652         AC_TRY_LINK([#include <winsock.h>],[
653                         socket(0,0,0);
654                         select(0,NULL,NULL,NULL,NULL);
655                         closesocket(0);
656                         gethostname(NULL,0);
657         ],[ol_cv_winsock=yes],[ol_cv_winsock=no])])
658
659         if test $ol_cv_winsock = yes ; then
660                 AC_DEFINE(HAVE_WINSOCK,1,[define if you have winsock])
661                 ac_cv_func_socket=yes
662                 ac_cv_func_select=yes
663                 ac_cv_func_closesocket=yes
664                 ac_cv_func_gethostname=yes
665         fi
666 fi
667
668 dnl Find socket()
669 dnl Likely combinations:
670 dnl             -lsocket [ -lnsl_s | -lnsl ]
671 dnl             -linet
672
673 AC_CHECK_FUNC(socket, :, [      
674 dnl hopefully we won't include too many libraries
675         AC_CHECK_LIB(socket, main)
676         AC_CHECK_LIB(net, main)
677         AC_CHECK_LIB(nsl_s, main)
678         AC_CHECK_LIB(nsl, main)
679         AC_CHECK_LIB(inet, socket)
680         AC_CHECK_LIB(gen, main)
681 ])
682
683 dnl require select
684 AC_CHECK_FUNC(select, :, AC_MSG_ERROR([select() required.]))
685
686 if test "${ac_cv_header_winsock_h}" != yes; then
687     dnl Select arg types
688     dnl (if this detection becomes permenent, it and the select() detection
689     dnl should be done before the yielding select test) 
690     AC_FUNC_SELECT_ARGTYPES
691 fi
692
693 dnl check to see if system call automatically restart
694 dnl AC_SYS_RESTARTABLE_SYSCALLS
695
696 dnl ----------------------------------------------------------------
697 dnl require POSIX regex
698 AC_CHECK_HEADERS( regex.h )
699 if test "$ac_cv_header_regex_h" != yes ; then
700         AC_MSG_ERROR([POSIX regex.h required.])
701 fi
702 AC_CHECK_FUNC(regfree, :, AC_MSG_ERROR([POSIX regex required.]))
703
704 OL_POSIX_REGEX
705 if test "$ol_cv_c_posix_regex" = no ; then
706         AC_MSG_ERROR([broken POSIX regex!])
707 fi
708
709 dnl ----------------------------------------------------------------
710 dnl Check for resolver routines
711 ol_link_dnssrv=no
712 AC_CHECK_FUNC(res_query,:)
713 if test $ac_cv_func_res_query = no ; then 
714         AC_CHECK_LIB(bind, res_query)
715         ac_cv_func_res_query=$ac_cv_lib_bind_res_query
716 fi
717
718 if test $ac_cv_func_res_query = no ; then 
719         AC_CHECK_LIB(bind, __res_query)
720         ac_cv_func_res_query=$ac_cv_lib_bind___res_query
721 fi
722
723 if test $ac_cv_func_res_query = no ; then 
724         AC_CHECK_LIB(resolv, res_query)
725         ac_cv_func_res_query=$ac_cv_lib_resolv_res_query
726 fi
727
728 if test "$ac_cv_func_res_query" = yes ; then
729         AC_DEFINE(HAVE_RES_QUERY,1,
730                 [define if you have res_query()])
731
732         if test $ol_enable_dnssrv != no ; then
733                 ol_link_dnssrv=yes
734         fi
735 fi
736
737 if test "$ol_enable_dnssrv" = yes -a "$ol_link_dnssrv" = no ; then
738         AC_MSG_ERROR([DNSSRV requires res_query()])
739 fi
740
741 dnl ----------------------------------------------------------------
742 dnl QUIPU
743 if test $ol_enable_quipu != no ; then
744         AC_CHECK_HEADERS(quipu/commonarg.h)
745
746         if test $ac_cv_header_quipu_commonarg_h = yes ; then
747                 BUILD_QUIPU=yes
748         elif test $ol_enable_quipu = auto ; then
749                 AC_MSG_WARN([no quipu for --enable-quipu=auto, disabling])
750         else
751                 AC_MSG_ERROR(no quipu for --enable-quipu=$ol_enable_quipu)
752         fi
753 fi
754
755 dnl ----------------------------------------------------------------
756 dnl Kerberos
757 ol_link_kbind=no
758 ol_link_kpasswd=no
759 ol_link_krb5=no
760 ol_link_krb4=no
761
762 if test $ol_with_kerberos = auto -o $ol_with_kerberos = k5 \
763         -o $ol_with_kerberos = k5only -o $ol_with_kerberos = k425 ; then
764
765         AC_CHECK_HEADERS(krb5.h)
766
767         if test $ac_cv_header_krb5_h = yes ; then
768                 dnl lazy check for Heimdal Kerberos
769                 AC_CHECK_HEADERS(heim_err.h)
770                 if test $ac_cv_header_heim_err_h = yes ; then
771                         krb5_impl=heimdal
772                 else
773                         krb5_impl=mit
774                 fi
775
776                 if test $krb5_impl = mit; then
777                         AC_CHECK_LIB(krb5, main,
778                                 [have_krb5=yes
779                                 KRB5_LIBS="-lkrb5 -lcrypto -lcom_err"],
780                                 [have_krb5=no],
781                                 [-lcrypto -lcom_err])
782
783                 elif test $krb5_impl = heimdal; then
784                         AC_CHECK_LIB(krb5, main,
785                                 [have_krb5=yes
786                                 KRB5_LIBS="-lkrb5 -ldes -lasn1 -lroken -lcom_err"],
787                                 [have_krb5=no],
788                                 [-ldes -lasn1 -lroken -lcom_err])
789
790                         AC_DEFINE(HAVE_HEIMDAL_KERBEROS, 1,
791                                 [define if you have HEIMDAL Kerberos])
792                 else
793                         have_krb5=no
794                         AC_MSG_WARN([Unrecongized Kerberos5 Implementation])
795                 fi
796
797                 if test $have_krb5 = yes ; then
798                         ol_link_krb5=yes
799
800                         AC_DEFINE(HAVE_KRB5, 1,
801                                 [define if you have Kerberos V])
802
803                         if test $ol_enable_kpasswd != no ; then
804                                 ol_link_kpasswd=yes;
805                         fi
806
807                         if test $ol_with_kerberos = k5only ; then
808                                 ol_with_kerberos=found
809                         fi
810
811                 elif test $ol_with_kerberos != auto ; then
812                         AC_MSG_ERROR([Required Kerberos 5 support not available])
813                 fi
814
815         fi
816 fi
817
818 if test $ol_link_krb5 = yes -a \
819         \( $ol_with_kerberos = auto -o $ol_with_kerberos = k425 \) ; then
820
821         AC_CHECK_HEADERS(kerberosIV/krb.h kerberosIV/des.h)
822
823         if test $ac_cv_header_kerberosIV_krb_h = yes ; then
824                 if test $krb5_impl = mit; then
825                         AC_CHECK_LIB(krb4, main, [have_k425=yes
826                                 KRB4_LIBS="-lkrb4 -ldes425"], [have_k425=no],
827                                 [-ldes425 -lkrb5 -lcrypto -lcom_err])
828
829                 elif test $krb5_impl = heimdal; then
830                         AC_CHECK_LIB(krb4, main, [have_k425=yes
831                                 KRB4_LIBS="-lkrb4"], [have_k425=no],
832                                 [-lkrb5 -ldes -lasn1 -lroken -lcom_err])
833
834                 else
835                         have_425=no
836                         AC_MSG_WARN([Unrecongized Kerberos5 Implementation])
837                 fi
838
839                 if test $have_k425 = yes ; then
840                         ol_with_kerberos=found
841                         ol_link_krb4=yes
842
843                         AC_DEFINE(HAVE_KRB425, 1,
844                                 [define if you have Kerberos V with IV support])
845                         AC_DEFINE(HAVE_KRB4, 1,
846                                 [define if you have Kerberos IV])
847
848                         AC_CACHE_CHECK([for des_debug in Kerberos libraries],
849                                 [ol_cv_var_des_debug], [
850                                 dnl save the flags
851                                 save_LIBS="$LIBS"
852                                 LIBS="$KRB4_LIBS $KRB5_LIBS $LIBS"
853                                 AC_TRY_LINK([
854 #include <kerberosIV/krb.h>
855 #include <kerberosIV/des.h>
856 extern int des_debug;
857 ],[
858 des_debug = 1;
859 ],                              ol_cv_var_des_debug=yes, ol_cv_var_des_debug=no)
860                                 dnl restore the LIBS
861                                 LIBS="$save_LIBS"
862                         ])
863
864                         if test $ol_cv_var_des_debug = yes ; then
865                                 AC_DEFINE(HAVE_DES_DEBUG,1,
866                                         [define if you have Kerberos des_debug])
867                         fi
868
869                         LIBS="$save_LIBS"
870                 fi
871         fi
872 fi
873
874 if test $ol_link_krb5 = yes ; then
875         ol_with_kerberos=found
876 fi
877
878 if test $ol_with_kerberos = auto -o $ol_with_kerberos = k4 \
879         -o $ol_with_kerberos = kth ; then
880
881         AC_CHECK_HEADERS(krb.h des.h krb-archaeology.h )
882
883         if test $ac_cv_header_krb_h = yes ; then
884                 AC_CHECK_LIB(krb, main, [have_k4=yes], [have_k4=no], [-ldes])
885
886                 if test $have_k4 = yes ; then
887                         ol_with_kerberos=found
888                         ol_link_krb4=yes
889
890                         AC_DEFINE(HAVE_KRB4, 1,
891                                 [define if you have Kerberos IV])
892
893                         KRB4_LIBS="-lkrb -ldes"
894
895                         if test $ac_cv_header_krb_archaeology_h = yes ; then
896                                 AC_DEFINE(HAVE_KTH_KERBEROS, 1,
897                                         [define if you have Kth Kerberos])
898                         fi
899                 fi
900         fi
901 fi
902
903 if test $ol_link_krb4 = yes -a $ol_enable_kpasswd != no ; then
904         ol_link_kpasswd=yes;
905 fi
906
907 if test $ol_link_krb4 = yes -o $ol_link_krb5 = yes ; then
908         AC_DEFINE(HAVE_KERBEROS, 1, [define if you have Kerberos])
909
910 elif test $ol_with_kerberos != auto -a $ol_with_kerberos != no ; then
911         AC_MSG_ERROR([Kerberos detection failed.])
912 fi
913
914 dnl ----------------------------------------------------------------
915 dnl TLS/SSL
916 ol_link_tls=no
917 if test $ol_with_tls != no ; then
918         
919         AC_CHECK_HEADERS(openssl/ssl.h ssl.h)
920         
921         if test $ac_cv_header_openssl_ssl_h = yes -o $ac_cv_header_ssl_h = yes ; then
922                 AC_CHECK_LIB(ssl, SSLeay_add_ssl_algorithms, 
923                         [have_ssleay=yes
924                         need_rsaref=no],
925                         [have_ssleay=no],
926                         [-lcrypto])
927                         
928                 if test $have_ssleay = no ; then
929                         AC_CHECK_LIB(ssl, SSL_library_init,
930                                 [have_ssleay=yes
931                                 need_rsaref=no], [have_ssleay=no],
932                                 [-lcrypto])
933                 fi
934
935                 if test $have_ssleay = no ; then
936                         AC_CHECK_LIB(ssl, ssl3_accept, 
937                                 [have_ssleay=yes
938                                 need_rsaref=yes], [have_ssleay=no],
939                                 [-lcrypto -lRSAglue -lrsaref])
940                 fi
941
942                 if test $have_ssleay = yes ; then
943                         ol_with_tls=found
944                         ol_link_tls=yes
945
946                         AC_DEFINE(HAVE_SSLEAY, 1, 
947                                 [define if you have SSLeay or OpenSSL])
948
949                         if test $need_rsaref = yes; then
950                                 AC_DEFINE(HAVE_RSAREF, 1, 
951                                         [define if you have RSAref])
952
953                                 TLS_LIBS="-lssl -lcrypto -lRSAglue -lrsaref"
954                         else
955                                 TLS_LIBS="-lssl -lcrypto"
956                         fi
957                 fi
958         fi
959 fi
960
961 if test $ol_link_tls = yes ; then
962         AC_DEFINE(HAVE_TLS, 1, [define if you have TLS])
963 fi      
964
965 dnl ----------------------------------------------------------------
966 dnl Tests for reentrant functions necessary to build a
967 dnl thread_safe -lldap.
968 AC_CHECK_FUNCS(         \
969         ctime_r                 \
970         gethostbyname_r gethostbyaddr_r \
971 )
972
973 if test "$ac_cv_func_ctime_r" = no ; then
974         ol_cv_func_ctime_r_nargs=0
975 else
976         OL_FUNC_CTIME_R_NARGS
977 dnl     OL_FUNC_CTIME_R_TYPE
978 fi
979
980 if test "$ac_cv_func_gethostbyname_r" = yes ; then
981         OL_FUNC_GETHOSTBYNAME_R_NARGS
982 else
983         ol_cv_func_gethostbyname_r_nargs=0
984 fi
985  
986 if test "$ac_cv_func_gethostbyaddr_r" = yes ; then
987         OL_FUNC_GETHOSTBYADDR_R_NARGS
988 else
989         ol_cv_func_gethostbyaddr_r_nargs=0
990 fi
991
992 if test "$ac_cv_func_ctime_r" = yes \
993         -a "$ol_cv_func_ctime_r_nargs" -ge 2 \
994         -a "$ol_cv_func_ctime_r_nargs" -le 3 \
995         -a "$ac_cv_func_gethostbyname_r" = yes \
996         -a "$ol_cv_func_gethostbyname_r_nargs" -ge 5 \
997         -a "$ol_cv_func_gethostbyname_r_nargs" -le 6 \
998         -a "$ac_cv_func_gethostbyaddr_r" = yes \
999         -a "$ol_cv_func_gethostbyaddr_r_nargs" -ge 5 \
1000         -a "$ol_cv_func_gethostbyaddr_r_nargs" -le 6 \
1001         ; then
1002  
1003         AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_REENTRANT,1)
1004 fi
1005
1006 dnl ----------------------------------------------------------------
1007 dnl Threads?
1008 ol_link_threads=no
1009
1010 if test $ol_with_threads = auto -o $ol_with_threads = yes \
1011         -o $ol_with_threads = nt ; then
1012
1013         OL_NT_THREADS
1014
1015         if test "$ol_cv_nt_threads" = yes ; then
1016         ol_link_threads=nt
1017         ol_with_threads=found
1018         ol_with_yielding_select=yes
1019
1020                 AC_DEFINE(HAVE_NT_SERVICE_MANAGER,1,[if you have NT Service Manager])
1021                 AC_DEFINE(HAVE_NT_EVENT_LOG,1,[if you have NT Event Log])
1022         fi
1023
1024         if test $ol_with_threads = nt ; then
1025                 AC_MSG_ERROR([could not locate NT Threads])
1026         fi
1027 fi
1028
1029 if test $ol_with_threads = auto -o $ol_with_threads = yes \
1030         -o $ol_with_threads = posix ; then
1031
1032         AC_CHECK_HEADERS(pthread.h)
1033
1034         if test $ac_cv_header_pthread_h = yes ; then
1035                 OL_POSIX_THREAD_VERSION
1036
1037                 if test $ol_cv_pthread_version = final ; then
1038                         AC_DEFINE(HAVE_PTHREADS_FINAL,1,
1039                                 [define if pthreads API compatible with final spec])
1040                 elif test $ol_cv_pthread_version = draft4 ; then
1041                         AC_DEFINE(HAVE_PTHREADS_D4,1,
1042                                 [define if pthreads API compatible with draft4 spec])
1043                 else
1044                         AC_MSG_ERROR([unknown pthread version])
1045                 fi
1046
1047                 # consider threads found
1048                 ol_with_threads=found
1049
1050                 OL_HEADER_LINUX_THREADS
1051                 OL_HEADER_GNU_PTH_PTHREAD_H
1052
1053                 if test $ol_cv_header_gnu_pth_pthread_h = no ; then
1054                         AC_CHECK_HEADERS(sched.h)
1055                 fi
1056
1057                 dnl Now the hard part, how to link?
1058                 dnl
1059                 dnl currently supported checks:
1060                 dnl
1061                 dnl Check for no flags 
1062                 dnl     pthread_create() in $LIBS
1063                 dnl
1064                 dnl Check special pthread (final) flags
1065                 dnl     [skipped] pthread_create() with -mt (Solaris) [disabled]
1066                 dnl     pthread_create() with -kthread (FreeBSD)
1067                 dnl     pthread_create() with -pthread (FreeBSD/Digital Unix)
1068                 dnl     pthread_create() with -pthreads (?)
1069                 dnl     pthread_create() with -mthreads (AIX)
1070                 dnl     pthread_create() with -thread (?)
1071                 dnl
1072                 dnl Check pthread (final) libraries
1073                 dnl     pthread_mutex_unlock() in -lpthread -lmach -lexc -lc_r (OSF/1)
1074                 dnl     pthread_mutex_lock() in -lpthread -lmach -lexc (OSF/1)
1075                 dnl     [skipped] pthread_mutex_trylock() in -lpthread -lexc (OSF/1)
1076                 dnl     pthread_join() -Wl,-woff,85 -lpthread (IRIX)
1077                 dnl     pthread_create() in -lpthread (many)
1078                 dnl     pthread_create() in -lc_r (FreeBSD)
1079                 dnl
1080                 dnl Check pthread (draft4) flags (depreciated)
1081                 dnl     pthread_create() with -threads (OSF/1)
1082                 dnl
1083                 dnl Check pthread (draft4) libraries (depreciated)
1084                 dnl     pthread_mutex_unlock() in -lpthreads -lmach -lexc -lc_r (OSF/1)
1085                 dnl     pthread_mutex_lock() in -lpthreads -lmach -lexc (OSF/1)
1086                 dnl     pthread_mutex_trylock() in -lpthreads -lexc (OSF/1)
1087                 dnl     pthread_create() in -lpthreads (many)
1088                 dnl
1089
1090                 dnl pthread_create in $LIBS
1091                 AC_CACHE_CHECK([for pthread_create in default libraries],
1092                         ol_cv_pthread_create,[
1093                 AC_TRY_RUN(OL_PTHREAD_TEST_PROGRAM,
1094                         [ol_cv_pthread_create=yes],
1095                         [ol_cv_pthread_create=no],
1096                         [AC_TRY_LINK(OL_PTHREAD_TEST_INCLUDES,OL_PTHREAD_TEST_FUNCTION,
1097                                 [ol_cv_pthread_create=yes],
1098                                 [ol_cv_pthread_create=no])])])
1099
1100                 if test $ol_cv_pthread_create != no ; then
1101                         ol_link_threads=posix
1102                         ol_link_pthreads=""
1103                 fi
1104                 
1105 dnl             OL_PTHREAD_TRY([-mt],           [ol_cv_pthread_mt])
1106                 OL_PTHREAD_TRY([-kthread],      [ol_cv_pthread_kthread])
1107                 OL_PTHREAD_TRY([-pthread],      [ol_cv_pthread_pthread])
1108                 OL_PTHREAD_TRY([-pthreads],     [ol_cv_pthread_pthreads])
1109                 OL_PTHREAD_TRY([-mthreads],     [ol_cv_pthread_mthreads])
1110                 OL_PTHREAD_TRY([-thread],       [ol_cv_pthread_thread])
1111
1112                 OL_PTHREAD_TRY([-lpthread -lmach -lexc -lc_r],
1113                         [ol_cv_pthread_lpthread_lmach_lexc_lc_r])
1114                 OL_PTHREAD_TRY([-lpthread -lmach -lexc],
1115                         [ol_cv_pthread_lpthread_lmach_lexc])
1116 dnl             OL_PTHREAD_TRY([-lpthread -lexc],
1117 dnl                     [ol_cv_pthread_lpthread_lexc])
1118
1119                 OL_PTHREAD_TRY([-lpthread -Wl,-woff,85],
1120                         [ol_cv_pthread_lib_lpthread_woff])
1121
1122                 OL_PTHREAD_TRY([-lpthread],     [ol_cv_pthread_lpthread])
1123                 OL_PTHREAD_TRY([-lc_r],         [ol_cv_pthread_lc_r])
1124
1125                 OL_PTHREAD_TRY([-threads],      [ol_cv_pthread_threads])
1126
1127                 OL_PTHREAD_TRY([-lpthreads -lmach -lexc -lc_r],
1128                         [ol_cv_pthread_lpthreads_lmach_lexc_lc_r])
1129                 OL_PTHREAD_TRY([-lpthreads -lmach -lexc],
1130                         [ol_cv_pthread_lpthreads_lmach_lexc])
1131                 OL_PTHREAD_TRY([-lpthreads -lexc],
1132                         [ol_cv_pthread_lpthreads_lexc])
1133
1134                 OL_PTHREAD_TRY([-lpthreads],[ol_cv_pthread_lib_lpthreads])
1135
1136                 if test $ol_link_threads != no ; then
1137                         AC_DEFINE(HAVE_PTHREADS,1,
1138                                 [define if you have POSIX Threads])
1139
1140                         LTHREAD_LIBS="$LTHREAD_LIBS $ol_link_pthreads"
1141
1142                         dnl save flags
1143                         save_CPPFLAGS="$CPPFLAGS"
1144                         save_LIBS="$LIBS"
1145                         LIBS="$LTHREAD_LIBS $LIBS"
1146
1147                         dnl All POSIX Thread (final) implementations should have
1148                         dnl sched_yield instead of pthread yield.
1149                         dnl check for both
1150                         AC_CHECK_FUNCS(sched_yield pthread_yield)
1151
1152                         if test $ac_cv_func_sched_yield = no -a \
1153                                 $ac_cv_func_pthread_yield = no ; then
1154                                 dnl Digital UNIX has sched_yield() in -lrt
1155                                 AC_CHECK_LIB(rt, sched_yield,
1156                                         [LTHREAD_LIBS="$LTHREAD_LIBS -lrt"
1157                                         AC_DEFINE(HAVE_SCHED_YIELD,1,
1158                                                 [Define if you have the sched_yield function.])
1159                                         ac_cv_func_sched_yield=yes],
1160                                         [ac_cv_func_sched_yield=no])
1161                         fi
1162                         if test $ac_cv_func_sched_yield = no -a \
1163                                 $ac_cv_func_pthread_yield = no ; then
1164                                 dnl Solaris has sched_yield() stub in -lposix4
1165                                 dnl but we'll use thr_yield instead.
1166                                 AC_CHECK_FUNCS(thr_yield)
1167                         fi
1168                         if test $ac_cv_func_sched_yield = no -a \
1169                                 $ac_cv_func_pthread_yield = no -a \
1170                                 "$ac_cv_func_thr_yield" = no ; then
1171                                 AC_MSG_WARN([could not locate sched_yield() or pthread_yield()])
1172                         fi
1173
1174                         dnl Check functions for compatibility
1175                         AC_CHECK_FUNCS(pthread_kill pthread_rwlock_destroy)
1176
1177                         dnl Check for pthread_detach with <pthread.h> inclusion
1178                         dnl as it's symbol may have been mangled.
1179                         AC_CACHE_CHECK([for pthread_detach with <pthread.h>],
1180                                 [ol_cv_func_pthread_detach], [
1181                                 dnl save the flags
1182                                 AC_TRY_LINK([
1183 #include <pthread.h>
1184 #ifndef NULL
1185 #define NULL (void*)0
1186 #endif
1187 ],
1188                                         [pthread_detach(NULL);],
1189                                         [ol_cv_func_pthread_detach=yes],
1190                                         [ol_cv_func_pthread_detach=no])
1191                         ])
1192
1193                         if test $ol_cv_func_pthread_detach = no ; then
1194                                 AC_MSG_ERROR([could not locate pthread_detach()])
1195                         fi
1196
1197                         AC_DEFINE(HAVE_PTHREAD_DETACH,1,
1198                                 [define if you have pthread_detach function])
1199
1200                         dnl Check for setconcurreny functions
1201                         AC_CHECK_FUNCS( \
1202                                 pthread_setconcurrency \
1203                                 pthread_getconcurrency \
1204                                 thr_setconcurrency \
1205                                 thr_getconcurrency \
1206                         )
1207
1208                         OL_SYS_LINUX_THREADS
1209                         OL_LINUX_THREADS
1210
1211                         if test $ol_cv_linux_threads = error; then
1212                                 AC_MSG_ERROR([LinuxThreads header/library mismatch]);
1213                         fi
1214
1215                         AC_CACHE_CHECK([if pthread_create() works],
1216                                 ol_cv_pthread_create_works,[
1217                         AC_TRY_RUN(OL_PTHREAD_TEST_PROGRAM,
1218                                 [ol_cv_pthread_create_works=yes],
1219                                 [ol_cv_pthread_create_works=no],
1220                                 [dnl assume yes
1221                                 ol_cv_pthread_create_works=yes])])
1222
1223                         if test $ol_cv_pthread_create_works = no ; then
1224                                 AC_MSG_ERROR([pthread_create is not usable, check environment settings])
1225                         fi
1226
1227                         dnl Check if select causes an yield
1228                         if test $ol_with_yielding_select = auto ; then
1229                                 AC_CACHE_CHECK([if select yields when using pthreads],
1230                                         ol_cv_pthread_select_yields,[
1231                                 AC_TRY_RUN([
1232 #include <sys/types.h>
1233 #include <sys/time.h>
1234 #include <unistd.h>
1235 #include <pthread.h>
1236 #ifndef NULL
1237 #define NULL (void*) 0
1238 #endif
1239
1240 static int fildes[2];
1241
1242 static void *task(p)
1243         void *p;
1244 {
1245         int i;
1246         struct timeval tv;
1247
1248         fd_set rfds;
1249
1250         tv.tv_sec=10;
1251         tv.tv_usec=0;
1252
1253         FD_ZERO(&rfds);
1254         FD_SET(fildes[0], &rfds);
1255
1256         /* we're not interested in any fds */
1257         i = select(FD_SETSIZE, &rfds, NULL, NULL, &tv);
1258
1259         if(i < 0) {
1260                 perror("select");
1261                 exit(10);
1262         }
1263
1264         exit(0); /* if we exit here, the select blocked the whole process */
1265 }
1266
1267 int main(argc, argv)
1268         int argc;
1269         char **argv;
1270 {
1271         pthread_t t;
1272
1273         /* create a pipe to select */
1274         if(pipe(&fildes[0])) {
1275                 perror("select");
1276                 exit(1);
1277         }
1278
1279 #ifdef HAVE_PTHREAD_SETCONCURRENCY
1280         (void) pthread_setconcurrency(2);
1281 #else
1282 #ifdef HAVE_THR_SETCONCURRENCY
1283         /* Set Solaris LWP concurrency to 2 */
1284         thr_setconcurrency(2);
1285 #endif
1286 #endif
1287
1288 #if HAVE_PTHREADS_D4
1289         pthread_create(&t, pthread_attr_default, task, NULL);
1290 #else
1291         pthread_create(&t, NULL, task, NULL);
1292 #endif
1293
1294 #if HAVE_SCHED_YIELD
1295         sched_yield();  /* make sure task runs first */
1296 #else
1297 #ifdef HAVE_PTHREAD_YIELD
1298         pthread_yield();        /* make sure task runs first */
1299 #endif
1300 #endif
1301
1302         exit(2);
1303 }],
1304                                 [ol_cv_pthread_select_yields=no],
1305                                 [ol_cv_pthread_select_yields=yes],
1306                                 [ol_cv_pthread_select_yields=cross])])
1307
1308                                 if test $ol_cv_pthread_select_yields = cross ; then
1309                                         AC_MSG_ERROR([crossing compiling: use --with-yielding_select=yes|no|manual])
1310                                 fi
1311
1312                                 if test $ol_cv_pthread_select_yields = yes ; then
1313                                         ol_with_yielding_select=yes
1314                                 fi
1315                         fi
1316
1317                         dnl restore flags
1318                         CPPFLAGS="$save_CPPFLAGS"
1319                         LIBS="$save_LIBS"
1320                 else
1321                         AC_MSG_ERROR([could not link with POSIX Threads])
1322                 fi
1323         fi
1324
1325         if test $ol_with_threads = posix ; then
1326                 AC_MSG_ERROR([could not locate POSIX Threads])
1327         fi
1328 fi
1329
1330 if test $ol_with_threads = auto -o $ol_with_threads = yes \
1331         -o $ol_with_threads = mach ; then
1332
1333         dnl check for Mach CThreads
1334         AC_CHECK_HEADERS(mach/cthreads.h)
1335         if test $ac_cv_header_mach_cthreads_h = yes ; then
1336                 ol_with_threads=found
1337
1338                 dnl check for cthread support in current $LIBS
1339                 AC_CHECK_FUNC(cthread_fork,[ol_link_threads=yes])
1340
1341                 if test $ol_link_threads = no ; then
1342                         dnl try -all_load
1343                         dnl this test needs work
1344                         AC_CACHE_CHECK([for cthread_fork with -all_load],
1345                                 [ol_cv_cthread_all_load], [
1346                                 dnl save the flags
1347                                 save_LIBS="$LIBS"
1348                                 LIBS="-all_load $LIBS"
1349                                 AC_TRY_LINK([#include <mach/cthreads.h>],[
1350                                         cthread_fork((void *)0, (void *)0);
1351                                         ], ol_cv_cthread_all_load=yes, ol_cv_cthread_all_load=no)
1352                                 dnl restore the LIBS
1353                                 LIBS="$save_LIBS"
1354                         ])
1355
1356                         if test $ol_cv_cthread_all_load = yes ; then
1357                                 LTHREAD_LIBS="$LTHREAD_LIBS -all_load"
1358                                 ol_link_threads=mach
1359                         fi
1360                 fi
1361
1362                 if test $ol_link_threads != no ; then
1363                         : check for cthread specific functionality here
1364                         AC_DEFINE(HAVE_MACH_CTHREADS,1,
1365                                 [define if you have Mach Cthreads])
1366                 else
1367                         AC_MSG_ERROR([could not link with Mach CThreads])
1368                 fi
1369         fi
1370
1371         if test $ol_with_threads = mach ; then
1372                 AC_MSG_ERROR([could not locate Mach CThreads])
1373         fi
1374 fi
1375
1376 if test $ol_with_threads = auto -o $ol_with_threads = yes \
1377         -o $ol_with_threads = pth ; then
1378
1379         AC_CHECK_HEADERS(pth.h)
1380
1381         if test $ac_cv_header_pth_h = yes ; then
1382                 AC_CHECK_LIB(pth, pth_version, [have_pth=yes], [have_pth=no])
1383
1384                 if test $have_pth = yes ; then
1385                         AC_DEFINE(HAVE_GNU_PTH,1,[if you have GNU Pth])
1386                         LTHREAD_LIBS="$LTHREAD_LIBS -lpth"
1387                         ol_link_threads=pth
1388
1389                         if test $ol_with_yielding_select = auto ; then
1390                                 ol_with_yielding_select=yes
1391                         fi
1392                 fi
1393         fi
1394 fi
1395
1396 if test $ol_with_threads = auto -o $ol_with_threads = yes \
1397         -o $ol_with_threads = lwp ; then
1398
1399         dnl check for SunOS5 LWP
1400         AC_CHECK_HEADERS(thread.h synch.h)
1401         if test $ac_cv_header_thread_h = yes -a $ac_cv_header_synch_h = yes ; then
1402                 AC_CHECK_LIB(thread, thr_create, [have_thr=yes], [have_thr=no])
1403
1404                 if test $have_thr = yes ; then
1405                         AC_DEFINE(HAVE_THR,1,
1406                                 [if you have Solaris LWP (thr) package])
1407                         LTHREAD_LIBS="$LTHREAD_LIBS -lthread"
1408                         ol_link_threads=thr
1409
1410                         if test $ol_with_yielding_select = auto ; then
1411                                 ol_with_yielding_select=yes
1412                         fi
1413
1414                         dnl Check for setconcurreny functions
1415                         AC_CHECK_FUNCS( \
1416                                 thr_setconcurrency \
1417                                 thr_getconcurrency \
1418                         )
1419                 fi
1420         fi
1421
1422         dnl check for SunOS4 LWP
1423         AC_CHECK_HEADERS(lwp/lwp.h)
1424         if test $ac_cv_header_lwp_lwp_h = yes ; then
1425                 AC_CHECK_LIB(lwp, lwp_create, [have_lwp=yes], [have_lwp=no])
1426
1427                 if test $have_lwp = yes ; then
1428                         AC_DEFINE(HAVE_LWP,1,
1429                                 [if you have SunOS LWP package])
1430                         LTHREAD_LIBS="$LTHREAD_LIBS -llwp"
1431                         ol_link_threads=lwp
1432
1433                         if test $ol_with_yielding_select = auto ; then
1434                                 ol_with_yielding_select=no
1435                         fi
1436                 fi
1437         fi
1438 fi
1439
1440 if test $ol_with_yielding_select = yes ; then
1441         AC_DEFINE(HAVE_YIELDING_SELECT,1,
1442                 [define if select implicitly yields])
1443 fi
1444
1445 if test $ol_with_threads = manual ; then
1446         dnl User thinks he can manually configure threads.
1447         ol_link_threads=yes
1448
1449         AC_MSG_WARN([thread defines and link options must be set manually])
1450
1451         AC_CHECK_HEADERS(pthread.h sched.h)
1452         AC_CHECK_FUNCS(sched_yield pthread_yield)
1453         OL_HEADER_LINUX_THREADS
1454
1455         AC_CHECK_HEADERS(mach/cthreads.h)
1456         AC_CHECK_HEADERS(lwp/lwp.h)
1457         AC_CHECK_HEADERS(thread.h synch.h)
1458 fi
1459
1460 if test $ol_link_threads != no -a $ol_link_threads != nt ; then  
1461         dnl needed to get reentrant/threadsafe versions
1462         dnl
1463         AC_DEFINE(REENTRANT,1)
1464         AC_DEFINE(_REENTRANT,1)
1465         AC_DEFINE(THREAD_SAFE,1)
1466         AC_DEFINE(_THREAD_SAFE,1)
1467         AC_DEFINE(THREADSAFE,1)
1468         AC_DEFINE(_THREADSAFE,1)
1469         AC_DEFINE(_SGI_MP_SOURCE,1)
1470
1471         dnl The errno declaration may dependent upon _REENTRANT.
1472         dnl If it does, we must link with thread support.
1473         AC_CACHE_CHECK([for thread specific errno],
1474                 [ol_cv_errno_thread_specific], [
1475                 AC_TRY_LINK([#include <errno.h>], [errno = 0;],
1476                         [ol_cv_errno_thread_specific=yes],
1477                         [ol_cv_errno_thread_specific=no])
1478         ])
1479
1480         dnl The h_errno declaration may dependent upon _REENTRANT.
1481         dnl If it does, we must link with thread support.
1482         AC_CACHE_CHECK([for thread specific h_errno],
1483                 [ol_cv_h_errno_thread_specific], [
1484                 AC_TRY_LINK([#include <netdb.h>], [h_errno = 0;],
1485                         [ol_cv_h_errno_thread_specific=yes],
1486                         [ol_cv_h_errno_thread_specific=no])
1487         ])
1488
1489         if test $ol_cv_errno_thread_specific != yes \
1490                 -o $ol_cv_h_errno_thread_specific != yes ; then
1491                 LIBS="$LTHREAD_LIBS $LIBS"
1492                 LTHREAD_LIBS=""
1493         fi
1494
1495 dnl When in thread environment, use 
1496 dnl             #if defined( HAVE_REENTRANT_FUNCTIONS ) \ 
1497 dnl                     || defined( HAVE_FUNC_R )
1498 dnl                     func_r(...);
1499 dnl             #else
1500 dnl             #       if defined( HAVE_THREADS ) 
1501 dnl                             /* lock */
1502 dnl             #       endif
1503 dnl                             func(...);
1504 dnl             #       if defined( HAVE_THREADS ) 
1505 dnl                             /* unlock */
1506 dnl             #       endif
1507 dnl             #endif
1508 dnl
1509 dnl HAVE_REENTRANT_FUNCTIONS is derived from:
1510 dnl             _POSIX_REENTRANT_FUNCTIONS
1511 dnl             _POSIX_THREAD_SAFE_FUNCTIONS
1512 dnl             _POSIX_THREADSAFE_FUNCTIONS
1513 dnl
1514 dnl             and is currently defined in lthread.h
1515 dnl
1516 dnl HAVE_THREADS is defined by lthread.h iff -UNO_THREADS
1517 dnl 
1518 dnl libldap/*.c should only include <lthread.h> iff
1519 dnl LDAP_R_COMPILE is defined.  ie:
1520 dnl             #ifdef LDAP_R_COMPILE
1521 dnl             #       include LDAP_R_COMPILE
1522 dnl             #endif
1523 dnl
1524 dnl LDAP_R_COMPILE is defined by libldap_r/Makefile.in
1525 dnl specifically for compiling the threadsafe version of
1526 dnl     the ldap library (-lldap_r).
1527 dnl             
1528 dnl     dnl check for reentrant/threadsafe functions
1529 dnl     dnl
1530 dnl     dnl note: these should only be used when linking
1531 dnl     dnl       with $LTHREAD_LIBS
1532 dnl     dnl
1533 dnl     save_CPPFLAGS="$CPPFLAGS"
1534 dnl     save_LIBS="$LIBS"
1535 dnl     LIBS="$LTHREAD_LIBS $LIBS"
1536 dnl     AC_CHECK_FUNCS( \
1537 dnl             gmtime_r \
1538 dnl             gethostbyaddr_r gethostbyname_r \
1539 dnl             feof_unlocked unlocked_feof \
1540 dnl             putc_unlocked unlocked_putc \
1541 dnl             flockfile ftrylockfile \
1542 dnl     )
1543 dnl     CPPFLAGS="$save_CPPFLAGS"
1544 dnl     LIBS="$save_LIBS"
1545 fi  
1546
1547 if test $ol_link_threads = no ; then
1548         if test $ol_with_threads = yes ; then
1549                 AC_MSG_ERROR([no suitable thread support])
1550         fi
1551
1552         if test $ol_with_threads = auto ; then
1553                 AC_MSG_WARN([no suitable thread support, disabling threads])
1554                 ol_with_threads=no
1555         fi
1556
1557         AC_DEFINE(NO_THREADS,1,
1558                 [define if you have (or want) no threads])
1559         LTHREAD_LIBS=""
1560 fi
1561
1562 if test $ol_link_threads != no ; then
1563         AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE,1)
1564 fi
1565
1566 dnl ----------------------------------------------------------------
1567 ol_link_ldbm=no 
1568
1569 if test $ol_with_ldbm_api = auto \
1570         -o $ol_with_ldbm_api = berkeley \
1571         -o $ol_with_ldbm_api = bcompat ; then
1572
1573         if test $ol_with_ldbm_api = bcompat; then \
1574                 OL_BERKELEY_COMPAT_DB
1575         else
1576                 OL_BERKELEY_DB
1577         fi
1578
1579         if test $ol_cv_berkeley_db != no ; then
1580                 AC_DEFINE(HAVE_BERKELEY_DB,1,
1581                         [define this if Berkeley DB is available])
1582
1583                 ol_link_ldbm=berkeley
1584                 ol_with_ldbm_api=db
1585
1586                 if test $ol_with_ldbm_type = hash ; then
1587                         AC_DEFINE(LDBM_USE_DBHASH,1,
1588                                 [define this to use DBHASH w/ LDBM backend])
1589                 else
1590                         AC_DEFINE(LDBM_USE_DBBTREE,1,
1591                                 [define this to use DBBTREE w/ LDBM backend])
1592                 fi
1593
1594                 dnl $ol_cv_lib_db should be yes or -ldb
1595                 dnl (it could be no, but that would be an error
1596                 if test $ol_cv_lib_db != yes ; then
1597                         LDBM_LIBS="$LDBM_LIBS $ol_cv_lib_db"
1598                 fi
1599         fi
1600 fi
1601
1602 if test $ol_link_ldbm = no -a $ol_with_ldbm_type = btree ; then
1603         AC_MSG_WARN(Could not find LDBM with BTREE support)
1604         ol_with_ldbm_api=none
1605 fi
1606
1607 if test $ol_with_ldbm_api = auto -o $ol_with_ldbm_api = mdbm ; then
1608         OL_MDBM
1609
1610         if test $ol_cv_mdbm = yes ; then
1611                 ol_link_ldbm=mdbm
1612                 ol_with_ldbm_api=mdbm
1613                 if test $ol_cv_lib_mdbm != yes ; then
1614                         LDBM_LIBS="$LDBM_LIBS $ol_cv_lib_mdbm"
1615                 fi
1616         fi
1617 fi
1618
1619 if test $ol_with_ldbm_api = auto -o $ol_with_ldbm_api = gdbm ; then
1620         OL_GDBM
1621
1622         if test $ol_cv_gdbm = yes ; then
1623                 ol_link_ldbm=gdbm
1624                 ol_with_ldbm_api=gdbm
1625
1626                 if test $ol_cv_lib_gdbm != yes ; then
1627                         LDBM_LIBS="$LDBM_LIBS $ol_cv_lib_gdbm"
1628                 fi
1629         fi
1630 fi
1631
1632 if test $ol_with_ldbm_api = ndbm ; then
1633         OL_NDBM
1634
1635         if test $ol_cv_ndbm = yes ; then
1636                 ol_link_ldbm=ndbm
1637                 ol_with_ldbm_api=ndbm
1638
1639                 if test $ol_cv_lib_ndbm != yes ; then
1640                         LDBM_LIBS="$LDBM_LIBS $ol_cv_lib_ndbm"
1641                 fi
1642         fi
1643 fi
1644
1645 if test $ol_link_ldbm = no -a $ol_enable_ldbm != no ; then
1646         AC_MSG_WARN(could not find suitable LDBM backend)
1647         if test $ol_enable_ldbm = yes ; then
1648                 AC_MSG_ERROR(select appropriate LDBM options or disable)
1649         fi
1650
1651         AC_MSG_WARN(disabling LDBM)
1652         ol_enable_ldbm=no
1653 fi
1654
1655 dnl ----------------------------------------------------------------
1656 if test $ol_enable_dynamic = yes -a $enable_shared = yes ; then
1657         LINK_BINS_DYNAMIC="yes"
1658 else
1659         LINK_BINS_DYNAMIC="no"
1660 fi
1661
1662 dnl ----------------------------------------------------------------
1663 if test $ol_enable_wrappers != no ; then
1664         AC_CHECK_HEADERS(tcpd.h)
1665
1666         if test $ac_cv_header_tcpd_h != yes ; then
1667                 have_wrappers=no
1668         else
1669                 AC_TRY_COMPILE([
1670 int allow_severity = 0;
1671 int deny_severity  = 0;
1672                 ],[hosts_access()],[have_wrappers=yes],[have_wrappers=no])
1673         fi
1674
1675         if test $have_wrappers = yes ; then
1676                 AC_DEFINE(HAVE_TCPD,1, [define if you have -lwrap])
1677                 WRAP_LIBS="-lwrap"
1678
1679                 dnl We add another check for -lnsl since some libwrap's
1680                 dnl need it, but it isn't always included from above
1681                 AC_CHECK_LIB(nsl, main)
1682         else
1683                 AC_MSG_WARN(could not find -lwrap)
1684                 if test $ol_enable_wrappers = yes ; then
1685                         AC_MSG_ERROR(could not find wrappers, select appropriate options or disable)
1686                 fi
1687
1688                 AC_MSG_WARN(disabling wrappers support)
1689                 ol_enable_wrappers=no
1690                 WRAP_LIBS=""
1691         fi
1692 fi
1693
1694 dnl ----------------------------------------------------------------
1695 if test $ol_enable_syslog != no ; then
1696         AC_CHECK_FUNC(openlog)
1697         if test $ac_cv_func_openlog = no -a $ol_enable_syslog = yes; then
1698                 AC_MSG_ERROR(could not find syslog, select appropriate options or disable)
1699         fi
1700         ol_enable_syslog=$ac_cv_func_openlog
1701 fi
1702
1703 dnl ----------------------------------------------------------------
1704 dnl ud needs termcap (should insert check here)
1705 ol_link_termcap=no
1706 AC_CHECK_HEADERS(termcap.h ncurses.h)
1707
1708 if test $ol_link_termcap = no ; then
1709         AC_CHECK_LIB(termcap, tputs, [have_termcap=yes], [have_termcap=no])
1710         if test $have_termcap = yes ; then
1711                 AC_DEFINE(HAVE_TERMCAP, 1, [define if you have -ltermcap])
1712                 ol_link_termcap=yes
1713                 TERMCAP_LIBS=-ltermcap
1714         fi
1715 fi
1716
1717 if test $ol_link_termcap = no ; then
1718         AC_CHECK_LIB(ncurses, initscr, [have_ncurses=yes], [have_ncurses=no])
1719         if test $have_ncurses = yes ; then
1720                 AC_DEFINE(HAVE_NCURSES, 1, [define if you have -lncurses])
1721                 ol_link_termcap=yes
1722                 TERMCAP_LIBS=-lncurses
1723         fi
1724 fi
1725
1726 if test $ol_link_termcap = no ; then
1727         AC_DEFINE(NO_TERMCAP,1, [define if you have no termcap support])
1728         TERMCAP_LIBS=
1729 fi
1730
1731 dnl ----------------------------------------------------------------
1732 dnl
1733 dnl Check for Cyrus SASL
1734 dnl
1735 ol_link_sasl=no
1736 ol_link_spasswd=no
1737 if test $ol_with_cyrus_sasl != no ; then
1738         AC_CHECK_HEADER(sasl.h)
1739
1740         if test $ac_cv_header_sasl_h = yes ; then
1741                 AC_CHECK_LIB(sasl, sasl_client_init,
1742                         [have_cyrus_sasl=yes], [have_cyrus_sasl=no])
1743
1744                 if test $have_cyrus_sasl != no ; then
1745                         SASL_LIBS="-lsasl"
1746                         AC_DEFINE(HAVE_CYRUS_SASL,1,[define if you have Cyrus SASL])
1747                         ol_link_sasl=yes
1748                 fi
1749         fi
1750
1751         if test $ol_link_sasl = no -a $ol_with_cyrus_sasl = yes ; then
1752                 AC_MSG_ERROR(no suitable API for --with-cyrus-sasl=$ol_with_cyrus_sasl)
1753         fi
1754 fi
1755
1756 dnl ----------------------------------------------------------------
1757 dnl Check for entropy sources
1758 if test $cross_compiling != yes ; then
1759         dev=no
1760         if test -r /dev/urandom ; then
1761                 dev="/dev/urandom";
1762         elif test -r /idev/urandom ; then
1763                 dev="/idev/urandom";
1764         elif test -r /dev/srandom ; then
1765                 dev="/dev/srandom";
1766         elif test -r /dev/random ; then
1767                 dev="/dev/random";
1768         elif test -r /idev/random ; then
1769                 dev="/idev/random";
1770         fi
1771
1772         if test $dev != no ; then
1773                 AC_DEFINE_UNQUOTED(URANDOM_DEVICE,"$dev",[set to urandom device])
1774         fi
1775 fi
1776
1777 dnl ----------------------------------------------------------------
1778 dnl
1779 dnl Check for fetch URL support
1780 dnl             should be extended to support other fetch URL APIs
1781 dnl
1782 ol_link_fetch=no
1783 if test $ol_with_fetch != no ; then
1784         OL_LIB_FETCH
1785
1786         if test $ol_cv_lib_fetch != no ; then
1787                 LDIF_LIBS="$LDIF_LIBS $ol_link_fetch"
1788                 ol_link_fetch=freebsd
1789
1790         elif test $ol_with_fetch != auto ; then
1791                 AC_MSG_ERROR(no suitable API for --with-fetch=$ol_with_fetch)
1792         fi 
1793 fi
1794
1795 dnl ----------------------------------------------------------------
1796 dnl
1797 dnl Check for GNU readline
1798 dnl
1799 ol_link_readline=no
1800 if test $ol_with_readline != no ; then
1801         AC_CHECK_HEADERS(readline/readline.h readline/history.h)
1802
1803         if test $ac_cv_header_readline_readline_h = yes ; then
1804                 save_LIBS="$LIBS"
1805                 LIBS="$TERMCAP_LIBS $LIBS"
1806                 AC_CHECK_LIB(readline, readline, 
1807                         [have_readline=yes], [have_readline=no])
1808                 LIBS="$save_LIBS"
1809                         
1810                 if test $have_readline = yes ; then
1811                         ol_with_readline=found
1812                         ol_link_readline=yes
1813
1814                         READLINE_LIBS="-lreadline"
1815                 fi
1816         fi
1817 fi
1818
1819 if test $ol_link_readline = yes ; then
1820         AC_DEFINE(HAVE_READLINE, 1, [define if you have -lreadline])
1821 fi
1822
1823
1824 dnl ----------------------------------------------------------------
1825 dnl FreeBSD (and others) have crypt(3) in -lcrypt
1826 if test $ol_enable_crypt != no ; then
1827         AC_CHECK_FUNC(crypt, [have_crypt=yes], [
1828                 AC_CHECK_LIB(crypt, crypt, [LUTIL_LIBS="$LUTIL_LIBS -lcrypt"
1829                         have_crypt=yes], [have_crypt=no])])
1830
1831         if test $have_crypt = yes ; then
1832                 AC_DEFINE(HAVE_CRYPT,1, [define if crypt(3) is available])
1833         else
1834                 AC_MSG_WARN(could not find crypt)
1835                 if test $ol_enable_crypt = yes ; then
1836                         AC_MSG_ERROR(could not find crypt, select appropriate options or disable)
1837                 fi
1838
1839                 AC_MSG_WARN(disabling crypt support)
1840                 ol_enable_crypt=no
1841         fi
1842 fi
1843
1844 dnl ----------------------------------------------------------------
1845 dnl FreeBSD (and others) have setproctitle(3) in -lutil
1846 if test $ol_enable_proctitle != no ; then
1847         AC_CHECK_FUNC(setproctitle,     [have_setproctitle=yes], [
1848                 AC_CHECK_LIB(util, setproctitle,
1849                         [have_setproctitle=yes
1850                         LUTIL_LIBS="$LUTIL_LIBS -lutil"],
1851                         [have_setproctitle=no
1852                         LIBOBJS="$LIBOBJS setproctitle.o"
1853                         LIBSRCS="$LIBSRCS setproctitle.c"])])
1854
1855         if test $have_setproctitle = yes ; then
1856                 AC_DEFINE(HAVE_SETPROCTITLE,1,
1857                         [define if setproctitle(3) is available])
1858         fi
1859 fi
1860
1861 dnl ----------------------------------------------------------------
1862 dnl Checks for typedefs, structures, and compiler characteristics.
1863 AC_TYPE_MODE_T
1864 AC_TYPE_OFF_T
1865 AC_TYPE_PID_T
1866 AM_TYPE_PTRDIFF_T
1867 AC_TYPE_SIGNAL
1868 AC_TYPE_SIZE_T
1869
1870 AC_CHECK_TYPE(ssize_t, [signed int])
1871 AC_CHECK_TYPE(caddr_t,  [char *])
1872
1873 OL_TYPE_SOCKLEN_T
1874 AC_STRUCT_ST_BLKSIZE
1875 AC_HEADER_TIME
1876 AC_STRUCT_TM
1877 AC_TYPE_UID_T
1878 OL_TYPE_SIG_ATOMIC_T
1879
1880 dnl AC_TYPE_GETGROUPS
1881
1882 OL_STRUCT_PASSWD_PW_GECOS
1883 OL_STRUCT_PASSWD_PW_PASSWD
1884
1885 OL_C_UPPER_LOWER
1886 AC_C_CONST
1887 OL_C_VOLATILE
1888
1889 if test $cross_compiling = yes ; then
1890         AC_DEFINE(CROSS_COMPILING, 1, [define if cross compiling])
1891 else
1892         AC_C_BIGENDIAN
1893 fi
1894
1895 AC_COMPILE_CHECK_SIZEOF(short) 
1896 AC_COMPILE_CHECK_SIZEOF(int) 
1897 AC_COMPILE_CHECK_SIZEOF(long)
1898
1899 if test "$ac_cv_sizeof_int" -lt 4 ; then
1900         AC_MSG_WARN([OpenLDAP requires 'int' to be 32 bits or greater.])
1901
1902         AC_DEFINE(LBER_INT_T,long)
1903 else
1904         AC_DEFINE(LBER_INT_T,int)
1905 fi
1906
1907 AC_DEFINE(LBER_LEN_T,long)
1908 AC_DEFINE(LBER_SOCKET_T,int)
1909 AC_DEFINE(LBER_TAG_T,long)
1910
1911 dnl ----------------------------------------------------------------
1912 dnl Checks for library functions.
1913 AC_FUNC_MEMCMP
1914 dnl AM_FUNC_MKTIME dnl checks for sys/time.h and unistd.h
1915 AC_FUNC_STRFTIME
1916 dnl AM_FUNC_STRTOD
1917
1918 OL_FUNC_INET_ATON
1919
1920 dnl Check for NT specific routines
1921 AC_CHECK_FUNC(_spawnlp, AC_DEFINE(HAVE_SPAWNLP,1,[if you have spawnlp()]))
1922
1923 AC_CHECK_FUNC(_snprintf, [ac_cv_func_snprintf=yes
1924         AC_DEFINE(snprintf, _snprintf, [define to snprintf routine])
1925 ])
1926
1927 AC_CHECK_FUNC(_vsnprintf, [ac_cv_func_vsnprintf=yes
1928         AC_DEFINE(vsnprintf, _vsnprintf, [define to vsnprintf routine])
1929 ])
1930
1931 AC_FUNC_VPRINTF
1932
1933 if test $ac_cv_func_vprintf = yes ; then
1934         dnl check for vsnprintf
1935         AC_CHECK_FUNCS(vsnprintf vsprintf)
1936 fi
1937
1938 AC_CHECK_FUNCS(         \
1939         bcopy                   \
1940         closesocket             \
1941         chroot                  \
1942         endgrent                \
1943         endpwent                \
1944         flock                   \
1945         getdtablesize   \
1946         getgrgid                \
1947         gethostname             \
1948         getpass                 \
1949         getpassphrase   \
1950         getpwuid                \
1951         getpwnam                \
1952         getspnam                \
1953         gettimeofday    \
1954         initgroups              \
1955         lockf                   \
1956         memcpy                  \
1957         memmove                 \
1958         mkstemp                 \
1959         pipe                    \
1960         read                    \
1961         recv                    \
1962         recvfrom                \
1963         setpwfile               \
1964         setgid                  \
1965         setegid                 \
1966         setsid                  \
1967         setuid                  \
1968         seteuid                 \
1969         sigaction               \
1970         signal                  \
1971         sigset                  \
1972         snprintf                \
1973         strdup                  \
1974         strerror                \
1975         strpbrk                 \
1976         strrchr                 \
1977         strsep                  \
1978         strstr                  \
1979         strtol                  \
1980         strtoul                 \
1981         strspn                  \
1982         sysconf                 \
1983         waitpid                 \
1984         wait4                   \
1985         write                   \
1986         send                    \
1987         sendto                  \
1988 )
1989
1990 dnl We actually may need to replace more than this.
1991 AC_REPLACE_FUNCS(getopt tempnam)
1992
1993 if test "$ac_cv_func_getopt" != yes; then
1994     LIBSRCS="$LIBSRCS getopt.c"
1995 fi
1996
1997 if test "$ac_cv_func_tempnam" != yes; then
1998     LIBSRCS="$LIBSRCS tempnam.c"
1999 fi
2000
2001 dnl ----------------------------------------------------------------
2002 # Check Configuration
2003 OL_SYS_ERRLIST
2004
2005 dnl ----------------------------------------------------------------
2006 dnl Sort out defines
2007
2008 if test "$ol_enable_debug" != no ; then
2009         AC_DEFINE(LDAP_DEBUG,1,
2010                 [define this to add debugging code])
2011 fi
2012 if test "$ol_enable_syslog" = yes ; then
2013         AC_DEFINE(LDAP_SYSLOG,1,
2014                 [define this to add syslog code])
2015 fi
2016 if test "$ol_enable_libui" = yes ; then
2017         AC_DEFINE(LDAP_LIBUI,1,
2018                 [define this for LDAP User Interface support])
2019 fi
2020 if test "$ol_enable_cache" = no ; then
2021         AC_DEFINE(LDAP_NOCACHE,1,
2022                 [define this to remove -lldap cache support])
2023 fi
2024 if test "$ol_link_kbind" != no ; then
2025         AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND,LDAP_VENDOR_VERSION)
2026 fi
2027 if test "$ol_enable_proctitle" != no ; then
2028         AC_DEFINE(LDAP_PROCTITLE,1,
2029                 [define this for LDAP process title support])
2030 fi
2031 if test "$ol_enable_referrals" != no ; then
2032         AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS,LDAP_VENDOR_VERSION)
2033 fi
2034 if test "$ol_enable_cldap" != no ; then
2035         AC_DEFINE(LDAP_CONNECTIONLESS,1,[define to support CLDAP])
2036 fi
2037 if test "$ol_enable_unix" != no; then
2038         AC_DEFINE(LDAP_PF_UNIX,1,[define to support PF_UNIX])
2039 fi
2040 if test "$ol_enable_ipv6" != no; then
2041         AC_DEFINE(LDAP_PF_INET6,1,[define to support PF_INET6])
2042 fi
2043 if test "$ol_enable_cleartext" != no ; then
2044         AC_DEFINE(SLAPD_CLEARTEXT,1,[define to support cleartext passwords])
2045 fi
2046 if test "$ol_enable_crypt" != no ; then
2047         AC_DEFINE(SLAPD_CRYPT,1,[define to support crypt(3) passwords])
2048 fi
2049 if test "$ol_link_kpasswd" != no ; then
2050         AC_DEFINE(SLAPD_KPASSWD,1,[define to support Kerberos passwords])
2051 fi
2052 if test "$ol_link_spasswd" != no ; then
2053         AC_DEFINE(SLAPD_SPASSWD,1,[define to support SASL passwords])
2054 fi
2055 if test "$ol_enable_multimaster" != no ; then
2056         AC_DEFINE(SLAPD_MULTIMASTER,1,[define to support multimaster replication])
2057 fi
2058 if test "$ol_enable_phonetic" != no ; then
2059         AC_DEFINE(SLAPD_PHONETIC,1,[define to support phonetic])
2060 fi
2061 if test "$ol_enable_rlookups" != no ; then
2062         AC_DEFINE(SLAPD_RLOOKUPS,1,[define to support reverse lookups])
2063 fi
2064 if test "$ol_enable_aci" != no ; then
2065         AC_DEFINE(SLAPD_ACI_ENABLED,1,[define to support per-object ACIs])
2066 fi
2067
2068 if test "$ol_link_modules" != no ; then
2069         AC_DEFINE(SLAPD_MODULES,1,[define to support modules])
2070         BUILD_SLAPD=yes
2071         SLAPD_MODULES_LDFLAGS="-dlopen self"
2072 fi
2073
2074 if test "$ol_link_dnssrv" != no ; then
2075         AC_DEFINE(SLAPD_DNSSRV,1,[define to support DNS SRV backend])
2076         BUILD_SLAPD=yes
2077         BUILD_DNSSRV=yes
2078         if test "$ol_with_dnssrv_module" != static ; then
2079                 AC_DEFINE(SLAPD_DNSSRV_DYNAMIC,1,
2080                         [define to support dynamic DNS SRV backend])
2081                 BUILD_DNSSRV=mod
2082                 BUILD_DNSSRV_DYNAMIC=shared
2083                 SLAPD_MODULES_LIST="$SLAPD_MODULES_LIST -dlopen \$(SLAP_DIR)back-dnssrv/back_dnssrv.la"
2084         fi
2085 fi
2086
2087 if test "$ol_enable_ldap" != no ; then
2088         AC_DEFINE(SLAPD_LDAP,1,[define to support LDAP backend])
2089         BUILD_SLAPD=yes
2090         BUILD_LDAP=yes
2091         if test "$ol_with_ldap_module" != static ; then
2092                 AC_DEFINE(SLAPD_LDAP_DYNAMIC,1,
2093                         [define to support dynamic LDAP backend])
2094                 BUILD_LDAP=mod
2095                 BUILD_LDAP_DYNAMIC=shared
2096                 SLAPD_MODULES_LIST="$SLAPD_MODULES_LIST -dlopen \$(SLAP_DIR)back-ldap/back_ldap.la"
2097         fi
2098 fi
2099
2100 if test "$ol_link_ldbm" != no ; then
2101         AC_DEFINE(SLAPD_LDBM,1,[define to support LDBM backend])
2102         BUILD_SLAPD=yes
2103         BUILD_LDBM=yes
2104         if test "$ol_with_ldbm_module" != static ; then
2105                 AC_DEFINE(SLAPD_LDBM_DYNAMIC,1,
2106                         [define to support dynamic LDBM backend])
2107                 BUILD_LDBM=mod
2108                 BUILD_LDBM_DYNAMIC=shared
2109                 SLAPD_MODULES_LIST="$SLAPD_MODULES_LIST -dlopen \$(SLAP_DIR)back-ldbm/back_ldbm.la"
2110         fi
2111 fi
2112
2113 if test "$ol_enable_passwd" != no ; then
2114         AC_DEFINE(SLAPD_PASSWD,1,[define to support PASSWD backend])
2115         BUILD_SLAPD=yes
2116         BUILD_PASSWD=yes
2117         if test "$ol_with_passwd_module" != static ; then
2118                 AC_DEFINE(SLAPD_PASSWD_DYNAMIC,1,
2119                         [define to support dynamic PASSWD backend])
2120                 BUILD_PASSWD=mod
2121                 BUILD_PASSWD_DYNAMIC=shared
2122                 SLAPD_MODULES_LIST="$SLAPD_MODULES_LIST -dlopen \$(SLAP_DIR)back-passwd/back_passwd.la"
2123         fi
2124 fi
2125
2126 if test "$ol_enable_shell" != no ; then
2127         AC_DEFINE(SLAPD_SHELL,1,[define to support SHELL backend])
2128         BUILD_SLAPD=yes
2129         BUILD_SHELL=yes
2130         if test "$ol_with_shell_module" != static ; then
2131                 AC_DEFINE(SLAPD_SHELL_DYNAMIC,1,
2132                         [define to support dynamic SHELL backend])
2133                 BUILD_SHELL=mod
2134                 BUILD_SHELL_DYNAMIC=shared
2135                 SLAPD_MODULES_LIST="$SLAPD_MODULES_LIST -dlopen \$(SLAP_DIR)back-shell/back_shell.la"
2136         fi
2137 fi
2138
2139 if test "$ol_enable_slurpd" != no -a "$ol_link_threads" != no -a \
2140         $BUILD_SLAPD = yes ; then
2141         BUILD_SLURPD=yes
2142 fi
2143
2144 dnl ----------------------------------------------------------------
2145
2146 if test "$LINK_BINS_DYNAMIC" = yes; then
2147     LIB_LINKAGE=DYN
2148     LT_LIB_LINKAGE=shared
2149 else
2150     LIB_LINKAGE=STAT
2151     LT_LIB_LINKAGE=static
2152 fi
2153
2154 if test "$ac_cv_mingw32" = yes ; then
2155     PLAT=NT
2156     DYN_EXT=dll
2157 else
2158     PLAT=UNIX
2159     DYN_EXT=so
2160 fi
2161
2162 AC_SUBST(LIBSRCS)
2163
2164 AC_SUBST(PLAT)
2165 AC_SUBST(LIB_LINKAGE)
2166 AC_SUBST(LT_LIB_LINKAGE)
2167 AC_SUBST(DYN_EXT)
2168
2169 AC_SUBST(BUILD_SLAPD)
2170   AC_SUBST(BUILD_DNSSRV)
2171   AC_SUBST(BUILD_LDAP)
2172   AC_SUBST(BUILD_LDBM)
2173   AC_SUBST(BUILD_PASSWD)
2174   AC_SUBST(BUILD_QUIPU)
2175   AC_SUBST(BUILD_SHELL)
2176   AC_SUBST(BUILD_DNSSRV_DYNAMIC)
2177   AC_SUBST(BUILD_LDAP_DYNAMIC)
2178   AC_SUBST(BUILD_LDBM_DYNAMIC)
2179   AC_SUBST(BUILD_PASSWD_DYNAMIC)
2180   AC_SUBST(BUILD_SHELL_DYNAMIC)
2181 AC_SUBST(BUILD_SLURPD)
2182
2183 AC_SUBST(LDAP_LIBS)
2184 AC_SUBST(LDIF_LIBS)
2185 AC_SUBST(SLAPD_LIBS)
2186 AC_SUBST(QUIPU_LIBS)
2187 AC_SUBST(SLURPD_LIBS)
2188 AC_SUBST(LDBM_LIBS)
2189 AC_SUBST(LTHREAD_LIBS)
2190 AC_SUBST(LUTIL_LIBS)
2191 AC_SUBST(WRAP_LIBS)
2192 AC_SUBST(LINK_BINS_DYNAMIC)
2193
2194 AC_SUBST(SLAPD_MODULES_CPPFLAGS)
2195 AC_SUBST(SLAPD_MODULES_LDFLAGS)
2196 AC_SUBST(SLAPD_MODULES_LIST)
2197
2198 AC_SUBST(KRB4_LIBS)
2199 AC_SUBST(KRB5_LIBS)
2200 AC_SUBST(READLINE_LIBS)
2201 AC_SUBST(SASL_LIBS)
2202 AC_SUBST(TERMCAP_LIBS)
2203 AC_SUBST(TLS_LIBS)
2204 AC_SUBST(MODULES_LIBS)
2205 AC_SUBST(AUTH_LIBS)
2206
2207 dnl ----------------------------------------------------------------
2208 dnl final output
2209 dnl
2210
2211 AC_OUTPUT( \
2212 Makefile:build/top.mk:Makefile.in:build/dir.mk \
2213 doc/Makefile:build/top.mk:doc/Makefile.in:build/dir.mk \
2214 doc/man/Makefile:build/top.mk:doc/man/Makefile.in:build/dir.mk \
2215 doc/man/man1/Makefile:build/top.mk:doc/man/man1/Makefile.in:build/man.mk \
2216 doc/man/man3/Makefile:build/top.mk:doc/man/man3/Makefile.in:build/man.mk \
2217 doc/man/man5/Makefile:build/top.mk:doc/man/man5/Makefile.in:build/man.mk \
2218 doc/man/man8/Makefile:build/top.mk:doc/man/man8/Makefile.in:build/man.mk \
2219 clients/Makefile:build/top.mk:clients/Makefile.in:build/dir.mk \
2220 clients/finger/Makefile:build/top.mk:clients/finger/Makefile.in:build/rules.mk \
2221 clients/fax500/Makefile:build/top.mk:clients/fax500/Makefile.in:build/rules.mk \
2222 clients/gopher/Makefile:build/top.mk:clients/gopher/Makefile.in:build/rules.mk \
2223 clients/mail500/Makefile:build/top.mk:clients/mail500/Makefile.in:build/rules.mk \
2224 clients/rcpt500/Makefile:build/top.mk:clients/rcpt500/Makefile.in:build/rules.mk \
2225 clients/ud/Makefile:build/top.mk:clients/ud/Makefile.in:build/rules.mk \
2226 clients/maildap/Makefile:build/top.mk:clients/maildap/Makefile.in:build/rules.mk \
2227 clients/tools/Makefile:build/top.mk:clients/tools/Makefile.in:build/rules.mk \
2228 include/Makefile:build/top.mk:include/Makefile.in \
2229 libraries/Makefile:build/top.mk:libraries/Makefile.in:build/dir.mk      \
2230 libraries/libavl/Makefile:build/top.mk:libraries/libavl/Makefile.in:build/lib.mk:build/lib-static.mk    \
2231 libraries/liblber/Makefile:build/top.mk:libraries/liblber/Makefile.in:build/lib.mk:build/lib-shared.mk  \
2232 libraries/libldap/Makefile:build/top.mk:libraries/libldap/Makefile.in:build/lib.mk:build/lib-shared.mk  \
2233 libraries/libldap_r/Makefile:build/top.mk:libraries/libldap_r/Makefile.in:build/lib.mk:build/lib-shared.mk      \
2234 libraries/libldbm/Makefile:build/top.mk:libraries/libldbm/Makefile.in:build/lib.mk:build/lib-static.mk  \
2235 libraries/libldif/Makefile:build/top.mk:libraries/libldif/Makefile.in:build/lib.mk:build/lib-static.mk  \
2236 libraries/liblunicode/Makefile:build/top.mk:libraries/liblunicode/Makefile.in:build/lib.mk:build/lib-static.mk  \
2237 libraries/liblutil/Makefile:build/top.mk:libraries/liblutil/Makefile.in:build/lib.mk:build/lib-static.mk        \
2238 servers/Makefile:build/top.mk:servers/Makefile.in:build/dir.mk \
2239 servers/slapd/Makefile:build/top.mk:servers/slapd/Makefile.in:build/srv.mk \
2240 servers/slapd/back-dnssrv/Makefile:build/top.mk:servers/slapd/back-dnssrv/Makefile.in:build/mod.mk \
2241 servers/slapd/back-ldap/Makefile:build/top.mk:servers/slapd/back-ldap/Makefile.in:build/mod.mk \
2242 servers/slapd/back-ldbm/Makefile:build/top.mk:servers/slapd/back-ldbm/Makefile.in:build/mod.mk \
2243 servers/slapd/back-passwd/Makefile:build/top.mk:servers/slapd/back-passwd/Makefile.in:build/mod.mk \
2244 servers/slapd/back-shell/Makefile:build/top.mk:servers/slapd/back-shell/Makefile.in:build/mod.mk \
2245 servers/slapd/shell-backends/Makefile:build/top.mk:servers/slapd/shell-backends/Makefile.in:build/srv.mk \
2246 servers/slapd/tools/Makefile:build/top.mk:servers/slapd/tools/Makefile.in \
2247 servers/slurpd/Makefile:build/top.mk:servers/slurpd/Makefile.in:build/srv.mk \
2248 tests/Makefile:build/top.mk:tests/Makefile.in:build/dir.mk \
2249 tests/progs/Makefile:build/top.mk:tests/progs/Makefile.in:build/rules.mk \
2250 contrib/Makefile:build/top.mk:contrib/Makefile.in:build/dir.mk \
2251 contrib/saucer/Makefile:build/top.mk:contrib/saucer/Makefile.in:build/rules.mk \
2252 contrib/web_ldap/Makefile:build/top.mk:contrib/web_ldap/Makefile.in:build/rules.mk \
2253 ,[
2254 date > stamp-h
2255 echo Please \"make depend\" to build dependencies
2256 ])