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