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