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