]> git.sur5r.net Git - openldap/blob - configure.in
Fix idl_firstid to return NOID when !(nids > 1) instead of when (nids == 1)
[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_lock() in -lpthread -lexc (OSF/1)
469                 dnl 6)  pthread_mutex_unlock() in -lpthread -lmach -lexc -lc_r (OSF/1)
470                 dnl 7)  pthread_create() in -lpthread (many)
471                 dnl 8)  pthread_create() in -lc_r (FreeBSD)
472                 dnl 9)  pthread_create() in -lpthreads (many)
473                 dnl 10) pthread_join() -Wl,-woff,85 -lpthreads (IRIX)
474                 dnl 11) pthread_create() in HP-UX -lpthread (HP-UX 11)
475                 dnl
476                 dnl Check pthread (draft4) flags (to be depreciated)
477                 dnl 12) pthread_create() with -threads (OSF/1)
478                 dnl
479                 dnl Check pthread (final) libraries (to be depreciated)
480                 dnl 13) pthread_mutex_lock() in -lpthreads -lexc (OSF/1)
481                 dnl 14) pthread_mutex_unlock() in -lpthreads -lmach -lexc -lc_r (OSF/1)
482                 dnl
483
484                 dnl pthread_create in $LIBS
485                 AC_CHECK_FUNC(pthread_create,[ol_link_threads=yes])
486
487                 if test $ol_link_threads = no ; then
488                         dnl try -kthread
489                         AC_CACHE_CHECK([for pthread_create with -kthread],
490                                 [ol_cv_kthread_flag], [
491                                 dnl save the flags
492                                 save_LIBS="$LIBS"
493                                 LIBS="-kthread $LIBS"
494                                 AC_TRY_LINK([char pthread();],[
495                                         pthread_create();
496                                         ], ol_cv_kthread_flag=yes, ol_cv_kthread_flag=no)
497                                 dnl restore the LIBS
498                                 LIBS="$save_LIBS"
499                         ])
500
501                         if test $ol_cv_kthread_flag = yes ; then
502                                 LTHREAD_LIBS="$LTHREAD_LIBS -kthread"
503                                 ol_link_threads=posix
504                         fi
505                 fi
506
507                 if test $ol_link_threads = no ; then
508                         dnl try -pthread
509                         AC_CACHE_CHECK([for pthread_create with -pthread],
510                                 [ol_cv_pthread_flag], [
511                                 dnl save the flags
512                                 save_LIBS="$LIBS"
513                                 LIBS="-pthread $LIBS"
514                                 AC_TRY_LINK([char pthread();],[
515                                         pthread_create();
516                                         ], ol_cv_pthread_flag=yes, ol_cv_pthread_flag=no)
517                                 dnl restore the LIBS
518                                 LIBS="$save_LIBS"
519                         ])
520
521                         if test $ol_cv_pthread_flag = yes ; then
522                                 LTHREAD_LIBS="$LTHREAD_LIBS -pthread"
523                                 ol_link_threads=posix
524                         fi
525                 fi
526
527                 if test $ol_link_threads = no ; then
528                         dnl try -pthreads
529                         AC_CACHE_CHECK([for pthread_create with -pthreads],
530                                 [ol_cv_pthreads_flag], [
531                                 dnl save the flags
532                                 save_LIBS="$LIBS"
533                                 LIBS="-pthreads $LIBS"
534                                 AC_TRY_LINK([char pthread();],[
535                                         pthread_create();
536                                         ], ol_cv_pthreads_flag=yes, ol_cv_pthreads_flag=no)
537                                 dnl restore the LIBS
538                                 LIBS="$save_LIBS"
539                         ])
540
541                         if test $ol_cv_pthreads_flag = yes ; then
542                                 LTHREAD_LIBS="$LTHREAD_LIBS -pthreads"
543                                 ol_link_threads=posix
544                         fi
545                 fi
546
547                 if test $ol_link_threads = no ; then
548                         dnl try -thread
549                         AC_CACHE_CHECK([for pthread_create with -thread],
550                                 [ol_cv_thread_flag], [
551                                 dnl save the flags
552                                 save_LIBS="$LIBS"
553                                 LIBS="-thread $LIBS"
554                                 AC_TRY_LINK([char pthread();],[
555                                         pthread_create();
556                                         ], ol_cv_thread_flag=yes, ol_cv_thread_flag=no)
557                                 dnl restore the LIBS
558                                 LIBS="$save_LIBS"
559                         ])
560
561                         if test $ol_cv_thread_flag = yes ; then
562                                 LTHREAD_LIBS="$LTHREAD_LIBS -thread"
563                                 ol_link_threads=posix
564                         fi
565                 fi
566
567                 if test $ol_link_threads = no ; then
568                         dnl try DEC Threads -lpthread -lexc
569                         save_LIBS="$LIBS"
570                         AC_CHECK_LIB(pthread, pthread_mutex_lock, [
571                                 ol_link_threads=posix
572                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthread -lexc"
573                                 if test $ol_with_yielding_select = auto ; then
574                                         ol_with_yielding_select=yes
575                                 fi
576                                 ],:,[-lexc])
577                         LIBS="$save_LIBS"
578                 fi
579
580                 if test $ol_link_threads = no ; then
581                         dnl try DEC Threads -lpthread -lmach -lexc -lc_r
582                         save_LIBS="$LIBS"
583                         AC_CHECK_LIB(pthread, pthread_mutex_unlock, [
584                                 ol_link_threads=posix
585                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthread -lmach -lexc -lc_r"
586                                 if test $ol_with_yielding_select = auto ; then
587                                         ol_with_yielding_select=yes
588                                 fi
589                                 ],:,[-lmach -lexc -lc_r])
590                         LIBS="$save_LIBS"
591                 fi
592
593                 if test $ol_link_threads = no ; then
594                         dnl try -lpthread
595                         save_LIBS="$LIBS"
596                         AC_CHECK_LIB(pthread, pthread_create, [
597                                 ol_link_threads=posix
598                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthread"],:)
599                         LIBS="$save_LIBS"
600                 fi
601
602                 if test $ol_link_threads = no ; then
603                         dnl try -lc_r
604                         save_LIBS="$LIBS"
605                         AC_CHECK_LIB(c_r, pthread_create, [
606                                 ol_link_threads=posix
607                                 LTHREAD_LIBS="$LTHREAD_LIBS -lc_r"],:)
608                         LIBS="$save_LIBS"
609                 fi
610
611                 if test $ol_link_threads = no ; then
612                         dnl try -lpthreads
613                         save_LIBS="$LIBS"
614                         AC_CHECK_LIB(pthreads, pthread_create, [
615                                 ol_link_threads=posix
616                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthreads"],:)
617                         LIBS="$save_LIBS"
618                 fi
619
620                 dnl IRIX Pthread check
621                 if test $ol_link_threads = no ; then
622                         dnl try IRIX Pthreads -Wl,-woff,85 -lpthreads
623                         save_LIBS="$LIBS"
624                         AC_CHECK_LIB(pthreads, pthread_join, [
625                                 ol_link_threads=posix
626                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthreads"
627                                 ],:,[-Wl,-woff,85])
628                         LIBS="$save_LIBS"
629                 fi
630
631                 dnl HP-UX 11 Pthread check
632                 if test $ol_link_threads = no; then
633                         save_LIBS="$LIBS"
634                         LIBS="$LIBS -lpthread"
635                         AC_MSG_CHECKING([for pthread_create() in HP-UX -lpthread])
636                         ol_try_pthread_hpux_11=no
637                         AC_CACHE_VAL(ol_cv_pthread_hpux_11,[
638                                 AC_TRY_LINK([
639 #include <pthread.h>
640 #include <elf.h>
641 #ifndef ELFABI_HPUX_REL11
642         die horribly
643 #endif
644                                 ], [pthread_create(NULL, NULL, NULL, NULL);],
645                                         ol_try_pthread_hpux_11=yes
646                                         ol_cv_pthread_hpux_11=yes,
647                                         ol_cv_pthread_hpux_11=no)])
648                         AC_MSG_RESULT(yes)
649                         LIBS="$save_LIBS"
650
651                         if test $ol_cv_pthread_hpux_11=yes ; then
652                                 ol_link_threads=posix
653                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthread"
654                                 if test $ol_try_pthread_hpux_11=yes ; then
655                                         dnl Some tests below may fail, cause we aint including
656                                         dnl pthread.h. Force appropriate ones to yes
657                                         ac_cv_func_pthread_attr_init=yes
658                                 fi
659                         fi
660                 fi
661
662                 if test $ol_link_threads = no ; then
663                         dnl try -threads
664                         AC_CACHE_CHECK([for pthread_create with -threads],
665                                 [ol_cv_thread_flag], [
666                                 dnl save the flags
667                                 save_LIBS="$LIBS"
668                                 LIBS="-threads $LIBS"
669                                 AC_TRY_LINK([char pthread();],[
670                                         pthread_create();
671                                         ], ol_cv_thread_flag=yes, ol_cv_thread_flag=no)
672                                 dnl restore the LIBS
673                                 LIBS="$save_LIBS"
674                         ])
675
676                         if test $ol_cv_thread_flag = yes ; then
677                                 LTHREAD_LIBS="$LTHREAD_LIBS -threads"
678                                 ol_link_threads=posix
679                         fi
680                 fi
681
682                 if test $ol_link_threads = no ; then
683                         dnl try DEC Threads -lpthreads -lexc
684                         save_LIBS="$LIBS"
685                         AC_CHECK_LIB(pthreads, pthread_mutex_lock, [
686                                 ol_link_threads=posix
687                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthreads -lexc"
688                                 if test $ol_with_yielding_select = auto ; then
689                                         ol_with_yielding_select=yes
690                                 fi
691                                 ],:,[-lexc])
692                         LIBS="$save_LIBS"
693                 fi
694
695                 if test $ol_link_threads = no ; then
696                         dnl try DEC Threads -lpthreads -lmach -lexc -lc_r
697                         save_LIBS="$LIBS"
698                         AC_CHECK_LIB(pthreads, pthread_mutex_unlock, [
699                                 ol_link_threads=posix
700                                 LTHREAD_LIBS="$LTHREAD_LIBS -lpthreads -lmach -lexc -lc_r"
701                                 if test $ol_with_yielding_select = auto ; then
702                                         ol_with_yielding_select=yes
703                                 fi
704                                 ],:,[-lmach -lexc -lc_r])
705                         LIBS="$save_LIBS"
706                 fi
707
708                 if test $ol_link_threads != no ; then
709                         AC_DEFINE(HAVE_PTHREADS)
710
711                         dnl save flags
712                         save_CPPFLAGS="$CPPFLAGS"
713                         save_LIBS="$LIBS"
714                         LIBS="$LTHREAD_LIBS $LIBS"
715
716                         dnl All POSIX Thread (final) implementations should have
717                         dnl sched_yield instead of pthread yield.
718                         dnl check for both
719                         AC_CHECK_FUNCS(sched_yield pthread_yield)
720
721                         if test $ac_cv_func_sched_yield = no -a \
722                                 $ac_cv_func_pthread_yield = no ; then
723                                 dnl Digital UNIX has sched_yield() in -lrt
724                                 AC_CHECK_LIB(rt, sched_yield,
725                                         [LTHREAD_LIBS="$LTHREAD_LIBS -lrt"
726                                         AC_DEFINE(HAVE_SCHED_YIELD,1)
727                                         ac_cv_func_sched_yield=yes],
728                                         [ac_cv_func_sched_yield=no])
729                         fi
730                         if test $ac_cv_func_sched_yield = no -a \
731                                 $ac_cv_func_pthread_yield = no ; then
732                                 dnl Solaris has sched_yield() in -lposix4
733                                 dnl but we'll use thr_yield instead.
734                                 AC_CHECK_FUNCS(thr_yield)
735                         fi
736                         if test $ac_cv_func_sched_yield = no -a \
737                                 $ac_cv_func_pthread_yield = no -a \
738                                 "$ac_cv_func_thr_yield" = no ; then
739                                 AC_MSG_WARN([could not locate sched_yield() or pthread_yield()])
740                         fi
741
742                         dnl Check functions for compatibility
743                         AC_CHECK_FUNCS(pthread_kill pthread_detach)
744
745                         if test $ac_cv_func_pthread_detach = no ; then
746                                 AC_MSG_ERROR([could not locate pthread_detach()])
747                         fi
748
749                         dnl Check for setconcurreny functions
750                         AC_CHECK_FUNCS( \
751                                 pthread_setconcurrency \
752                                 pthread_getconcurrency \
753                                 thr_setconcurrency \
754                                 thr_getconcurrency \
755                         )
756
757                         AC_MSG_CHECKING([if pthread_create() works])
758                         AC_CACHE_VAL(ol_cv_pthread_create_works,[
759                         AC_TRY_RUN([
760 #include <pthread.h>
761 #ifndef NULL
762 #define NULL (void*)0
763 #endif
764
765 static void *task(p)
766         void *p;
767 {
768         return (void *) (p == NULL);
769 }
770
771 int main(argc, argv)
772         int argc;
773         char **argv;
774 {
775         pthread_t t;
776         exit(pthread_create(&t, NULL, task, NULL));
777 }
778 ],
779                                 [ol_cv_pthread_create_works=yes],
780                                 [ol_cv_pthread_create_works=no],
781                                 [dnl assume yes
782                                 ol_cv_pthread_create_works=yes])])
783                         AC_MSG_RESULT($ol_cv_pthread_create_works)
784
785                         if test $ol_cv_pthread_create_works = no ; then
786                                 AC_MSG_ERROR([pthread.h and pthread_create are not compatible])
787                         fi
788
789                         dnl Check if select causes an yield
790                         if test $ol_with_yielding_select = auto ; then
791                                 AC_MSG_CHECKING([if select yields when using pthreads])
792                                 AC_CACHE_VAL(ol_cv_pthread_select_yields,[
793                                 AC_TRY_RUN([
794 #include <sys/types.h>
795 #include <sys/time.h>
796 #include <unistd.h>
797 #include <pthread.h>
798 #ifndef NULL
799 #define NULL (void*) 0
800 #endif
801
802 static int fildes[2];
803
804 static void *task(p)
805         void *p;
806 {
807         int i;
808         struct timeval tv;
809
810         fd_set rfds;
811
812         tv.tv_sec=10;
813         tv.tv_usec=0;
814
815         FD_ZERO(&rfds);
816         FD_SET(fildes[0], &rfds);
817
818         /* we're not interested in any fds */
819         i = select(FD_SETSIZE, &rfds, NULL, NULL, &tv);
820
821         if(i < 0) {
822                 perror("select");
823                 exit(10);
824         }
825
826         exit(0); /* if we exit here, the select blocked the whole process */
827 }
828
829 int main(argc, argv)
830         int argc;
831         char **argv;
832 {
833         pthread_t t;
834
835         /* create a pipe to select */
836         if(pipe(&fildes[0])) {
837                 perror("select");
838                 exit(1);
839         }
840
841 #ifdef HAVE_PTHREAD_SETCONCURRENCY
842         (void) pthread_setconcurrency(2);
843 #else
844 #ifdef HAVE_THR_SETCONCURRENCY
845         /* Set Solaris LWP concurrency to 2 */
846         thr_setconcurrency(2);
847 #endif
848 #endif
849
850         pthread_create(&t, NULL, task, NULL);
851
852 #if HAVE_SCHED_YIELD
853         sched_yield();  /* make sure task runs first */
854 #else
855 #ifdef HAVE_PTHREAD_YIELD
856         pthread_yield();        /* make sure task runs first */
857 #endif
858 #endif
859
860         exit(2);
861 }],
862                                 [ol_cv_pthread_select_yields=no],
863                                 [ol_cv_pthread_select_yields=yes], [
864                                 AC_MSG_ERROR([crossing compiling: use --with-yielding_select=yes|no|manual])])])
865                                 AC_MSG_RESULT($ol_cv_pthread_select_yields)
866
867                                 if test $ol_cv_pthread_select_yields = yes ; then
868                                         ol_with_yielding_select=yes
869                                 fi
870                         fi
871
872                         dnl restore flags
873                         CPPFLAGS="$save_CPPFLAGS"
874                         LIBS="$save_LIBS"
875                 else
876                         AC_MSG_ERROR([could not link with POSIX Threads])
877                 fi
878         fi
879
880         if test $ol_with_threads = posix ; then
881                 AC_MSG_ERROR([could not locate POSIX Threads])
882         fi
883 fi
884
885 if test $ol_with_threads = auto -o $ol_with_threads = yes \
886         -o $ol_with_threads = mach ; then
887
888         dnl check for Mach CThreads
889         AC_CHECK_HEADERS(mach/cthreads.h)
890         if test $ac_cv_header_mach_cthreads_h = yes ; then
891                 ol_with_threads=found
892
893                 dnl check for cthread support in current $LIBS
894                 AC_CHECK_FUNC(cthread_fork,[ol_link_threads=yes])
895
896                 if test $ol_link_threads = no ; then
897                         dnl try -all_load
898                         dnl this test needs work
899                         AC_CACHE_CHECK([for cthread_fork with -all_load],
900                                 [ol_cv_cthread_all_load], [
901                                 dnl save the flags
902                                 save_LIBS="$LIBS"
903                                 LIBS="-all_load $LIBS"
904                                 AC_TRY_LINK([#include <mach/cthreads.h>],[
905                                         cthread_fork((void *)0, (void *)0);
906                                         ], ol_cv_cthread_all_load=yes, ol_cv_cthread_all_load=no)
907                                 dnl restore the LIBS
908                                 LIBS="$save_LIBS"
909                         ])
910
911                         if test $ol_cv_cthread_all_load = yes ; then
912                                 LTHREAD_LIBS="$LTHREAD_LIBS -all_load"
913                                 ol_link_threads=mach
914                         fi
915                 fi
916
917                 if test $ol_link_threads != no ; then
918                         : check for cthread specific functionality here
919                         AC_DEFINE(HAVE_MACH_CTHREADS,1)
920                 else
921                         AC_MSG_ERROR([could not link with Mach CThreads])
922                 fi
923         fi
924
925         if test $ol_with_threads = mach ; then
926                 AC_MSG_ERROR([could not locate Mach CThreads])
927         fi
928 fi
929
930 if test $ol_with_threads = auto -o $ol_with_threads = yes \
931         -o $ol_with_threads = lwp ; then
932
933         dnl check for SunOS5 LWP
934         AC_CHECK_HEADERS(thread.h synch.h)
935         if test $ac_cv_header_thread_h = yes -a $ac_cv_header_synch_h = yes ; then
936                 AC_CHECK_LIB(thread, thr_create, [have_thr=yes], [have_thr=no])
937
938                 if test $have_thr = yes ; then
939                         AC_DEFINE(HAVE_THR)
940                         LTHREAD_LIBS="$LTHREAD_LIBS -lthread"
941                         ol_link_threads=thr
942
943                         if test $ol_with_yielding_select = auto ; then
944                                 ol_with_yielding_select=yes
945                         fi
946
947                         dnl Check for setconcurreny functions
948                         AC_CHECK_FUNCS( \
949                                 thr_setconcurrency \
950                                 thr_getconcurrency \
951                         )
952                 fi
953         fi
954
955         dnl check for SunOS4 LWP
956         AC_CHECK_HEADERS(lwp/lwp.h)
957         if test $ac_cv_header_lwp_lwp_h = yes ; then
958                 AC_CHECK_LIB(lwp, lwp_create, [have_lwp=yes], [have_lwp=no])
959
960                 if test $have_lwp = yes ; then
961                         AC_DEFINE(HAVE_LWP)
962                         LTHREAD_LIBS="$LTHREAD_LIBS -llwp"
963                         ol_link_threads=lwp
964
965                         if test $ol_with_yielding_select = auto ; then
966                                 ol_with_yielding_select=no
967                         fi
968                 fi
969         fi
970 fi
971
972 if test $ol_with_yielding_select = yes ; then
973         AC_DEFINE(HAVE_YIELDING_SELECT,1)
974 fi
975
976 if test $ol_with_threads = manual ; then
977         dnl User thinks he can manually configure threads.
978         ol_link_threads=yes
979
980         AC_MSG_WARN([thread defines and link options must be set manually])
981
982         AC_CHECK_HEADERS(pthread.h sched.h)
983         AC_CHECK_FUNCS(sched_yield pthread_yield)
984         OL_LINUX_THREADS
985
986         AC_CHECK_HEADERS(mach/cthreads.h)
987         AC_CHECK_HEADERS(lwp/lwp.h)
988         AC_CHECK_HEADERS(thread.h synch.h)
989 fi
990
991 if test $ol_link_threads != no ; then  
992         dnl needed to get reentrant/threadsafe versions
993         dnl
994         AC_DEFINE(REENTRANT,1)
995         AC_DEFINE(_REENTRANT,1)
996         AC_DEFINE(THREAD_SAFE,1)
997         AC_DEFINE(_THREAD_SAFE,1)
998         AC_DEFINE(THREADSAFE,1)
999         AC_DEFINE(_THREADSAFE,1)
1000
1001         dnl this might cause the errno symbol to be
1002         dnl replaced with a function to get a thread specific errno.
1003         dnl check to see if everything needs to be compiled
1004         dnl with the thread libraries
1005         AC_CACHE_CHECK([for thread specific errno],
1006                 [ol_cv_errno_thread_specific], [
1007                 AC_TRY_LINK([
1008 #include <errno.h>
1009                         ], [
1010 int x = errno;
1011                         ],
1012                         [ol_cv_errno_thread_specific=yes],
1013                         [ol_cv_errno_thread_specific=no])
1014         ])
1015
1016         if test $ol_cv_errno_thread_specific != yes ; then
1017                 LIBS="$LTHREAD_LIBS $LIBS"
1018                 LTHREAD_LIBS=""
1019         fi
1020
1021 dnl When in thread environment, use 
1022 dnl             #if defined( HAVE_REENTRANT_FUNCTIONS ) \ 
1023 dnl                     || defined( HAVE_FUNC_R )
1024 dnl                     func_r(...);
1025 dnl             #else
1026 dnl             #       if defined( HAVE_THREADS ) 
1027 dnl                             /* lock */
1028 dnl             #       endif
1029 dnl                             func(...);
1030 dnl             #       if defined( HAVE_THREADS ) 
1031 dnl                             /* unlock */
1032 dnl             #       endif
1033 dnl             #endif
1034 dnl
1035 dnl HAVE_REENTRANT_FUNCTIONS is derived from:
1036 dnl             _POSIX_REENTRANT_FUNCTIONS
1037 dnl             _POSIX_THREAD_SAFE_FUNCTIONS
1038 dnl             _POSIX_THREADSAFE_FUNCTIONS
1039 dnl
1040 dnl             and is currently defined in lthread.h
1041 dnl
1042 dnl HAVE_THREADS is defined by lthread.h iff -UNO_THREADS
1043 dnl 
1044 dnl libldap/*.c should only include <lthread.h> iff
1045 dnl LDAP_R_COMPILE is defined.  ie:
1046 dnl             #ifdef LDAP_R_COMPILE
1047 dnl             #       include LDAP_R_COMPILE
1048 dnl             #endif
1049 dnl
1050 dnl LDAP_R_COMIPLE is defined by libldap_r/Makefile.in
1051 dnl specifically for compiling the threadsafe version of
1052 dnl     the ldap library (-lldap_r).
1053 dnl             
1054 dnl     dnl check for reentrant/threadsafe functions
1055 dnl     dnl
1056 dnl     dnl note: these should only be used when linking
1057 dnl     dnl       with $LTHREAD_LIBS
1058 dnl     dnl
1059 dnl     save_CPPFLAGS="$CPPFLAGS"
1060 dnl     save_LIBS="$LIBS"
1061 dnl     LIBS="$LTHREAD_LIBS $LIBS"
1062 dnl     AC_CHECK_FUNCS( \
1063 dnl             strtok_r \
1064 dnl             gmtime_r \
1065 dnl             gethostbyaddr_r gethostbyname_r \
1066 dnl             feof_unlocked unlocked_feof \
1067 dnl             putc_unlocked unlocked_putc \
1068 dnl             flockfile ftrylockfile \
1069 dnl     )
1070 dnl     CPPFLAGS="$save_CPPFLAGS"
1071 dnl     LIBS="$save_LIBS"
1072 fi  
1073
1074 dnl ----------------------------------------------------------------
1075
1076 if test $ol_link_threads = no ; then
1077         if test $ol_with_threads = yes ; then
1078                 AC_MSG_ERROR([no suitable thread support])
1079         fi
1080
1081         if test $ol_with_threads = auto ; then
1082                 AC_MSG_WARN([no suitable thread support, disabling threads])
1083                 ol_with_threads=no
1084         fi
1085
1086         AC_DEFINE(NO_THREADS,1)
1087         LTHREAD_LIBS=""
1088 fi
1089
1090 ol_link_ldbm=no 
1091 if test $ol_with_ldbm_api = auto -o $ol_with_ldbm_api = db2 ; then
1092         OL_BERKELEY_DB2
1093
1094         if test $ol_cv_berkeley_db2 = yes ; then
1095                 ol_link_ldbm=db2
1096                 ol_with_ldbm_api=db2
1097
1098                 if test $ol_with_ldbm_type = hash ; then
1099                         AC_DEFINE(LDBM_USE_DBHASH,1)
1100                 else
1101                         AC_DEFINE(LDBM_USE_DBBTREE,1)
1102                 fi
1103
1104                 dnl $ol_cv_lib_db2 should be yes or -ldb
1105                 dnl (it could be no, but that would be an error
1106                 if test $ol_cv_lib_db2 != yes ; then
1107                         LDBM_LIBS="$LDBM_LIBS $ol_cv_lib_db2"
1108                 fi
1109         fi
1110 fi
1111
1112 ol_link_bdb2=no
1113 if test $ol_link_ldbm = db2 -a $ol_enable_bdb2 != no ; then
1114         ol_link_bdb2=yes
1115 fi
1116
1117 if test $ol_with_ldbm_api = auto -o $ol_with_ldbm_api = db ; then
1118         OL_BERKELEY_DB
1119
1120         if test $ol_cv_berkeley_db = yes ; then
1121                 ol_link_ldbm=db
1122                 ol_with_ldbm_api=db
1123
1124                 if test $ol_with_ldbm_type = hash ; then
1125                         AC_DEFINE(LDBM_USE_DBHASH,1)
1126                 else
1127                         AC_DEFINE(LDBM_USE_DBBTREE,1)
1128                 fi
1129
1130                 dnl $ol_cv_lib_db should be yes or -ldb
1131                 dnl (it could be no, but that would be an error
1132                 if test $ol_cv_lib_db != yes ; then
1133                         LDBM_LIBS="$LDBM_LIBS $ol_cv_lib_db"
1134                 fi
1135         fi
1136 fi
1137
1138 if test $ol_with_ldbm_api = manual ; then
1139         dnl User thinks he can manually configure LDBM api.
1140         ol_link_ldbm=yes
1141
1142         AC_MSG_WARN([LDBM defines and link options must be set manually])
1143
1144         AC_CHECK_HEADERS(db.h db_185.h gdbm.h ndbm.h)
1145 fi
1146
1147 if test $ol_link_ldbm = no -a $ol_with_ldbm_type = btree ; then
1148         AC_MSG_WARN(Could not find LDBM with BTREE support)
1149         ol_with_ldbm_api=none
1150 fi
1151
1152 if test $ol_with_ldbm_api = auto -o $ol_with_ldbm_api = gdbm ; then
1153         OL_GDBM
1154
1155         if test $ol_cv_gdbm = yes ; then
1156                 ol_link_ldbm=gdbm
1157                 ol_with_ldbm_api=gdbm
1158
1159                 if test $ol_cv_lib_gdbm != yes ; then
1160                         LDBM_LIBS="$LDBM_LIBS $ol_cv_lib_gdbm"
1161                 fi
1162         fi
1163 fi
1164
1165 if test $ol_with_ldbm_api = auto ; then
1166         AC_MSG_WARN([skipping automatic checking for NDBM, must be manually enabled.])
1167 elif test $ol_with_ldbm_api = ndbm ; then
1168         OL_NDBM
1169
1170         if test $ol_cv_ndbm = yes ; then
1171                 ol_link_ldbm=ndbm
1172                 ol_with_ldbm_api=ndbm
1173
1174                 if test $ol_cv_lib_ndbm != yes ; then
1175                         LDBM_LIBS="$LDBM_LIBS $ol_cv_lib_ndbm"
1176                 fi
1177         fi
1178 fi
1179
1180 if test $ol_link_ldbm = no -a $ol_enable_ldbm != no ; then
1181         AC_MSG_WARN(could not find suitable LDBM backend)
1182         if test $ol_enable_ldbm = yes ; then
1183                 AC_MSG_ERROR(select appropriate LDBM options or disable)
1184         fi
1185
1186         AC_MSG_WARN(disabling LDBM)
1187         ol_enable_ldbm=no
1188 fi
1189
1190 if test $ol_enable_wrappers != no ; then
1191         AC_CHECK_HEADERS(tcpd.h)
1192
1193         if test $ac_cv_header_tcpd_h != yes ; then
1194                 have_wrappers=no
1195         else
1196                 AC_CHECK_LIB(wrap, main,
1197                         [have_wrappers=yes], [have_wrappers=no])
1198         fi
1199
1200         if test $have_wrappers = yes ; then
1201                 AC_DEFINE(HAVE_TCPD)
1202                 SLAPD_LIBS="$SLAPD_LIBS -lwrap"
1203         else
1204                 AC_MSG_WARN(could not find -lwrap)
1205                 if test $ol_enable_wrappers = yes ; then
1206                         AC_MSG_ERROR(could not find wrappers, select appropriate options or disable)
1207                 fi
1208
1209                 AC_MSG_WARN(disabling wrappers support)
1210                 ol_enable_wrappers=no
1211         fi
1212 fi
1213
1214 if test $ol_enable_syslog != no ; then
1215         AC_CHECK_FUNC(openlog)
1216         if test $ac_cv_func_openlog = no -a $ol_enable_syslog = yes; then
1217                 AC_MSG_ERROR(could not find syslog, select appropriate options or disable)
1218         fi
1219         ol_enable_syslog=$ac_cv_func_openlog
1220 fi
1221
1222 if test $ol_enable_dmalloc != no ; then
1223         AC_CHECK_HEADERS(dmalloc.h)
1224         AC_CHECK_LIB(dmalloc, dmalloc_shutdown)
1225 fi
1226
1227 # ud needs termcap (should insert check here)
1228 ol_link_termcap=no
1229 AC_CHECK_HEADERS(termcap.h ncurses.h)
1230
1231 if test $ol_link_termcap = no ; then
1232         AC_CHECK_LIB(termcap, tputs, [have_termcap=yes], [have_termcap=no])
1233         if test $have_termcap = yes ; then
1234                 AC_DEFINE(HAVE_TERMCAP)
1235                 ol_link_termcap=yes
1236                 TERMCAP_LIBS=-ltermcap
1237         fi
1238 fi
1239
1240 if test $ol_link_termcap = no ; then
1241         AC_CHECK_LIB(ncurses, initscr, [have_ncurses=yes], [have_ncurses=no])
1242         if test $have_ncurses = yes ; then
1243                 AC_DEFINE(HAVE_NCURSES)
1244                 ol_link_termcap=yes
1245                 TERMCAP_LIBS=-lncurses
1246         fi
1247 fi
1248
1249 if test $ol_link_termcap = no ; then
1250         AC_DEFINE(NO_TERMCAP,1)
1251         TERMCAP_LIBS=
1252 fi
1253
1254 # FreeBSD (and others) have crypt(3) in -lcrypt
1255 if test $ol_enable_crypt != no ; then
1256         AC_CHECK_FUNC(crypt, [have_crypt=yes], [
1257                 AC_CHECK_LIB(crypt, crypt, [LUTIL_LIBS="$LUTIL_LIBS -lcrypt"
1258                         have_crypt=yes], [have_crypt=no])])
1259
1260         if test $have_crypt = yes ; then
1261                 AC_DEFINE(HAVE_CRYPT,1)
1262         else
1263                 AC_MSG_WARN(could not find crypt)
1264                 if test $ol_enable_crypt = yes ; then
1265                         AC_MSG_ERROR(could not find crypt, select appropriate options or disable)
1266                 fi
1267
1268                 AC_MSG_WARN(disabling crypt support)
1269                 ol_enable_crypt=no
1270         fi
1271 fi
1272
1273 # FreeBSD (and others) have setproctitle(3) in -lutil
1274 if test $ol_enable_proctitle != no ; then
1275         AC_CHECK_FUNC(setproctitle,     [have_setproctitle=yes], [
1276                 AC_CHECK_LIB(util, setproctitle,
1277                         [have_setproctitle=yes
1278                         LUTIL_LIBS="$LUTIL_LIBS -lutil"],
1279                         [have_setproctitle=no
1280                         LIBOBJS="$LIBOBJS setproctitle.o"])])
1281
1282         if test $have_setproctitle = yes ; then
1283                 AC_DEFINE(HAVE_SETPROCTITLE,1)
1284         fi
1285 fi
1286
1287 dnl ----------------------------------------------------------------
1288 dnl Checks for header files.
1289 AC_HEADER_STDC
1290
1291 if test $ac_cv_header_stdc != yes; then
1292         AC_MSG_WARN([could not Standard C compliant headers])
1293 fi
1294
1295 AC_HEADER_DIRENT
1296 AC_HEADER_SYS_WAIT
1297 AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
1298 if test $am_cv_sys_posix_termios = yes ; then
1299         AC_DEFINE(HAVE_POSIX_TERMIOS,1)
1300 fi
1301
1302 AC_CHECK_HEADERS(       \
1303         crypt.h                 \
1304         errno.h                 \
1305         fcntl.h                 \
1306         filio.h                 \
1307         getopt.h                \
1308         libutil.h               \
1309         limits.h                \
1310         malloc.h                \
1311         memory.h                \
1312         regex.h                 \
1313         psap.h                  \
1314         pwd.h                   \
1315         sgtty.h                 \
1316         stdarg.h                \
1317         stddef.h                \
1318         string.h                \
1319         strings.h               \
1320         sysexits.h              \
1321         sys/file.h              \
1322         sys/filio.h             \
1323         sys/errno.h             \
1324         sys/ioctl.h             \
1325         sys/param.h             \
1326         sys/resource.h  \
1327         sys/socket.h    \
1328         sys/syslog.h    \
1329         sys/time.h              \
1330         sys/types.h             \
1331         syslog.h                \
1332         termios.h               \
1333         unistd.h                \
1334 )
1335
1336 dnl ----------------------------------------------------------------
1337 dnl Checks for typedefs, structures, and compiler characteristics.
1338 AC_TYPE_GETGROUPS dnl requires AC_TYPE_UID_T
1339 AC_TYPE_MODE_T
1340 AC_TYPE_OFF_T
1341 AC_TYPE_PID_T
1342 AM_TYPE_PTRDIFF_T
1343 AC_TYPE_SIGNAL
1344 OL_TYPE_SIG_ATOMIC_T
1345 AC_TYPE_SIZE_T
1346 AC_STRUCT_ST_BLKSIZE
1347 AC_HEADER_TIME
1348 AC_STRUCT_TM
1349
1350 OL_C_UPPER_LOWER
1351 AC_C_CONST
1352 OL_C_VOLATILE
1353
1354 if test $cross_compiling = yes ; then
1355         AC_DEFINE(CROSS_COMPILING, 1)
1356 else
1357         AC_C_BIGENDIAN
1358         AC_CHECK_SIZEOF(short) 
1359         AC_CHECK_SIZEOF(int) 
1360         AC_CHECK_SIZEOF(long)
1361 fi
1362
1363 dnl ----------------------------------------------------------------
1364 dnl Checks for library functions.
1365 AC_FUNC_MEMCMP
1366 dnl AM_FUNC_MKTIME dnl checks for sys/time.h and unistd.h
1367 AC_FUNC_STRFTIME
1368 dnl AM_FUNC_STRTOD
1369 AC_FUNC_VPRINTF
1370
1371 if test $ac_cv_func_vprintf = yes ; then
1372         dnl check for vsnprintf
1373         AC_CHECK_FUNCS(vsnprintf vsprintf)
1374 fi
1375
1376 AC_CHECK_FUNCS(         \
1377         bcopy                   \
1378         flock                   \
1379         getdtablesize   \
1380         gethostname             \
1381         getpwuid                \
1382         gettimeofday    \
1383         lockf                   \
1384         memcpy                  \
1385         memmove                 \
1386         mkstemp                 \
1387         select                  \
1388         setpwfile               \
1389         setsid                  \
1390         signal                  \
1391         sigset                  \
1392         snprintf                \
1393         socket                  \
1394         strdup                  \
1395         strerror                \
1396         strpbrk                 \
1397         strrchr                 \
1398         strsep                  \
1399         strstr                  \
1400         strtok                  \
1401         strtol                  \
1402         strtoul                 \
1403         strspn                  \
1404         sysconf                 \
1405         waitpid                 \
1406 )
1407
1408 # these functions are required to build a thread_safe -lldap
1409 AC_CHECK_FUNCS(         \
1410         strtok_r                \
1411         ctime_r                 \
1412         gethostbyaddr_r \
1413         gethostbyname_r \
1414 )
1415
1416 if test "$ac_cv_func_ctime_r" = yes ; then
1417         OL_FUNC_CTIME_R_NARGS
1418 else
1419         ol_cv_func_ctime_r=0
1420 fi
1421
1422 if test "$ac_cv_func_strtok_r" = yes \
1423         -a "$ac_cv_func_ctime_r" = yes \
1424         -a "$ol_cv_func_ctime_r_nargs" -ge 2 -a "$ol_cv_func_ctime_r_nargs" -le 3 \
1425         -a "$ac_cv_func_gethostbyaddr_r" = yes \
1426         -a "$ac_cv_func_gethostbyname_r" = yes \
1427         ; then
1428
1429         AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_REENTRANT, 1)
1430 fi
1431
1432 if test $ol_link_threads != no ; then
1433         AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE, 1)
1434 fi
1435
1436 dnl We actually may need to replace more than this.
1437 AC_REPLACE_FUNCS(getopt tempnam)
1438
1439 dnl ----------------------------------------------------------------
1440 # Check Configuration
1441 OL_SYS_ERRLIST
1442
1443 dnl ----------------------------------------------------------------
1444 dnl Sort out defines
1445
1446 if test "$ol_enable_debug" != no ; then
1447         AC_DEFINE(LDAP_DEBUG,1)
1448 fi
1449 if test "$ol_enable_syslog" = yes ; then
1450         AC_DEFINE(LDAP_SYSLOG,1)
1451 fi
1452 if test "$ol_enable_libui" = yes ; then
1453         AC_DEFINE(LDAP_LIBUI,1)
1454 fi
1455 if test "$ol_enable_cache" = no ; then
1456         AC_DEFINE(LDAP_NOCACHE,1)
1457 fi
1458 if test "$ol_enable_dns" != no ; then
1459         AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_V2_DNS,LDAP_VENDOR_VERSION,1)
1460 fi
1461 if test "$ol_enable_proctitle" != no ; then
1462         AC_DEFINE(LDAP_PROCTITLE,1)
1463 fi
1464 if test "$ol_enable_referrals" != no ; then
1465         AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS,LDAP_VENDOR_VERSION,1)
1466 fi
1467 if test "$ol_enable_cldap" != no ; then
1468         AC_DEFINE(LDAP_CONNECTIONLESS,1)
1469 fi
1470
1471 if test "$ol_enable_aclgroups" != no ; then
1472         AC_DEFINE(SLAPD_ACLGROUPS,1)
1473 fi
1474 if test "$ol_enable_crypt" != no ; then
1475         AC_DEFINE(SLAPD_CRYPT,1)
1476 fi
1477 if test "$ol_enable_cleartext" != no ; then
1478         AC_DEFINE(SLAPD_CLEARTEXT,1)
1479 fi
1480 if test "$ol_enable_phonetic" != no ; then
1481         AC_DEFINE(SLAPD_PHONETIC,1)
1482 fi
1483 if test "$ol_enable_rlookups" != no ; then
1484         AC_DEFINE(SLAPD_RLOOKUPS,1)
1485 fi
1486
1487 if test "$ol_link_bdb2" != no ; then
1488         AC_DEFINE(SLAPD_BDB2,1)
1489         BUILD_SLAPD=yes
1490         BUILD_BDB2=yes
1491 fi
1492
1493 if test "$ol_link_ldbm" != no ; then
1494         AC_DEFINE(SLAPD_LDBM,1)
1495         BUILD_SLAPD=yes
1496         BUILD_LDBM=yes
1497 fi
1498
1499 if test "$ol_enable_passwd" != no ; then
1500         AC_DEFINE(SLAPD_PASSWD,1)
1501         BUILD_SLAPD=yes
1502         BUILD_PASSWD=yes
1503 fi
1504
1505 if test "$ol_enable_perl" != no ; then
1506         AC_DEFINE(SLAPD_PERL,1)
1507         BUILD_SLAPD=yes
1508         BUILD_PERL=yes
1509 fi
1510
1511 if test "$ol_enable_shell" != no ; then
1512         AC_DEFINE(SLAPD_SHELL,1)
1513         BUILD_SLAPD=yes
1514         BUILD_SHELL=yes
1515 fi
1516
1517 if test "$ol_enable_slurpd" != no -a "$ol_link_threads" != no -a \
1518         $BUILD_SLAPD = yes ; then
1519         BUILD_SLURPD=yes
1520 fi
1521
1522 if test "$ol_link_isode" != no ; then
1523         BUILD_LDAPD=yes
1524 fi
1525
1526 dnl ----------------------------------------------------------------
1527
1528 AC_SUBST(BUILD_LDAPD)
1529 AC_SUBST(BUILD_SLAPD)
1530   AC_SUBST(BUILD_BDB2)
1531   AC_SUBST(BUILD_LDBM)
1532   AC_SUBST(BUILD_PASSWD)
1533   AC_SUBST(BUILD_PERL)
1534   AC_SUBST(BUILD_SHELL)
1535 AC_SUBST(BUILD_SLURPD)
1536
1537 AC_SUBST(LDAP_LIBS)
1538 AC_SUBST(LDAPD_LIBS)
1539 AC_SUBST(SLAPD_LIBS)
1540 AC_SUBST(SLURPD_LIBS)
1541 AC_SUBST(LDBM_LIBS)
1542 AC_SUBST(LTHREAD_LIBS)
1543 AC_SUBST(LUTIL_LIBS)
1544
1545 AC_SUBST(SLAPD_PERL_CPPFLAGS)
1546 AC_SUBST(SLAPD_PERL_LDFLAGS)
1547
1548 AC_SUBST(KRB_LIBS)
1549 AC_SUBST(TERMCAP_LIBS)
1550
1551 dnl ----------------------------------------------------------------
1552 dnl final output
1553 dnl
1554
1555 AC_OUTPUT( \
1556 Makefile:build/top.mk:Makefile.in:build/dir.mk \
1557 doc/Makefile:build/top.mk:doc/Makefile.in:build/dir.mk \
1558 doc/man/Makefile:build/top.mk:doc/man/Makefile.in:build/dir.mk \
1559 doc/man/man1/Makefile:build/top.mk:doc/man/man1/Makefile.in:build/man.mk \
1560 doc/man/man3/Makefile:build/top.mk:doc/man/man3/Makefile.in:build/man.mk \
1561 doc/man/man5/Makefile:build/top.mk:doc/man/man5/Makefile.in:build/man.mk \
1562 doc/man/man8/Makefile:build/top.mk:doc/man/man8/Makefile.in:build/man.mk \
1563 clients/Makefile:build/top.mk:clients/Makefile.in:build/dir.mk \
1564 clients/finger/Makefile:build/top.mk:clients/finger/Makefile.in:build/rules.mk \
1565 clients/fax500/Makefile:build/top.mk:clients/fax500/Makefile.in:build/rules.mk \
1566 clients/gopher/Makefile:build/top.mk:clients/gopher/Makefile.in:build/rules.mk \
1567 clients/mail500/Makefile:build/top.mk:clients/mail500/Makefile.in:build/rules.mk \
1568 clients/rcpt500/Makefile:build/top.mk:clients/rcpt500/Makefile.in:build/rules.mk \
1569 clients/ud/Makefile:build/top.mk:clients/ud/Makefile.in:build/rules.mk \
1570 clients/tools/Makefile:build/top.mk:clients/tools/Makefile.in:build/rules.mk \
1571 include/Makefile:build/top.mk:include/Makefile.in \
1572 libraries/Makefile:build/top.mk:libraries/Makefile.in:build/dir.mk      \
1573 libraries/libavl/Makefile:build/top.mk:libraries/libavl/Makefile.in:build/lib.mk:build/lib-static.mk    \
1574 libraries/liblber/Makefile:build/top.mk:libraries/liblber/Makefile.in:build/lib.mk:build/lib-shared.mk  \
1575 libraries/libldap/Makefile:build/top.mk:libraries/libldap/Makefile.in:build/lib.mk:build/lib-shared.mk  \
1576 libraries/libldap_r/Makefile:build/top.mk:libraries/libldap_r/Makefile.in:build/lib.mk:build/lib-shared.mk      \
1577 libraries/libldbm/Makefile:build/top.mk:libraries/libldbm/Makefile.in:build/lib.mk:build/lib-static.mk  \
1578 libraries/libldif/Makefile:build/top.mk:libraries/libldif/Makefile.in:build/lib.mk:build/lib-static.mk  \
1579 libraries/liblutil/Makefile:build/top.mk:libraries/liblutil/Makefile.in:build/lib.mk:build/lib-static.mk        \
1580 servers/Makefile:build/top.mk:servers/Makefile.in:build/dir.mk \
1581 servers/ldapd/Makefile:build/top.mk:servers/ldapd/Makefile.in:build/srv.mk \
1582 servers/slapd/Makefile:build/top.mk:servers/slapd/Makefile.in:build/srv.mk \
1583 servers/slapd/back-ldbm/Makefile:build/top.mk:servers/slapd/back-ldbm/Makefile.in:build/srv.mk \
1584 servers/slapd/back-passwd/Makefile:build/top.mk:servers/slapd/back-passwd/Makefile.in:build/srv.mk \
1585 servers/slapd/back-perl/Makefile:build/top.mk:servers/slapd/back-perl/Makefile.in:build/srv.mk \
1586 servers/slapd/back-shell/Makefile:build/top.mk:servers/slapd/back-shell/Makefile.in:build/srv.mk \
1587 servers/slapd/shell-backends/Makefile:build/top.mk:servers/slapd/shell-backends/Makefile.in:build/srv.mk \
1588 servers/slapd/tools/Makefile:build/top.mk:servers/slapd/tools/Makefile.in \
1589 servers/slurpd/Makefile:build/top.mk:servers/slurpd/Makefile.in:build/srv.mk \
1590 tests/Makefile:build/top.mk:tests/Makefile.in \
1591 ,[
1592 date > stamp-h
1593 echo Please \"make depend\" to build dependencies
1594 ])