]> git.sur5r.net Git - openldap/blob - configure.in
Detect pthread_detach using #include <pthread.h> (using AC_TRY_LINK)
[openldap] / configure.in
1 dnl
2 dnl Copyright 1998,1999 The OpenLDAP Foundation.  All Rights Reserved.
3 dnl 
4 dnl Redistribution and use in source and binary forms are permitted only
5 dnl as authorized by the OpenLDAP Public License.  A copy of this
6 dnl license is available at http://www.OpenLDAP.org/license.html or
7 dnl in file LICENSE in the top-level directory of the distribution.
8 dnl
9
10 dnl Configure.in for OpenLDAP
11 AC_INIT(include/ldap.h)dnl
12 AC_CONFIG_AUX_DIR(build)dnl
13 AM_INIT_AUTOMAKE(OpenLDAP,[2.0-devel], [no ac_define])dnl
14
15 dnl We use autoconf features new to 2.13.
16 dnl     aclocal.m4 should be built using aclocal from automake 1.4
17 AC_PREREQ(2.13)dnl Required Autoconf version
18
19 AC_CONFIG_HEADER(include/portable.h include/ldap_features.h)dnl
20
21 dnl
22 dnl Start Args
23 AC_MSG_CHECKING(configure arguments)
24 AC_PREFIX_DEFAULT(/usr/local)
25
26 top_builddir=`pwd`
27 AC_SUBST(top_builddir)dnl
28
29 ldap_subdir="openldap"
30
31 AC_ARG_WITH(subdir, [  --with-subdir=DIR change default subdirectory used for installs], [
32         if test "$withval" = "no"; then
33                 ldap_subdir=""
34         elif test "$withval" != "yes"; then
35                 ldap_subdir="$withval"
36         fi
37 ])dnl
38
39 AC_SUBST(ldap_subdir)dnl
40
41 OL_ARG_ENABLE(debug,[  --enable-debug   enable debugging], yes)dnl
42 ol_enable_syslog=no
43 dnl OL_ARG_ENABLE(syslog,[  --enable-syslog     enable syslog support], auto)dnl
44 OL_ARG_ENABLE(proctitle,[  --enable-proctitle   enable proctitle support], yes)dnl
45 OL_ARG_ENABLE(cache,[  --enable-cache   enable caching], yes)dnl
46 OL_ARG_ENABLE(dns,[  --enable-dns               enable V2 DNS  extension], no)dnl
47 OL_ARG_ENABLE(referrals,[  --enable-referrals   enable V2 Referrals extension], yes)dnl
48 OL_ARG_ENABLE(cldap,[  --enable-cldap   enable connectionless ldap], no)dnl
49 OL_ARG_ENABLE(x_compile,[  --enable-x-compile   enable cross compiling],
50         no, [yes no])dnl
51
52
53 dnl General "with" options
54 OL_ARG_ENABLE(dmalloc,[  --enable-dmalloc       enable debug malloc support], no)dnl
55
56 OL_ARG_WITH(kerberos,[  --with-kerberos use Kerberos],
57         auto, [auto k5 k4 afs yes no])
58 OL_ARG_WITH(threads,[  --with-threads   use threads],
59         auto, [auto posix mach lwp yes no manual] )
60 OL_ARG_WITH(yielding_select,[  --with-yielding-select   with implicitly yielding select],
61         auto, [auto yes no manual] )
62
63 dnl Server options
64
65 dnl LDAPD OPTIONS
66 AC_ARG_WITH(xxldapdoptions,[LDAPD Options:])
67 OL_ARG_ENABLE(ldapd,[  --enable-ldapd   enable building ldapd], no)dnl
68
69 dnl SLAPD OPTIONS
70 AC_ARG_WITH(xxslapdoptions,[SLAPD Options:])
71 OL_ARG_ENABLE(slapd,[  --enable-slapd   enable building slapd], yes)dnl
72 OL_ARG_ENABLE(aclgroups,[    --enable-aclgroups enable ACL group support], auto)dnl
73 OL_ARG_ENABLE(cleartext,[    --enable-cleartext enable cleartext passwords], yes)dnl
74 OL_ARG_ENABLE(crypt,[    --enable-crypt enable crypt(3) passwords], auto)dnl
75 OL_ARG_ENABLE(wrappers,[    --enable-wrappers   enable tcp wrapper support], no)dnl
76 OL_ARG_ENABLE(phonetic,[    --enable-phonetic   enable phonetic/soundex], no)dnl
77 OL_ARG_ENABLE(rlookups,[    --enable-rlookups   enable reverse lookups], auto)dnl
78
79 dnl SLAPD Backend options
80 OL_ARG_ENABLE(bdb2,[    --enable-bdb2   enable bdb2 backend], no)dnl
81 OL_ARG_ENABLE(ldbm,[    --enable-ldbm   enable ldbm backend], yes)dnl
82 OL_ARG_WITH(ldbm_api,[      --with-ldbm-api     use LDBM API], auto,
83         [auto db2 db gdbm ndbm manual])
84 OL_ARG_WITH(ldbm_type,[      --with-ldbm-type   use LDBM type], auto,
85         [auto btree hash])
86
87 OL_ARG_ENABLE(passwd,[    --enable-passwd       enable passwd backend], no)dnl
88 OL_ARG_ENABLE(perl,[    --enable-perl   enable perl backend], no)dnl
89 OL_ARG_ENABLE(shell,[    --enable-shell enable shell backend], no)dnl
90
91 dnl SLURPD OPTIONS
92 AC_ARG_WITH(xxslurpdoptions,[SLURPD Options:])
93 OL_ARG_ENABLE(slurpd,[  --enable-slurpd enable building slurpd], auto)dnl
94
95 AC_ARG_WITH(xxliboptions,[Library Generation & Linking Options])
96 AM_ENABLE_STATIC
97 dnl AM_DISABLE_SHARED
98 AM_ENABLE_SHARED
99
100 dnl General "enable" options
101 # validate options
102 if test $ol_enable_dns = yes ; then
103         if test $ol_enable_referrals = no ; then
104                 AC_MSG_ERROR([DNS requires --enable-referrals])
105         fi
106         if test $ol_enable_referrals = auto ; then
107                 AC_MSG_WARN([DNS requires referrals, adding --enable-referrals])
108                 ol_enable_referrals=yes
109         fi
110 fi
111
112 if test $ol_enable_slapd = no ; then
113         dnl SLAPD was specificallly disabled
114         if test $ol_enable_bdb2 = yes ; then
115                 AC_MSG_WARN([slapd disabled, ignoring --enable_bdb2 argument])
116         fi
117         if test $ol_enable_ldbm = yes ; then
118                 AC_MSG_WARN([slapd disabled, ignoring --enable_ldbm argument])
119         fi
120         if test $ol_enable_passwd = yes ; then
121                 AC_MSG_WARN([slapd disabled, ignoring --enable_passwd argument])
122         fi
123         if test $ol_enable_perl = yes ; then
124                 AC_MSG_WARN([slapd disabled, ignoring --enable_perl argument])
125         fi
126         if test $ol_enable_shell = yes ; then
127                 AC_MSG_WARN([slapd disabled, ignoring --enable_shell argument])
128         fi
129         if test $ol_enable_aclgroups = yes ; then
130                 AC_MSG_WARN([slapd disabled, ignoring --enable_aclgroups argument])
131         fi
132         if test $ol_enable_wrappers = yes ; then
133                 AC_MSG_WARN([slapd disabled, ignoring --enable_wrappers argument])
134         fi
135         if test $ol_enable_phonetic = yes ; then
136                 AC_MSG_WARN([slapd disabled, ignoring --enable_phonetic argument])
137         fi
138         if test $ol_enable_rlookups = yes ; then
139                 AC_MSG_WARN([slapd disabled, ignoring --enable_rlookups argument])
140         fi
141         if test $ol_with_ldbm_api != auto ; then
142                 AC_MSG_WARN([slapd disabled, ignoring --with_ldbm_api argument])
143         fi
144         if test $ol_with_ldbm_type != auto ; then
145                 AC_MSG_WARN([slapd disabled, ignoring --with_ldbm_type argument])
146         fi
147         if test $ol_enable_slurpd = yes ; then
148                 AC_MSG_ERROR([slurpd requires slapd])
149         fi
150
151         # force settings to no
152         ol_enable_bdb2=no
153         ol_enable_ldbm=no
154         ol_enable_passwd=no
155         ol_enable_perl=no
156         ol_enable_shell=no
157         ol_enable_aclgroups=no
158         ol_enable_wrappers=no
159         ol_enable_phonetic=no
160         ol_enable_rlookups=no
161         ol_with_ldbm_api=no
162         ol_with_ldbm_type=no
163         ol_enable_slurpd=no
164
165 elif test $ol_enable_ldbm = no ; then
166         dnl SLAPD without LDBM
167
168         if test $ol_with_ldbm_api != auto ; then
169                 AC_MSG_WARN([LDBM disabled, ignoring --with_ldbm_api argument])
170         fi
171
172         if test $ol_with_ldbm_type != auto ; then
173                 AC_MSG_WARN([LDBM disabled, ignoring --with_ldbm_type argument])
174         fi
175
176         if test $ol_enable_bdb2 = yes ; then
177                 AC_MSG_ERROR([BDB2 requires --enable-ldbm])
178         fi
179
180         if test $ol_enable_passwd = no -a \
181                 $ol_enable_perl = no -a \
182                 $ol_enable_shell = no ; then
183                 AC_MSG_ERROR([slapd requires a backend])
184         fi
185
186         ol_with_ldbm_api=no
187         ol_with_ldbm_type=no
188
189 elif test $ol_enable_bdb2 = yes ; then
190         dnl SLAPD with BDB2
191
192         if test $ol_with_ldbm_api != auto -a \
193                 $ol_with_ldbm_api != db2 ; then
194                 AC_MSG_ERROR([BDB2 requires LDBM API DB2])
195         fi
196
197         ol_with_ldbm_api=db2
198
199 else
200         dnl SLAPD with LDBM
201
202         if test $ol_enable_bdb2 != no ; then
203                 if test $ol_with_ldbm_api != auto -a \
204                         $ol_with_ldbm_api != db2 ; then
205                         AC_MSG_WARN([BDB2 requires LDBM api db2 or auto])
206                         ol_enable_bdb2=no
207                 fi
208         fi
209
210         if test $ol_with_ldbm_api = gdbm -a \
211                 $ol_with_ldbm_type = btree ; then
212                 AC_MSG_ERROR([GDBM only supports LDBM type hash])
213         fi
214         if test $ol_with_ldbm_api = ndbm -a \
215                 $ol_with_ldbm_type = btree ; then
216                 AC_MSG_ERROR([NDBM only supports LDBM type hash])
217         fi
218 fi
219
220 if test $ol_enable_slurpd = yes ; then
221         dnl SLURPD was specifically enabled
222         if test $ol_with_threads = no ; then
223                 AC_MSG_ERROR([slurpd requires threads])
224         fi
225 fi
226
227 AC_MSG_RESULT(done)
228
229 AC_CANONICAL_HOST
230
231 ## Initialize vars
232 LDAP_LIBS=
233 LDBM_LIBS=
234 LTHREAD_LIBS=
235 LUTIL_LIBS=
236
237 LDAPD_LIBS=
238 SLAPD_LIBS=
239 SLURPD_LIBS=
240
241 BUILD_LDAPD=no
242 BUILD_SLAPD=no
243 BUILD_SLURPD=no
244
245 BUILD_BDB2=no
246 BUILD_LDBM=no
247 BUILD_PASSWD=no
248 BUILD_PERL=no
249 BUILD_SHELL=no
250 BUILD_THREAD=no
251
252 SLAPD_PERL_LDFLAGS=
253 SLAPD_PERL_CPPFLAGS=
254
255 KRB_LIBS=
256 TERMCAP_LIBS=
257
258 dnl ----------------------------------------------------------------
259 dnl Checks for programs
260
261 AC_PROG_INSTALL
262 AM_PROG_LIBTOOL
263 dnl AC_PROG_MAKE_SET
264
265 AC_PROG_AWK
266 AC_PROG_LN_S
267
268 AC_PATH_PROG(SENDMAIL, sendmail, /usr/lib/sendmail,
269         $PATH:/usr/libexec:/usr/lib:/usr/sbin:/usr/etc:/etc)
270 AC_PATH_PROG(EDITOR, vi, /usr/ucb/vi, $PATH:/usr/ucb)
271 AC_PATH_PROG(FINGER, finger, /usr/ucb/finger, $PATH:/usr/ucb)
272
273 if test $ol_enable_perl = yes ; then
274         AC_PATH_PROG(PERLBIN, perl, /usr/bin/perl)
275
276         if test "no$PERLBIN" = "no" ; then
277                 ol_enable_perl=no
278         fi
279
280         SLAPD_PERL_LDFLAGS="`$PERLBIN -MExtUtils::Embed -e ldopts|sed -e s/-lc//`"
281         SLAPD_PERL_CPPFLAGS="`$PERLBIN -MExtUtils::Embed -e perl_inc`"
282 fi
283
284 AC_PROG_CPP
285
286 if test $cross_compiling = yes -a $ol_enable_x_compile = yes; then
287         AC_MSG_WARN([cross compiling....  some functionality will be removed.])
288
289 elif test $cross_compiling = no -a $ol_enable_x_compile = yes; then
290         AC_MSG_WARN([programs compiled here do run here...])
291         AC_MSG_ERROR([  if not cross compiling, use --disable-x-compile.])
292
293 elif test $cross_compiling = yes -a $ol_enable_x_compile = no; then
294         AC_MSG_WARN([programs compiled here do not run here...])
295         AC_MSG_ERROR([  if cross compiling,  add --enable-x-compile.])
296 fi
297
298 dnl Checks for UNIX Variants
299 AC_AIX
300 AC_ISC_POSIX
301 AC_MINIX
302
303 dnl Checks for system services
304 AC_CYGWIN
305 AC_MINGW32
306 AC_EXEEXT
307 AC_OBJEXT
308
309 dnl OpenLDAP requires STDC features
310 AM_PROG_CC_STDC
311 if test "X${am_cv_prog_cc_stdc}" = "Xno" ; then
312         AC_MSG_ERROR([OpenLDAP requires compiler to support STDC prototypes.])
313 fi
314
315 dnl AM_C_PROTOTYPES
316
317 dnl Checks for libraries
318
319 dnl Find socket()
320 dnl Likely combinations:
321 dnl             -lsocket [ -lnsl_s | -lnsl ]
322 dnl             -linet
323
324 AC_CHECK_FUNC(socket, [have_socket=yes], [      
325 dnl
326 dnl hopefully we won't include too many libraries
327 dnl
328         AC_CHECK_LIB(socket, main)
329         AC_CHECK_LIB(net, main)
330         AC_CHECK_LIB(nsl_s, main)
331         AC_CHECK_LIB(nsl, main)
332         AC_CHECK_LIB(inet, socket)
333         AC_CHECK_LIB(gen, main)
334 ])
335
336 dnl Check for resolver routines
337 AC_CHECK_FUNCS(res_search)
338 if test $ac_cv_func_res_search = "no" ; then 
339         AC_CHECK_LIB(bind, res_search)
340         if test "$ac_cv_lib_bind_res_search" = "yes" ; then
341                 AC_DEFINE(HAVE_RES_SEARCH,1)
342         else
343                 AC_CHECK_LIB(resolv, res_search)
344                 if test "$ac_cv_lib_resolv_res_search" = "yes" ; then
345                         AC_DEFINE(HAVE_RES_SEARCH,1)
346                 fi
347         fi
348 fi
349
350 dnl HP-UX requires -lV3
351 AC_CHECK_LIB(V3, sigset)
352
353 # ISODE tests
354 ol_link_isode=no
355 if test $ol_enable_ldapd != no ; then
356         dnl look for ISODE libraries
357         AC_CHECK_LIB(xtpp, main, [
358                 ol_link_isode=yes
359                 AC_DEFINE(HAVE_XTPP,1, [define if you have -lxttp])
360                 LDAPD_LIBS="$LDAPD_LIBS -lxtpp -lxtdsap -lxtisode -losi"
361                 ],:,[-lxtdsap -lxtisode -losi])
362         AC_CHECK_LIB(dsap, main, [
363                 ol_link_isode=yes
364                 AC_DEFINE(HAVE_DSAP,1, [define if you have -ldsap])
365                 LDAPD_LIBS="$LDAPD_LIBS -ldsap"
366                 ],:,[-lisode])
367         AC_CHECK_LIB(isode, main, [
368                 ol_link_isode=yes
369                 AC_DEFINE(HAVE_ISODE,1, [define if you have -lisode])
370                 LDAPD_LIBS="$LDAPD_LIBS -lisode"
371                 ],:)
372 fi
373
374 if test $ol_link_isode != no; then
375         AC_CHECK_LIB(pp, main, [
376                 AC_DEFINE(HAVE_PP,1, [define if you have -lpp])
377                 LDAPD_LIBS="-lpp $LDAPD_LIBS"
378                 ],:)
379
380         AC_PATH_PROG(PEPSY, pepsy)
381 fi
382
383 dnl
384 dnl check for kerberos
385 dnl
386 ol_link_kerberos=no
387
388 if test $ol_with_kerberos = auto -o $ol_with_kerberos = k5 ; then
389         AC_CHECK_HEADERS(kerberosIV/krb.h kerberosIV/des.h)
390
391         if test $ac_cv_header_kerberosIV_krb_h = yes ; then
392                 AC_CHECK_LIB(krb4, main, [have_k5=yes], [have_k5=no],
393                         [-lkrb5 -ldes425])
394
395                 if test $have_k5 = yes ; then
396                         ol_with_kerberos=found
397                         ol_link_kerberos=yes
398
399                         KRB_LIBS="-lkrb4 -lkrb5 -ldes425"
400
401                         LIBS="$KRB_LIBS $LIBS"
402
403                         AC_CACHE_CHECK([for des_debug in Kerberos libraries],
404                                 [ol_cv_var_des_debug], [
405                                 dnl save the flags
406                                 save_LIBS="$LIBS"
407                                 LIBS="$KRB_LIBS $LIBS"
408                                 AC_TRY_LINK([
409 #include <kerberosIV/krb.h>
410 #include <kerberosIV/des.h>
411 extern int des_debug;
412 ],[
413 des_debug = 1;
414 ],                              ol_cv_var_des_debug=yes, ol_cv_var_des_debug=no)
415                                 dnl restore the LIBS
416                                 LIBS="$save_LIBS"
417                         ])
418
419                         if test $ol_cv_var_des_debug= yes ; then
420                                 AC_DEFINE(HAVE_DES_DEBUG,1,
421                                         [define if you have Kerberos des_debug])
422                         fi
423
424                         LIBS="$save_LIBS"
425                 fi
426         fi
427 fi
428
429 if test $ol_with_kerberos = auto -o $ol_with_kerberos = k4 ; then
430         AC_CHECK_HEADERS(krb.h des.h)
431
432         if test $ac_cv_header_krb_h = yes ; then
433                 AC_CHECK_LIB(krb, main, [have_k4=yes], [have_k4=no], [-ldes])
434
435                 if test $have_k4 = yes ; then
436                         ol_with_kerberos=found
437                         ol_link_kerberos=yes
438
439                         KRB_LIBS="-lkrb -ldes"
440                 fi
441         fi
442 fi
443
444 if test $ol_link_kerberos = yes ; then
445         AC_DEFINE(HAVE_KERBEROS, 1, [define if you have Kerberos])
446 fi
447
448 ol_link_threads=no
449 if test $ol_with_threads = auto -o $ol_with_threads = yes \
450         -o $ol_with_threads = posix ; then
451
452         AC_CHECK_HEADERS(pthread.h sched.h)
453
454         if test $ac_cv_header_pthread_h = yes ; then
455                 OL_POSIX_THREAD_VERSION
456
457                 if test $ol_cv_pthread_version = final ; then
458                         AC_DEFINE(HAVE_PTHREADS_FINAL,1,
459                                 [define if pthreads API compatible with final spec])
460                 elif test $ol_cv_pthread_version = draft4 ; then
461                         AC_DEFINE(HAVE_PTHREADS_D4,1,
462                                 [define if pthreads API compatible with draft4 spec])
463                 else
464                         AC_MSG_ERROR([unknown pthread version])
465                 fi
466
467                 # consider threads found
468                 ol_with_threads=found
469
470                 OL_LINUX_THREADS
471
472                 if test $ol_cv_linux_threads = yes ; then
473                         AC_DEFINE(HAVE_LINUX_THREADS,1,
474                                 [define if you have LinuxThreads])
475                 fi
476
477                 dnl Now the hard part, how to link?
478                 dnl
479                 dnl currently supported checks:
480                 dnl
481                 dnl Check for no flags 
482                 dnl     pthread_create() in $LIBS
483                 dnl
484                 dnl Check special pthread (final) flags
485                 dnl     pthread_create() with -kthread (FreeBSD)
486                 dnl     pthread_create() with -pthread (FreeBSD/Digital Unix)
487                 dnl     pthread_create() with -pthreads (?)
488                 dnl     pthread_create() with -thread (?)
489                 dnl
490                 dnl Check pthread (final) libraries
491                 dnl     pthread_mutex_unlock() in -lpthread -lmach -lexc -lc_r (OSF/1)
492                 dnl     pthread_mutex_lock() in -lpthread -lmach -lexc (OSF/1)
493                 dnl     pthread_mutex_trylock() in -lpthread -lexc (OSF/1)
494                 dnl     pthread_create() in -lpthread (many)
495                 dnl     pthread_create() in -lc_r (FreeBSD)
496                 dnl     pthread_create() in -lpthreads (many)
497                 dnl     pthread_join() -Wl,-woff,85 -lpthreads (IRIX)
498                 dnl     pthread_create() in HP-UX -lpthread (HP-UX 11)
499                 dnl
500                 dnl Check pthread (draft4) flags (to be depreciated)
501                 dnl     pthread_create() with -threads (OSF/1)
502                 dnl
503                 dnl Check pthread (final) libraries (to be depreciated)
504                 dnl     pthread_mutex_unlock() in -lpthreads -lmach -lexc -lc_r (OSF/1)
505                 dnl     pthread_mutex_lock() in -lpthreads -lmach -lexc (OSF/1)
506                 dnl     pthread_mutex_trylock() in -lpthreads -lexc (OSF/1)
507                 dnl
508
509                 dnl pthread_create in $LIBS
510                 AC_CHECK_FUNC(pthread_create,[ol_link_threads=yes])
511
512                 if test $ol_link_threads = no ; then
513                         dnl try -kthread
514                         AC_CACHE_CHECK([for pthread_create with -kthread],
515                                 [ol_cv_kthread_flag], [
516                                 dnl save the flags
517                                 save_LIBS="$LIBS"
518                                 LIBS="-kthread $LIBS"
519                                 AC_TRY_LINK([#include <pthread.h>],
520                                         [pthread_create(NULL,NULL,NULL,NULL);],
521                                         [ol_cv_kthread_flag=yes], [ol_cv_kthread_flag=no])
522                                 dnl restore the LIBS
523                                 LIBS="$save_LIBS"
524                         ])
525
526                         if test $ol_cv_kthread_flag = yes ; then
527                                 LTHREAD_LIBS="$LTHREAD_LIBS -kthread"
528                                 ol_link_threads=posix
529                         fi
530                 fi
531
532                 if test $ol_link_threads = no ; then
533                         dnl try -pthread
534                         AC_CACHE_CHECK([for pthread_create with -pthread],
535                                 [ol_cv_pthread_flag], [
536                                 dnl save the flags
537                                 save_LIBS="$LIBS"
538                                 LIBS="-pthread $LIBS"
539                                 AC_TRY_LINK([#include <pthread.h>],
540                                         [pthread_create(NULL,NULL,NULL,NULL);],
541                                         [ol_cv_pthread_flag=yes], [ol_cv_pthread_flag=no])
542                                 dnl restore the LIBS
543                                 LIBS="$save_LIBS"
544                         ])
545
546                         if test $ol_cv_pthread_flag = yes ; then
547                                 LTHREAD_LIBS="$LTHREAD_LIBS -pthread"
548                                 ol_link_threads=posix
549                         fi
550                 fi
551
552                 if test $ol_link_threads = no ; then
553                         dnl try -pthreads
554                         AC_CACHE_CHECK([for pthread_create with -pthreads],
555                                 [ol_cv_pthreads_flag], [
556                                 dnl save the flags
557                                 save_LIBS="$LIBS"
558                                 LIBS="-pthreads $LIBS"
559                                 AC_TRY_LINK([#include <pthread.h>],
560                                         [pthread_create(NULL,NULL,NULL,NULL);],
561                                         [ol_cv_pthreads_flag=yes], [ol_cv_pthreads_flag=no])
562                                 dnl restore the LIBS
563                                 LIBS="$save_LIBS"
564                         ])
565
566                         if test $ol_cv_pthreads_flag = yes ; then
567                                 LTHREAD_LIBS="$LTHREAD_LIBS -pthreads"
568                                 ol_link_threads=posix
569                         fi
570                 fi
571
572                 if test $ol_link_threads = no ; then
573                         dnl try -thread
574                         AC_CACHE_CHECK([for pthread_create with -thread],
575                                 [ol_cv_thread_flag], [
576                                 dnl save the flags
577                                 save_LIBS="$LIBS"
578                                 LIBS="-thread $LIBS"
579                                 AC_TRY_LINK([char pthread_create();],
580                                         [pthread_create();],
581                                         [ol_cv_thread_flag=yes], [ol_cv_thread_flag=no])
582                                 dnl restore the LIBS
583                                 LIBS="$save_LIBS"
584                         ])
585
586                         if test $ol_cv_thread_flag = yes ; then
587                                 LTHREAD_LIBS="$LTHREAD_LIBS -thread"
588                                 ol_link_threads=posix
589                         fi
590                 fi
591
592                 if test $ol_link_threads = no ; then
593                         dnl try DEC Threads -lpthread -lmach -lexc -lc_r
594                         save_LIBS="$LIBS"
595                         AC_CHECK_LIB(pthread, pthread_mutex_unlock, [
596                                 ol_link_threads=posix
597                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthread -lmach -lexc -lc_r"
598                                 if test $ol_with_yielding_select = auto ; then
599                                         ol_with_yielding_select=yes
600                                 fi
601                                 ],:,[-lmach -lexc -lc_r])
602                         LIBS="$save_LIBS"
603                 fi
604
605                 if test $ol_link_threads = no ; then
606                         dnl try DEC Threads -lpthread -lmach -lexc
607                         save_LIBS="$LIBS"
608                         AC_CHECK_LIB(pthread, pthread_mutex_lock, [
609                                 ol_link_threads=posix
610                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthread -lmach -lexc"
611                                 if test $ol_with_yielding_select = auto ; then
612                                         ol_with_yielding_select=yes
613                                 fi
614                                 ],:,[-lmach -lexc])
615                         LIBS="$save_LIBS"
616                 fi
617
618                 if test $ol_link_threads = no ; then
619                         dnl try DEC Threads -lpthread -lexc
620                         save_LIBS="$LIBS"
621                         AC_CHECK_LIB(pthread, pthread_mutex_trylock, [
622                                 ol_link_threads=posix
623                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthread -lexc"
624                                 if test $ol_with_yielding_select = auto ; then
625                                         ol_with_yielding_select=yes
626                                 fi
627                                 ],:,[-lexc])
628                         LIBS="$save_LIBS"
629                 fi
630
631                 if test $ol_link_threads = no ; then
632                         dnl try -lpthread
633                         save_LIBS="$LIBS"
634                         AC_CHECK_LIB(pthread, pthread_create, [
635                                 ol_link_threads=posix
636                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthread"],:)
637                         LIBS="$save_LIBS"
638                 fi
639
640                 if test $ol_link_threads = no ; then
641                         dnl try -lc_r
642                         save_LIBS="$LIBS"
643                         AC_CHECK_LIB(c_r, pthread_create, [
644                                 ol_link_threads=posix
645                                 LTHREAD_LIBS="$LTHREAD_LIBS -lc_r"],:)
646                         LIBS="$save_LIBS"
647                 fi
648
649                 if test $ol_link_threads = no ; then
650                         dnl try -lpthreads
651                         save_LIBS="$LIBS"
652                         AC_CHECK_LIB(pthreads, pthread_create, [
653                                 ol_link_threads=posix
654                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthreads"],:)
655                         LIBS="$save_LIBS"
656                 fi
657
658                 dnl IRIX Pthread check
659                 if test $ol_link_threads = no ; then
660                         dnl try IRIX Pthreads -Wl,-woff,85 -lpthreads
661                         save_LIBS="$LIBS"
662                         AC_CHECK_LIB(pthreads, pthread_join, [
663                                 ol_link_threads=posix
664                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthreads"
665                                 ],:,[-Wl,-woff,85])
666                         LIBS="$save_LIBS"
667                 fi
668
669                 dnl HP-UX 11 Pthread check
670                 if test $ol_link_threads = no; then
671                         save_LIBS="$LIBS"
672                         LIBS="$LIBS -lpthread"
673                         AC_MSG_CHECKING([for pthread_create() in HP-UX -lpthread])
674                         ol_try_pthread_hpux_11=no
675                         AC_CACHE_VAL(ol_cv_pthread_hpux_11,[
676                                 AC_TRY_LINK([
677 #include <pthread.h>
678 #include <elf.h>
679 #ifndef ELFABI_HPUX_REL11
680         die horribly
681 #endif
682                                 ], [pthread_create(NULL, NULL, NULL, NULL);],
683                                         ol_try_pthread_hpux_11=yes
684                                         ol_cv_pthread_hpux_11=yes,
685                                         ol_cv_pthread_hpux_11=no)])
686                         AC_MSG_RESULT(yes)
687                         LIBS="$save_LIBS"
688
689                         if test $ol_cv_pthread_hpux_11=yes ; then
690                                 ol_link_threads=posix
691                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthread"
692                                 if test $ol_try_pthread_hpux_11=yes ; then
693                                         dnl Some tests below may fail, cause we aint including
694                                         dnl pthread.h. Force appropriate ones to yes
695                                         ac_cv_func_pthread_attr_init=yes
696                                 fi
697                         fi
698                 fi
699
700                 if test $ol_link_threads = no ; then
701                         dnl try -threads
702                         AC_CACHE_CHECK([for pthread_create with -threads],
703                                 [ol_cv_thread_flag], [
704                                 dnl save the flags
705                                 save_LIBS="$LIBS"
706                                 LIBS="-threads $LIBS"
707                                 AC_TRY_LINK([char pthread_create();],[
708                                         pthread_create();
709                                         ], ol_cv_thread_flag=yes, ol_cv_thread_flag=no)
710                                 dnl restore the LIBS
711                                 LIBS="$save_LIBS"
712                         ])
713
714                         if test $ol_cv_thread_flag = yes ; then
715                                 LTHREAD_LIBS="$LTHREAD_LIBS -threads"
716                                 ol_link_threads=posix
717                         fi
718                 fi
719
720                 if test $ol_link_threads = no ; then
721                         dnl try DEC Threads -lpthreads -lmach -lexc -lc_r
722                         save_LIBS="$LIBS"
723                         AC_CHECK_LIB(pthreads, pthread_mutex_unlock, [
724                                 ol_link_threads=posix
725                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthreads -lmach -lexc -lc_r"
726                                 if test $ol_with_yielding_select = auto ; then
727                                         ol_with_yielding_select=yes
728                                 fi
729                                 ],:,[-lmach -lexc -lc_r])
730                         LIBS="$save_LIBS"
731                 fi
732
733                 if test $ol_link_threads = no ; then
734                         dnl try DEC Threads -lpthreads -lmach -lexc
735                         save_LIBS="$LIBS"
736                         AC_CHECK_LIB(pthreads, pthread_mutex_lock, [
737                                 ol_link_threads=posix
738                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthreads -lmach -lexc"
739                                 if test $ol_with_yielding_select = auto ; then
740                                         ol_with_yielding_select=yes
741                                 fi
742                                 ],:,[-lmach -lexc])
743                         LIBS="$save_LIBS"
744                 fi
745
746                 if test $ol_link_threads = no ; then
747                         dnl try DEC Threads -lpthreads -lexc
748                         save_LIBS="$LIBS"
749                         AC_CHECK_LIB(pthreads, pthread_mutex_trylock, [
750                                 ol_link_threads=posix
751                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthreads -lexc"
752                                 if test $ol_with_yielding_select = auto ; then
753                                         ol_with_yielding_select=yes
754                                 fi
755                                 ],:,[-lexc])
756                         LIBS="$save_LIBS"
757                 fi
758
759                 if test $ol_link_threads != no ; then
760                         AC_DEFINE(HAVE_PTHREADS,1,
761                                 [define if you have POSIX Threads])
762
763                         dnl save flags
764                         save_CPPFLAGS="$CPPFLAGS"
765                         save_LIBS="$LIBS"
766                         LIBS="$LTHREAD_LIBS $LIBS"
767
768                         dnl All POSIX Thread (final) implementations should have
769                         dnl sched_yield instead of pthread yield.
770                         dnl check for both
771                         AC_CHECK_FUNCS(sched_yield pthread_yield)
772
773                         if test $ac_cv_func_sched_yield = no -a \
774                                 $ac_cv_func_pthread_yield = no ; then
775                                 dnl Digital UNIX has sched_yield() in -lrt
776                                 AC_CHECK_LIB(rt, sched_yield,
777                                         [LTHREAD_LIBS="$LTHREAD_LIBS -lrt"
778                                         AC_DEFINE(HAVE_SCHED_YIELD,1)
779                                         ac_cv_func_sched_yield=yes],
780                                         [ac_cv_func_sched_yield=no])
781                         fi
782                         if test $ac_cv_func_sched_yield = no -a \
783                                 $ac_cv_func_pthread_yield = no ; then
784                                 dnl Solaris has sched_yield() in -lposix4
785                                 dnl but we'll use thr_yield instead.
786                                 AC_CHECK_FUNCS(thr_yield)
787                         fi
788                         if test $ac_cv_func_sched_yield = no -a \
789                                 $ac_cv_func_pthread_yield = no -a \
790                                 "$ac_cv_func_thr_yield" = no ; then
791                                 AC_MSG_WARN([could not locate sched_yield() or pthread_yield()])
792                         fi
793
794                         dnl Check functions for compatibility
795                         AC_CHECK_FUNCS(pthread_kill)
796
797                         dnl Check for pthread_detach with <pthread.h> inclusion
798                         dnl as it's symbol may have been mangled.
799                         AC_CACHE_CHECK([for pthread_detach with <pthread.h>],
800                                 [ol_cv_func_pthread_detach], [
801                                 dnl save the flags
802                                 AC_TRY_LINK([#include <pthread.h>],
803                                         [pthread_detach(NULL);],
804                                         [ol_cv_func_pthread_detach=yes],
805                                         [ol_cv_func_pthread_detach=no])
806                         ])
807
808                         if test $ol_cv_func_pthread_detach = no ; then
809                                 AC_MSG_ERROR([could not locate pthread_detach()])
810                         fi
811
812                         AC_DEFINE(HAVE_PTHREAD_DETACH,1,
813                                 [define if you have pthread_detach function])
814
815                         dnl Check for setconcurreny functions
816                         AC_CHECK_FUNCS( \
817                                 pthread_setconcurrency \
818                                 pthread_getconcurrency \
819                                 thr_setconcurrency \
820                                 thr_getconcurrency \
821                         )
822
823                         AC_MSG_CHECKING([if pthread_create() works])
824                         AC_CACHE_VAL(ol_cv_pthread_create_works,[
825                         AC_TRY_RUN([
826 #include <pthread.h>
827 #ifndef NULL
828 #define NULL (void*)0
829 #endif
830
831 static void *task(p)
832         void *p;
833 {
834         return (void *) (p == NULL);
835 }
836
837 int main(argc, argv)
838         int argc;
839         char **argv;
840 {
841         pthread_t t;
842         exit(pthread_create(&t, NULL, task, NULL));
843 }
844 ],
845                                 [ol_cv_pthread_create_works=yes],
846                                 [ol_cv_pthread_create_works=no],
847                                 [dnl assume yes
848                                 ol_cv_pthread_create_works=yes])])
849                         AC_MSG_RESULT($ol_cv_pthread_create_works)
850
851                         if test $ol_cv_pthread_create_works = no ; then
852                                 AC_MSG_ERROR([pthread.h and pthread_create are not compatible])
853                         fi
854
855                         dnl Check if select causes an yield
856                         if test $ol_with_yielding_select = auto ; then
857                                 AC_MSG_CHECKING([if select yields when using pthreads])
858                                 AC_CACHE_VAL(ol_cv_pthread_select_yields,[
859                                 AC_TRY_RUN([
860 #include <sys/types.h>
861 #include <sys/time.h>
862 #include <unistd.h>
863 #include <pthread.h>
864 #ifndef NULL
865 #define NULL (void*) 0
866 #endif
867
868 static int fildes[2];
869
870 static void *task(p)
871         void *p;
872 {
873         int i;
874         struct timeval tv;
875
876         fd_set rfds;
877
878         tv.tv_sec=10;
879         tv.tv_usec=0;
880
881         FD_ZERO(&rfds);
882         FD_SET(fildes[0], &rfds);
883
884         /* we're not interested in any fds */
885         i = select(FD_SETSIZE, &rfds, NULL, NULL, &tv);
886
887         if(i < 0) {
888                 perror("select");
889                 exit(10);
890         }
891
892         exit(0); /* if we exit here, the select blocked the whole process */
893 }
894
895 int main(argc, argv)
896         int argc;
897         char **argv;
898 {
899         pthread_t t;
900
901         /* create a pipe to select */
902         if(pipe(&fildes[0])) {
903                 perror("select");
904                 exit(1);
905         }
906
907 #ifdef HAVE_PTHREAD_SETCONCURRENCY
908         (void) pthread_setconcurrency(2);
909 #else
910 #ifdef HAVE_THR_SETCONCURRENCY
911         /* Set Solaris LWP concurrency to 2 */
912         thr_setconcurrency(2);
913 #endif
914 #endif
915
916         pthread_create(&t, NULL, task, NULL);
917
918 #if HAVE_SCHED_YIELD
919         sched_yield();  /* make sure task runs first */
920 #else
921 #ifdef HAVE_PTHREAD_YIELD
922         pthread_yield();        /* make sure task runs first */
923 #endif
924 #endif
925
926         exit(2);
927 }],
928                                 [ol_cv_pthread_select_yields=no],
929                                 [ol_cv_pthread_select_yields=yes], [
930                                 AC_MSG_ERROR([crossing compiling: use --with-yielding_select=yes|no|manual])])])
931                                 AC_MSG_RESULT($ol_cv_pthread_select_yields)
932
933                                 if test $ol_cv_pthread_select_yields = yes ; then
934                                         ol_with_yielding_select=yes
935                                 fi
936                         fi
937
938                         dnl restore flags
939                         CPPFLAGS="$save_CPPFLAGS"
940                         LIBS="$save_LIBS"
941                 else
942                         AC_MSG_ERROR([could not link with POSIX Threads])
943                 fi
944         fi
945
946         if test $ol_with_threads = posix ; then
947                 AC_MSG_ERROR([could not locate POSIX Threads])
948         fi
949 fi
950
951 if test $ol_with_threads = auto -o $ol_with_threads = yes \
952         -o $ol_with_threads = mach ; then
953
954         dnl check for Mach CThreads
955         AC_CHECK_HEADERS(mach/cthreads.h)
956         if test $ac_cv_header_mach_cthreads_h = yes ; then
957                 ol_with_threads=found
958
959                 dnl check for cthread support in current $LIBS
960                 AC_CHECK_FUNC(cthread_fork,[ol_link_threads=yes])
961
962                 if test $ol_link_threads = no ; then
963                         dnl try -all_load
964                         dnl this test needs work
965                         AC_CACHE_CHECK([for cthread_fork with -all_load],
966                                 [ol_cv_cthread_all_load], [
967                                 dnl save the flags
968                                 save_LIBS="$LIBS"
969                                 LIBS="-all_load $LIBS"
970                                 AC_TRY_LINK([#include <mach/cthreads.h>],[
971                                         cthread_fork((void *)0, (void *)0);
972                                         ], ol_cv_cthread_all_load=yes, ol_cv_cthread_all_load=no)
973                                 dnl restore the LIBS
974                                 LIBS="$save_LIBS"
975                         ])
976
977                         if test $ol_cv_cthread_all_load = yes ; then
978                                 LTHREAD_LIBS="$LTHREAD_LIBS -all_load"
979                                 ol_link_threads=mach
980                         fi
981                 fi
982
983                 if test $ol_link_threads != no ; then
984                         : check for cthread specific functionality here
985                         AC_DEFINE(HAVE_MACH_CTHREADS,1,
986                                 [define if you have Mach Cthreads])
987                 else
988                         AC_MSG_ERROR([could not link with Mach CThreads])
989                 fi
990         fi
991
992         if test $ol_with_threads = mach ; then
993                 AC_MSG_ERROR([could not locate Mach CThreads])
994         fi
995 fi
996
997 if test $ol_with_threads = auto -o $ol_with_threads = yes \
998         -o $ol_with_threads = lwp ; then
999
1000         dnl check for SunOS5 LWP
1001         AC_CHECK_HEADERS(thread.h synch.h)
1002         if test $ac_cv_header_thread_h = yes -a $ac_cv_header_synch_h = yes ; then
1003                 AC_CHECK_LIB(thread, thr_create, [have_thr=yes], [have_thr=no])
1004
1005                 if test $have_thr = yes ; then
1006                         AC_DEFINE(HAVE_THR,1,
1007                                 [if you have Solaris LWP (thr) package])
1008                         LTHREAD_LIBS="$LTHREAD_LIBS -lthread"
1009                         ol_link_threads=thr
1010
1011                         if test $ol_with_yielding_select = auto ; then
1012                                 ol_with_yielding_select=yes
1013                         fi
1014
1015                         dnl Check for setconcurreny functions
1016                         AC_CHECK_FUNCS( \
1017                                 thr_setconcurrency \
1018                                 thr_getconcurrency \
1019                         )
1020                 fi
1021         fi
1022
1023         dnl check for SunOS4 LWP
1024         AC_CHECK_HEADERS(lwp/lwp.h)
1025         if test $ac_cv_header_lwp_lwp_h = yes ; then
1026                 AC_CHECK_LIB(lwp, lwp_create, [have_lwp=yes], [have_lwp=no])
1027
1028                 if test $have_lwp = yes ; then
1029                         AC_DEFINE(HAVE_LWP,1,
1030                                 [if you have SunOS LWP package])
1031                         LTHREAD_LIBS="$LTHREAD_LIBS -llwp"
1032                         ol_link_threads=lwp
1033
1034                         if test $ol_with_yielding_select = auto ; then
1035                                 ol_with_yielding_select=no
1036                         fi
1037                 fi
1038         fi
1039 fi
1040
1041 if test $ol_with_yielding_select = yes ; then
1042         AC_DEFINE(HAVE_YIELDING_SELECT,1,
1043                 [define if select implicitly yields])
1044 fi
1045
1046 if test $ol_with_threads = manual ; then
1047         dnl User thinks he can manually configure threads.
1048         ol_link_threads=yes
1049
1050         AC_MSG_WARN([thread defines and link options must be set manually])
1051
1052         AC_CHECK_HEADERS(pthread.h sched.h)
1053         AC_CHECK_FUNCS(sched_yield pthread_yield)
1054         OL_LINUX_THREADS
1055
1056         AC_CHECK_HEADERS(mach/cthreads.h)
1057         AC_CHECK_HEADERS(lwp/lwp.h)
1058         AC_CHECK_HEADERS(thread.h synch.h)
1059 fi
1060
1061 if test $ol_link_threads != no ; then  
1062         dnl needed to get reentrant/threadsafe versions
1063         dnl
1064         AC_DEFINE(REENTRANT,1)
1065         AC_DEFINE(_REENTRANT,1)
1066         AC_DEFINE(THREAD_SAFE,1)
1067         AC_DEFINE(_THREAD_SAFE,1)
1068         AC_DEFINE(THREADSAFE,1)
1069         AC_DEFINE(_THREADSAFE,1)
1070
1071         dnl this might cause the errno symbol to be
1072         dnl replaced with a function to get a thread specific errno.
1073         dnl check to see if everything needs to be compiled
1074         dnl with the thread libraries
1075         AC_CACHE_CHECK([for thread specific errno],
1076                 [ol_cv_errno_thread_specific], [
1077                 AC_TRY_LINK([#include <errno.h>], [int x = errno;],
1078                         [ol_cv_errno_thread_specific=yes],
1079                         [ol_cv_errno_thread_specific=no])
1080         ])
1081
1082         if test $ol_cv_errno_thread_specific != yes ; then
1083                 LIBS="$LTHREAD_LIBS $LIBS"
1084                 LTHREAD_LIBS=""
1085         fi
1086
1087 dnl When in thread environment, use 
1088 dnl             #if defined( HAVE_REENTRANT_FUNCTIONS ) \ 
1089 dnl                     || defined( HAVE_FUNC_R )
1090 dnl                     func_r(...);
1091 dnl             #else
1092 dnl             #       if defined( HAVE_THREADS ) 
1093 dnl                             /* lock */
1094 dnl             #       endif
1095 dnl                             func(...);
1096 dnl             #       if defined( HAVE_THREADS ) 
1097 dnl                             /* unlock */
1098 dnl             #       endif
1099 dnl             #endif
1100 dnl
1101 dnl HAVE_REENTRANT_FUNCTIONS is derived from:
1102 dnl             _POSIX_REENTRANT_FUNCTIONS
1103 dnl             _POSIX_THREAD_SAFE_FUNCTIONS
1104 dnl             _POSIX_THREADSAFE_FUNCTIONS
1105 dnl
1106 dnl             and is currently defined in lthread.h
1107 dnl
1108 dnl HAVE_THREADS is defined by lthread.h iff -UNO_THREADS
1109 dnl 
1110 dnl libldap/*.c should only include <lthread.h> iff
1111 dnl LDAP_R_COMPILE is defined.  ie:
1112 dnl             #ifdef LDAP_R_COMPILE
1113 dnl             #       include LDAP_R_COMPILE
1114 dnl             #endif
1115 dnl
1116 dnl LDAP_R_COMIPLE is defined by libldap_r/Makefile.in
1117 dnl specifically for compiling the threadsafe version of
1118 dnl     the ldap library (-lldap_r).
1119 dnl             
1120 dnl     dnl check for reentrant/threadsafe functions
1121 dnl     dnl
1122 dnl     dnl note: these should only be used when linking
1123 dnl     dnl       with $LTHREAD_LIBS
1124 dnl     dnl
1125 dnl     save_CPPFLAGS="$CPPFLAGS"
1126 dnl     save_LIBS="$LIBS"
1127 dnl     LIBS="$LTHREAD_LIBS $LIBS"
1128 dnl     AC_CHECK_FUNCS( \
1129 dnl             strtok_r \
1130 dnl             gmtime_r \
1131 dnl             gethostbyaddr_r gethostbyname_r \
1132 dnl             feof_unlocked unlocked_feof \
1133 dnl             putc_unlocked unlocked_putc \
1134 dnl             flockfile ftrylockfile \
1135 dnl     )
1136 dnl     CPPFLAGS="$save_CPPFLAGS"
1137 dnl     LIBS="$save_LIBS"
1138 fi  
1139
1140 dnl ----------------------------------------------------------------
1141
1142 if test $ol_link_threads = no ; then
1143         if test $ol_with_threads = yes ; then
1144                 AC_MSG_ERROR([no suitable thread support])
1145         fi
1146
1147         if test $ol_with_threads = auto ; then
1148                 AC_MSG_WARN([no suitable thread support, disabling threads])
1149                 ol_with_threads=no
1150         fi
1151
1152         AC_DEFINE(NO_THREADS,1,
1153                 [define if you have (or want) no threads])
1154         LTHREAD_LIBS=""
1155 fi
1156
1157 ol_link_ldbm=no 
1158 if test $ol_with_ldbm_api = auto -o $ol_with_ldbm_api = db2 ; then
1159         OL_BERKELEY_DB2
1160
1161         if test $ol_cv_berkeley_db2 = yes ; then
1162                 ol_link_ldbm=db2
1163                 ol_with_ldbm_api=db2
1164
1165                 if test $ol_with_ldbm_type = hash ; then
1166                         AC_DEFINE(LDBM_USE_DBHASH,1)
1167                 else
1168                         AC_DEFINE(LDBM_USE_DBBTREE,1)
1169                 fi
1170
1171                 dnl $ol_cv_lib_db2 should be yes or -ldb
1172                 dnl (it could be no, but that would be an error
1173                 if test $ol_cv_lib_db2 != yes ; then
1174                         LDBM_LIBS="$LDBM_LIBS $ol_cv_lib_db2"
1175                 fi
1176         fi
1177 fi
1178
1179 ol_link_bdb2=no
1180 if test $ol_link_ldbm = db2 -a $ol_enable_bdb2 != no ; then
1181         ol_link_bdb2=yes
1182 fi
1183
1184 if test $ol_with_ldbm_api = auto -o $ol_with_ldbm_api = db ; then
1185         OL_BERKELEY_DB
1186
1187         if test $ol_cv_berkeley_db = yes ; then
1188                 ol_link_ldbm=db
1189                 ol_with_ldbm_api=db
1190
1191                 if test $ol_with_ldbm_type = hash ; then
1192                         AC_DEFINE(LDBM_USE_DBHASH,1)
1193                 else
1194                         AC_DEFINE(LDBM_USE_DBBTREE,1)
1195                 fi
1196
1197                 dnl $ol_cv_lib_db should be yes or -ldb
1198                 dnl (it could be no, but that would be an error
1199                 if test $ol_cv_lib_db != yes ; then
1200                         LDBM_LIBS="$LDBM_LIBS $ol_cv_lib_db"
1201                 fi
1202         fi
1203 fi
1204
1205 if test $ol_with_ldbm_api = manual ; then
1206         dnl User thinks he can manually configure LDBM api.
1207         ol_link_ldbm=yes
1208
1209         AC_MSG_WARN([LDBM defines and link options must be set manually])
1210
1211         AC_CHECK_HEADERS(db.h db_185.h gdbm.h ndbm.h)
1212 fi
1213
1214 if test $ol_link_ldbm = no -a $ol_with_ldbm_type = btree ; then
1215         AC_MSG_WARN(Could not find LDBM with BTREE support)
1216         ol_with_ldbm_api=none
1217 fi
1218
1219 if test $ol_with_ldbm_api = auto -o $ol_with_ldbm_api = gdbm ; then
1220         OL_GDBM
1221
1222         if test $ol_cv_gdbm = yes ; then
1223                 ol_link_ldbm=gdbm
1224                 ol_with_ldbm_api=gdbm
1225
1226                 if test $ol_cv_lib_gdbm != yes ; then
1227                         LDBM_LIBS="$LDBM_LIBS $ol_cv_lib_gdbm"
1228                 fi
1229         fi
1230 fi
1231
1232 if test $ol_with_ldbm_api = auto ; then
1233         AC_MSG_WARN([skipping automatic checking for NDBM, must be manually enabled.])
1234 elif test $ol_with_ldbm_api = ndbm ; then
1235         OL_NDBM
1236
1237         if test $ol_cv_ndbm = yes ; then
1238                 ol_link_ldbm=ndbm
1239                 ol_with_ldbm_api=ndbm
1240
1241                 if test $ol_cv_lib_ndbm != yes ; then
1242                         LDBM_LIBS="$LDBM_LIBS $ol_cv_lib_ndbm"
1243                 fi
1244         fi
1245 fi
1246
1247 if test $ol_link_ldbm = no -a $ol_enable_ldbm != no ; then
1248         AC_MSG_WARN(could not find suitable LDBM backend)
1249         if test $ol_enable_ldbm = yes ; then
1250                 AC_MSG_ERROR(select appropriate LDBM options or disable)
1251         fi
1252
1253         AC_MSG_WARN(disabling LDBM)
1254         ol_enable_ldbm=no
1255 fi
1256
1257 if test $ol_enable_wrappers != no ; then
1258         AC_CHECK_HEADERS(tcpd.h)
1259
1260         if test $ac_cv_header_tcpd_h != yes ; then
1261                 have_wrappers=no
1262         else
1263                 AC_CHECK_LIB(wrap, main,
1264                         [have_wrappers=yes], [have_wrappers=no])
1265         fi
1266
1267         if test $have_wrappers = yes ; then
1268                 AC_DEFINE(HAVE_TCPD,1, [define if you have -lwrap])
1269                 SLAPD_LIBS="$SLAPD_LIBS -lwrap"
1270         else
1271                 AC_MSG_WARN(could not find -lwrap)
1272                 if test $ol_enable_wrappers = yes ; then
1273                         AC_MSG_ERROR(could not find wrappers, select appropriate options or disable)
1274                 fi
1275
1276                 AC_MSG_WARN(disabling wrappers support)
1277                 ol_enable_wrappers=no
1278         fi
1279 fi
1280
1281 if test $ol_enable_syslog != no ; then
1282         AC_CHECK_FUNC(openlog)
1283         if test $ac_cv_func_openlog = no -a $ol_enable_syslog = yes; then
1284                 AC_MSG_ERROR(could not find syslog, select appropriate options or disable)
1285         fi
1286         ol_enable_syslog=$ac_cv_func_openlog
1287 fi
1288
1289 if test $ol_enable_dmalloc != no ; then
1290         AC_CHECK_HEADERS(dmalloc.h)
1291         AC_CHECK_LIB(dmalloc, dmalloc_shutdown)
1292 fi
1293
1294 # ud needs termcap (should insert check here)
1295 ol_link_termcap=no
1296 AC_CHECK_HEADERS(termcap.h ncurses.h)
1297
1298 if test $ol_link_termcap = no ; then
1299         AC_CHECK_LIB(termcap, tputs, [have_termcap=yes], [have_termcap=no])
1300         if test $have_termcap = yes ; then
1301                 AC_DEFINE(HAVE_TERMCAP, 1, [define if you have -ltermcap])
1302                 ol_link_termcap=yes
1303                 TERMCAP_LIBS=-ltermcap
1304         fi
1305 fi
1306
1307 if test $ol_link_termcap = no ; then
1308         AC_CHECK_LIB(ncurses, initscr, [have_ncurses=yes], [have_ncurses=no])
1309         if test $have_ncurses = yes ; then
1310                 AC_DEFINE(HAVE_NCURSES, 1, [define if you have -lncurses])
1311                 ol_link_termcap=yes
1312                 TERMCAP_LIBS=-lncurses
1313         fi
1314 fi
1315
1316 if test $ol_link_termcap = no ; then
1317         AC_DEFINE(NO_TERMCAP,1, [define if you have no termcap support])
1318         TERMCAP_LIBS=
1319 fi
1320
1321 # FreeBSD (and others) have crypt(3) in -lcrypt
1322 if test $ol_enable_crypt != no ; then
1323         AC_CHECK_FUNC(crypt, [have_crypt=yes], [
1324                 AC_CHECK_LIB(crypt, crypt, [LUTIL_LIBS="$LUTIL_LIBS -lcrypt"
1325                         have_crypt=yes], [have_crypt=no])])
1326
1327         if test $have_crypt = yes ; then
1328                 AC_DEFINE(HAVE_CRYPT,1)
1329         else
1330                 AC_MSG_WARN(could not find crypt)
1331                 if test $ol_enable_crypt = yes ; then
1332                         AC_MSG_ERROR(could not find crypt, select appropriate options or disable)
1333                 fi
1334
1335                 AC_MSG_WARN(disabling crypt support)
1336                 ol_enable_crypt=no
1337         fi
1338 fi
1339
1340 # FreeBSD (and others) have setproctitle(3) in -lutil
1341 if test $ol_enable_proctitle != no ; then
1342         AC_CHECK_FUNC(setproctitle,     [have_setproctitle=yes], [
1343                 AC_CHECK_LIB(util, setproctitle,
1344                         [have_setproctitle=yes
1345                         LUTIL_LIBS="$LUTIL_LIBS -lutil"],
1346                         [have_setproctitle=no
1347                         LIBOBJS="$LIBOBJS setproctitle.o"])])
1348
1349         if test $have_setproctitle = yes ; then
1350                 AC_DEFINE(HAVE_SETPROCTITLE,1)
1351         fi
1352 fi
1353
1354 dnl ----------------------------------------------------------------
1355 dnl Checks for header files.
1356 AC_HEADER_STDC
1357
1358 if test $ac_cv_header_stdc != yes; then
1359         AC_MSG_WARN([could not Standard C compliant headers])
1360 fi
1361
1362 AC_HEADER_DIRENT
1363 AC_HEADER_SYS_WAIT
1364 AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
1365 if test $am_cv_sys_posix_termios = yes ; then
1366         AC_DEFINE(HAVE_POSIX_TERMIOS,1,
1367                 [define if you have POSIX termios])
1368 fi
1369
1370 AC_CHECK_HEADERS(       \
1371         arpa/nameser.h  \
1372         crypt.h                 \
1373         errno.h                 \
1374         fcntl.h                 \
1375         filio.h                 \
1376         getopt.h                \
1377         libutil.h               \
1378         limits.h                \
1379         malloc.h                \
1380         memory.h                \
1381         regex.h                 \
1382         psap.h                  \
1383         pwd.h                   \
1384         resolv.h                \
1385         sgtty.h                 \
1386         stdarg.h                \
1387         stddef.h                \
1388         string.h                \
1389         strings.h               \
1390         sysexits.h              \
1391         sys/file.h              \
1392         sys/filio.h             \
1393         sys/errno.h             \
1394         sys/ioctl.h             \
1395         sys/param.h             \
1396         sys/resource.h  \
1397         sys/socket.h    \
1398         sys/syslog.h    \
1399         sys/time.h              \
1400         sys/types.h             \
1401         syslog.h                \
1402         termios.h               \
1403         unistd.h                \
1404 )
1405
1406 dnl ----------------------------------------------------------------
1407 dnl Checks for typedefs, structures, and compiler characteristics.
1408 AC_TYPE_GETGROUPS dnl requires AC_TYPE_UID_T
1409 AC_TYPE_MODE_T
1410 AC_TYPE_OFF_T
1411 AC_TYPE_PID_T
1412 AM_TYPE_PTRDIFF_T
1413 AC_TYPE_SIGNAL
1414 OL_TYPE_SIG_ATOMIC_T
1415 AC_TYPE_SIZE_T
1416 AC_STRUCT_ST_BLKSIZE
1417 AC_HEADER_TIME
1418 AC_STRUCT_TM
1419
1420 OL_C_UPPER_LOWER
1421 AC_C_CONST
1422 OL_C_VOLATILE
1423
1424 if test $cross_compiling = yes ; then
1425         AC_DEFINE(CROSS_COMPILING, 1, [define if cross compiling])
1426 else
1427         AC_C_BIGENDIAN
1428         AC_CHECK_SIZEOF(short) 
1429         AC_CHECK_SIZEOF(int) 
1430         AC_CHECK_SIZEOF(long)
1431 fi
1432
1433 dnl ----------------------------------------------------------------
1434 dnl Checks for library functions.
1435 AC_FUNC_MEMCMP
1436 dnl AM_FUNC_MKTIME dnl checks for sys/time.h and unistd.h
1437 AC_FUNC_STRFTIME
1438 dnl AM_FUNC_STRTOD
1439 AC_FUNC_VPRINTF
1440
1441 if test $ac_cv_func_vprintf = yes ; then
1442         dnl check for vsnprintf
1443         AC_CHECK_FUNCS(vsnprintf vsprintf)
1444 fi
1445
1446 AC_CHECK_FUNCS(         \
1447         bcopy                   \
1448         flock                   \
1449         getdtablesize   \
1450         gethostname             \
1451         getpwuid                \
1452         gettimeofday    \
1453         lockf                   \
1454         memcpy                  \
1455         memmove                 \
1456         mkstemp                 \
1457         select                  \
1458         setpwfile               \
1459         setsid                  \
1460         signal                  \
1461         sigset                  \
1462         snprintf                \
1463         socket                  \
1464         strdup                  \
1465         strerror                \
1466         strpbrk                 \
1467         strrchr                 \
1468         strsep                  \
1469         strstr                  \
1470         strtok                  \
1471         strtol                  \
1472         strtoul                 \
1473         strspn                  \
1474         sysconf                 \
1475         waitpid                 \
1476 )
1477
1478 # these functions are required to build a thread_safe -lldap
1479 AC_CHECK_FUNCS(         \
1480         strtok_r                \
1481         ctime_r                 \
1482         gethostbyaddr_r \
1483         gethostbyname_r \
1484 )
1485
1486 if test "$ac_cv_func_ctime_r" = yes ; then
1487         OL_FUNC_CTIME_R_NARGS
1488 else
1489         ol_cv_func_ctime_r=0
1490 fi
1491
1492 if test "$ac_cv_func_strtok_r" = yes \
1493         -a "$ac_cv_func_ctime_r" = yes \
1494         -a "$ol_cv_func_ctime_r_nargs" -ge 2 -a "$ol_cv_func_ctime_r_nargs" -le 3 \
1495         -a "$ac_cv_func_gethostbyaddr_r" = yes \
1496         -a "$ac_cv_func_gethostbyname_r" = yes \
1497         ; then
1498
1499         AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_REENTRANT, 1)
1500 fi
1501
1502 if test $ol_link_threads != no ; then
1503         AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE, 1)
1504 fi
1505
1506 dnl We actually may need to replace more than this.
1507 AC_REPLACE_FUNCS(getopt tempnam)
1508
1509 dnl ----------------------------------------------------------------
1510 # Check Configuration
1511 OL_SYS_ERRLIST
1512
1513 dnl ----------------------------------------------------------------
1514 dnl Sort out defines
1515
1516 if test "$ol_enable_debug" != no ; then
1517         AC_DEFINE(LDAP_DEBUG,1)
1518 fi
1519 if test "$ol_enable_syslog" = yes ; then
1520         AC_DEFINE(LDAP_SYSLOG,1)
1521 fi
1522 if test "$ol_enable_libui" = yes ; then
1523         AC_DEFINE(LDAP_LIBUI,1)
1524 fi
1525 if test "$ol_enable_cache" = no ; then
1526         AC_DEFINE(LDAP_NOCACHE,1)
1527 fi
1528 if test "$ol_enable_dns" != no ; then
1529         AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_V2_DNS,LDAP_VENDOR_VERSION)
1530 fi
1531 if test "$ol_enable_proctitle" != no ; then
1532         AC_DEFINE(LDAP_PROCTITLE,1)
1533 fi
1534 if test "$ol_enable_referrals" != no ; then
1535         AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS,LDAP_VENDOR_VERSION)
1536 fi
1537 if test "$ol_enable_cldap" != no ; then
1538         AC_DEFINE(LDAP_CONNECTIONLESS,1)
1539 fi
1540
1541 if test "$ol_enable_aclgroups" != no ; then
1542         AC_DEFINE(SLAPD_ACLGROUPS,1)
1543 fi
1544 if test "$ol_enable_crypt" != no ; then
1545         AC_DEFINE(SLAPD_CRYPT,1)
1546 fi
1547 if test "$ol_enable_cleartext" != no ; then
1548         AC_DEFINE(SLAPD_CLEARTEXT,1)
1549 fi
1550 if test "$ol_enable_phonetic" != no ; then
1551         AC_DEFINE(SLAPD_PHONETIC,1)
1552 fi
1553 if test "$ol_enable_rlookups" != no ; then
1554         AC_DEFINE(SLAPD_RLOOKUPS,1)
1555 fi
1556
1557 if test "$ol_link_bdb2" != no ; then
1558         AC_DEFINE(SLAPD_BDB2,1)
1559         BUILD_SLAPD=yes
1560         BUILD_BDB2=yes
1561 fi
1562
1563 if test "$ol_link_ldbm" != no ; then
1564         AC_DEFINE(SLAPD_LDBM,1)
1565         BUILD_SLAPD=yes
1566         BUILD_LDBM=yes
1567 fi
1568
1569 if test "$ol_enable_passwd" != no ; then
1570         AC_DEFINE(SLAPD_PASSWD,1)
1571         BUILD_SLAPD=yes
1572         BUILD_PASSWD=yes
1573 fi
1574
1575 if test "$ol_enable_perl" != no ; then
1576         AC_DEFINE(SLAPD_PERL,1)
1577         BUILD_SLAPD=yes
1578         BUILD_PERL=yes
1579 fi
1580
1581 if test "$ol_enable_shell" != no ; then
1582         AC_DEFINE(SLAPD_SHELL,1)
1583         BUILD_SLAPD=yes
1584         BUILD_SHELL=yes
1585 fi
1586
1587 if test "$ol_enable_slurpd" != no -a "$ol_link_threads" != no -a \
1588         $BUILD_SLAPD = yes ; then
1589         BUILD_SLURPD=yes
1590 fi
1591
1592 if test "$ol_link_isode" != no ; then
1593         BUILD_LDAPD=yes
1594 fi
1595
1596 dnl ----------------------------------------------------------------
1597
1598 AC_SUBST(BUILD_LDAPD)
1599 AC_SUBST(BUILD_SLAPD)
1600   AC_SUBST(BUILD_BDB2)
1601   AC_SUBST(BUILD_LDBM)
1602   AC_SUBST(BUILD_PASSWD)
1603   AC_SUBST(BUILD_PERL)
1604   AC_SUBST(BUILD_SHELL)
1605 AC_SUBST(BUILD_SLURPD)
1606
1607 AC_SUBST(LDAP_LIBS)
1608 AC_SUBST(LDAPD_LIBS)
1609 AC_SUBST(SLAPD_LIBS)
1610 AC_SUBST(SLURPD_LIBS)
1611 AC_SUBST(LDBM_LIBS)
1612 AC_SUBST(LTHREAD_LIBS)
1613 AC_SUBST(LUTIL_LIBS)
1614
1615 AC_SUBST(SLAPD_PERL_CPPFLAGS)
1616 AC_SUBST(SLAPD_PERL_LDFLAGS)
1617
1618 AC_SUBST(KRB_LIBS)
1619 AC_SUBST(TERMCAP_LIBS)
1620
1621 dnl ----------------------------------------------------------------
1622 dnl final output
1623 dnl
1624
1625 AC_OUTPUT( \
1626 Makefile:build/top.mk:Makefile.in:build/dir.mk \
1627 doc/Makefile:build/top.mk:doc/Makefile.in:build/dir.mk \
1628 doc/man/Makefile:build/top.mk:doc/man/Makefile.in:build/dir.mk \
1629 doc/man/man1/Makefile:build/top.mk:doc/man/man1/Makefile.in:build/man.mk \
1630 doc/man/man3/Makefile:build/top.mk:doc/man/man3/Makefile.in:build/man.mk \
1631 doc/man/man5/Makefile:build/top.mk:doc/man/man5/Makefile.in:build/man.mk \
1632 doc/man/man8/Makefile:build/top.mk:doc/man/man8/Makefile.in:build/man.mk \
1633 clients/Makefile:build/top.mk:clients/Makefile.in:build/dir.mk \
1634 clients/finger/Makefile:build/top.mk:clients/finger/Makefile.in:build/rules.mk \
1635 clients/fax500/Makefile:build/top.mk:clients/fax500/Makefile.in:build/rules.mk \
1636 clients/gopher/Makefile:build/top.mk:clients/gopher/Makefile.in:build/rules.mk \
1637 clients/mail500/Makefile:build/top.mk:clients/mail500/Makefile.in:build/rules.mk \
1638 clients/rcpt500/Makefile:build/top.mk:clients/rcpt500/Makefile.in:build/rules.mk \
1639 clients/ud/Makefile:build/top.mk:clients/ud/Makefile.in:build/rules.mk \
1640 clients/tools/Makefile:build/top.mk:clients/tools/Makefile.in:build/rules.mk \
1641 include/Makefile:build/top.mk:include/Makefile.in \
1642 libraries/Makefile:build/top.mk:libraries/Makefile.in:build/dir.mk      \
1643 libraries/libavl/Makefile:build/top.mk:libraries/libavl/Makefile.in:build/lib.mk:build/lib-static.mk    \
1644 libraries/liblber/Makefile:build/top.mk:libraries/liblber/Makefile.in:build/lib.mk:build/lib-shared.mk  \
1645 libraries/libldap/Makefile:build/top.mk:libraries/libldap/Makefile.in:build/lib.mk:build/lib-shared.mk  \
1646 libraries/libldap_r/Makefile:build/top.mk:libraries/libldap_r/Makefile.in:build/lib.mk:build/lib-shared.mk      \
1647 libraries/libldbm/Makefile:build/top.mk:libraries/libldbm/Makefile.in:build/lib.mk:build/lib-static.mk  \
1648 libraries/libldif/Makefile:build/top.mk:libraries/libldif/Makefile.in:build/lib.mk:build/lib-static.mk  \
1649 libraries/liblutil/Makefile:build/top.mk:libraries/liblutil/Makefile.in:build/lib.mk:build/lib-static.mk        \
1650 servers/Makefile:build/top.mk:servers/Makefile.in:build/dir.mk \
1651 servers/ldapd/Makefile:build/top.mk:servers/ldapd/Makefile.in:build/srv.mk \
1652 servers/slapd/Makefile:build/top.mk:servers/slapd/Makefile.in:build/srv.mk \
1653 servers/slapd/back-bdb2/Makefile:build/top.mk:servers/slapd/back-bdb2/Makefile.in:build/srv.mk \
1654 servers/slapd/back-ldbm/Makefile:build/top.mk:servers/slapd/back-ldbm/Makefile.in:build/srv.mk \
1655 servers/slapd/back-passwd/Makefile:build/top.mk:servers/slapd/back-passwd/Makefile.in:build/srv.mk \
1656 servers/slapd/back-perl/Makefile:build/top.mk:servers/slapd/back-perl/Makefile.in:build/srv.mk \
1657 servers/slapd/back-shell/Makefile:build/top.mk:servers/slapd/back-shell/Makefile.in:build/srv.mk \
1658 servers/slapd/shell-backends/Makefile:build/top.mk:servers/slapd/shell-backends/Makefile.in:build/srv.mk \
1659 servers/slapd/tools/Makefile:build/top.mk:servers/slapd/tools/Makefile.in \
1660 servers/slurpd/Makefile:build/top.mk:servers/slurpd/Makefile.in:build/srv.mk \
1661 tests/Makefile:build/top.mk:tests/Makefile.in \
1662 ,[
1663 date > stamp-h
1664 echo Please \"make depend\" to build dependencies
1665 ])