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