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