]> git.sur5r.net Git - openldap/blob - build/openldap.m4
Add BerkeleyDB 3 DB_THREAD detection
[openldap] / build / openldap.m4
1 dnl $OpenLDAP$
2 dnl
3 dnl Copyright 1998-2000 The OpenLDAP Foundation,  All Rights Reserved.
4 dnl COPYING RESTRICTIONS APPLY, See COPYRIGHT file
5 dnl
6 dnl OpenLDAP Autoconf Macros
7 dnl
8 dnl --------------------------------------------------------------------
9 dnl Restricted form of AC_ARG_ENABLE that limits user options
10 dnl
11 dnl $1 = option name
12 dnl $2 = help-string
13 dnl $3 = default value  (auto)
14 dnl $4 = allowed values (auto yes no)
15 AC_DEFUN([OL_ARG_ENABLE], [# OpenLDAP --enable-$1
16         AC_ARG_ENABLE($1,[$2 (]ifelse($3,,auto,$3)[)],[
17         ol_arg=invalid
18         for ol_val in ifelse($4,,[auto yes no],[$4]) ; do
19                 if test "$enableval" = "$ol_val" ; then
20                         ol_arg="$ol_val"
21                 fi
22         done
23         if test "$ol_arg" = "invalid" ; then
24                 AC_MSG_ERROR(bad value $enableval for --enable-$1)
25         fi
26         ol_enable_$1="$ol_arg"
27 ],
28 [       ol_enable_$1=ifelse($3,,"auto","$3")])dnl
29 dnl AC_VERBOSE(OpenLDAP -enable-$1 $ol_enable_$1)
30 # end --enable-$1
31 ])dnl
32 dnl
33 dnl --------------------------------------------------------------------
34 dnl Restricted form of AC_ARG_WITH that limits user options
35 dnl
36 dnl $1 = option name
37 dnl $2 = help-string
38 dnl $3 = default value (no)
39 dnl $4 = allowed values (yes or no)
40 AC_DEFUN([OL_ARG_WITH], [# OpenLDAP --with-$1
41         AC_ARG_WITH($1,[$2 (]ifelse($3,,yes,$3)[)],[
42         ol_arg=invalid
43         for ol_val in ifelse($4,,[yes no],[$4]) ; do
44                 if test "$withval" = "$ol_val" ; then
45                         ol_arg="$ol_val"
46                 fi
47         done
48         if test "$ol_arg" = "invalid" ; then
49                 AC_MSG_ERROR(bad value $withval for --with-$1)
50         fi
51         ol_with_$1="$ol_arg"
52 ],
53 [       ol_with_$1=ifelse($3,,"no","$3")])dnl
54 dnl AC_VERBOSE(OpenLDAP --with-$1 $ol_with_$1)
55 # end --with-$1
56 ])dnl
57 dnl
58 dnl ====================================================================
59 dnl
60 AC_DEFUN(AC_COMPILE_CHECK_SIZEOF,
61 [changequote(<<, >>)dnl 
62 dnl The name to #define. 
63 define(<<AC_TYPE_NAME>>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl 
64 dnl The cache variable name. 
65 define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl 
66 changequote([, ])dnl 
67 AC_MSG_CHECKING(size of $1) 
68 AC_CACHE_VAL(AC_CV_NAME, 
69 [for ac_size in 4 8 1 2 16 $2 ; do # List sizes in rough order of prevalence. 
70   AC_TRY_COMPILE([#include "confdefs.h" 
71 #include <sys/types.h> 
72 $2 
73 ], [switch (0) case 0: case (sizeof ($1) == $ac_size):;], AC_CV_NAME=$ac_size) 
74   if test x$AC_CV_NAME != x ; then break; fi 
75 done 
76 ]) 
77 if test x$AC_CV_NAME = x ; then 
78   AC_MSG_ERROR([cannot determine a size for $1]) 
79 fi 
80 AC_MSG_RESULT($AC_CV_NAME) 
81 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The number of bytes in type $1]) 
82 undefine([AC_TYPE_NAME])dnl 
83 undefine([AC_CV_NAME])dnl 
84 ])
85 dnl ====================================================================
86 dnl check if hard links are supported.
87 dnl
88 AC_DEFUN([OL_PROG_LN_H], [# test for ln hardlink support
89 AC_MSG_CHECKING(whether ln works)
90 AC_CACHE_VAL(ol_cv_prog_LN_H,
91 [rm -f conftest.src conftest.dst
92 echo "conftest" > conftest.src
93 if ln conftest.src conftest.dst 2>/dev/null
94 then
95   ol_cv_prog_LN_H="ln"
96 else
97   ol_cv_prog_LN_H="cp"
98 fi
99 rm -f conftest.src conftest.dst
100 ])dnl
101 LN_H="$ol_cv_prog_LN_H"
102 if test "$ol_cv_prog_LN_H" = "ln"; then
103         AC_MSG_RESULT(yes)
104 else
105         AC_MSG_RESULT(no)
106 fi
107 AC_SUBST(LN_H)dnl
108 ])dnl
109 dnl
110 dnl ====================================================================
111 dnl Check for dependency generation flag
112 AC_DEFUN([OL_MKDEPEND], [# test for make depend flag
113 OL_MKDEP=
114 OL_MKDEP_FLAGS=
115 if test -z "${MKDEP}"; then
116         OL_MKDEP="${CC-cc}"
117         if test -z "${MKDEP_FLAGS}"; then
118                 AC_CACHE_CHECK([for ${OL_MKDEP} depend flag], ol_cv_mkdep, [
119                         ol_cv_mkdep=no
120                         for flag in "-M" "-xM"; do
121                                 cat > conftest.c <<EOF
122  noCode;
123 EOF
124                                 if AC_TRY_COMMAND($OL_MKDEP $flag conftest.c) \
125                                         | egrep '^conftest\.'"${ac_objext}" >/dev/null 2>&1
126                                 then
127                                         if test ! -f conftest."${ac_object}" ; then
128                                                 ol_cv_mkdep=$flag
129                                                 OL_MKDEP_FLAGS="$flag"
130                                                 break
131                                         fi
132                                 fi
133                         done
134                         rm -f conftest*
135                 ])
136         else
137                 cc_cv_mkdep=yes
138                 OL_MKDEP_FLAGS="${MKDEP_FLAGS}"
139         fi
140 else
141         cc_cv_mkdep=yes
142         OL_MKDEP="${MKDEP}"
143         OL_MKDEP_FLAGS="${MKDEP_FLAGS}"
144 fi
145 AC_SUBST(OL_MKDEP)
146 AC_SUBST(OL_MKDEP_FLAGS)
147 ])
148 dnl
149 dnl ====================================================================
150 dnl Check if system uses EBCDIC instead of ASCII
151 AC_DEFUN([OL_CPP_EBCDIC], [# test for EBCDIC
152 AC_CACHE_CHECK([for EBCDIC],ol_cv_cpp_ebcdic,[
153         AC_TRY_CPP([
154 #if !('M' == 0xd4)
155 #include <__ASCII__/generate_error.h>
156 #endif
157 ],
158         [ol_cv_cpp_ebcdic=yes],
159         [ol_cv_cpp_ebcdic=no])])
160 if test $ol_cv_cpp_ebcdic = yes ; then
161         AC_DEFINE(HAVE_EBCDIC,1, [define if system uses EBCDIC instead of ASCII])
162 fi
163 ])
164 dnl
165 dnl --------------------------------------------------------------------
166 dnl OpenLDAP version of STDC header check w/ EBCDIC support
167 AC_DEFUN(OL_HEADER_STDC,
168 [AC_REQUIRE_CPP()dnl
169 AC_REQUIRE([OL_CPP_EBCDIC])dnl
170 AC_CACHE_CHECK([for ANSI C header files], ol_cv_header_stdc,
171 [AC_TRY_CPP([#include <stdlib.h>
172 #include <stdarg.h>
173 #include <string.h>
174 #include <float.h>], ol_cv_header_stdc=yes, ol_cv_header_stdc=no)
175
176 if test $ol_cv_header_stdc = yes; then
177   # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
178 AC_EGREP_HEADER(memchr, string.h, , ol_cv_header_stdc=no)
179 fi
180
181 if test $ol_cv_header_stdc = yes; then
182   # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
183 AC_EGREP_HEADER(free, stdlib.h, , ol_cv_header_stdc=no)
184 fi
185
186 if test $ol_cv_header_stdc = yes; then
187   # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
188 AC_TRY_RUN([#include <ctype.h>
189 #ifndef HAVE_EBCDIC
190 #       define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
191 #       define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
192 #else
193 #       define ISLOWER(c) (('a' <= (c) && (c) <= 'i') \
194                 || ('j' <= (c) && (c) <= 'r') \
195                 || ('s' <= (c) && (c) <= 'z'))
196 #       define TOUPPER(c)       (ISLOWER(c) ? ((c) | 0x40) : (c))
197 #endif
198 #define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
199 int main () { int i; for (i = 0; i < 256; i++)
200 if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2);
201 exit (0); }
202 ], , ol_cv_header_stdc=no, :)
203 fi])
204 if test $ol_cv_header_stdc = yes; then
205   AC_DEFINE(STDC_HEADERS)
206 fi
207 ac_cv_header_stdc=disable
208 ])
209 dnl
210 dnl ====================================================================
211 dnl Check if struct passwd has pw_gecos
212 AC_DEFUN([OL_STRUCT_PASSWD_PW_GECOS], [# test for pw_gecos in struct passwd
213 AC_CACHE_CHECK([struct passwd for pw_gecos],ol_cv_struct_passwd_pw_gecos,[
214         AC_TRY_COMPILE([#include <pwd.h>],[
215         struct passwd pwd;
216         pwd.pw_gecos = pwd.pw_name;
217 ],
218         [ol_cv_struct_passwd_pw_gecos=yes],
219         [ol_cv_struct_passwd_pw_gecos=no])])
220 if test $ol_cv_struct_passwd_pw_gecos = yes ; then
221         AC_DEFINE(HAVE_PW_GECOS,1, [define if struct passwd has pw_gecos])
222 fi
223 ])
224 dnl
225 dnl --------------------------------------------------------------------
226 dnl Check if struct passwd has pw_passwd
227 AC_DEFUN([OL_STRUCT_PASSWD_PW_PASSWD], [# test for pw_passwd in struct passwd
228 AC_CACHE_CHECK([struct passwd for pw_passwd],ol_cv_struct_passwd_pw_passwd,[
229         AC_TRY_COMPILE([#include <pwd.h>],[
230         struct passwd pwd;
231         pwd.pw_passwd = pwd.pw_name;
232 ],
233         [ol_cv_struct_passwd_pw_passwd=yes],
234         [ol_cv_struct_passwd_pw_passwd=no])])
235 if test $ol_cv_struct_passwd_pw_passwd = yes ; then
236         AC_DEFINE(HAVE_PW_PASSWD,1, [define if struct passwd has pw_passwd])
237 fi
238 ])
239 dnl
240 dnl ====================================================================
241 dnl Berkeley DB macros
242 dnl
243 dnl --------------------------------------------------------------------
244 dnl Try to link
245 AC_DEFUN([OL_BERKELEY_DB_TRY],
246 [if test $ol_cv_lib_db = no ; then
247         AC_CACHE_CHECK([for Berkeley DB link (]ifelse($2,,default,$2)[)],[$1],
248 [
249         ol_DB_LIB=ifelse($2,,,$2)
250         ol_LIBS=$LIBS
251         LIBS="$ol_DB_LIB $LIBS"
252
253         AC_TRY_LINK([
254 #ifdef HAVE_DB_185_H
255 # include <db_185.h>
256 #else
257 # include <db.h>
258 #endif
259
260 #ifndef DB_VERSION_MAJOR
261 # define DB_VERSION_MAJOR 1
262 #endif
263
264 #ifndef NULL
265 #define NULL ((void*)0)
266 #endif
267 ],[
268 #if DB_VERSION_MAJOR > 2
269         db_env_create( NULL, 0 );
270 #elif DB_VERSION_MAJOR > 1
271         db_appexit( NULL );
272 #else
273         (void) dbopen( NULL, 0, 0, 0, NULL);
274 #endif
275 ],[$1=yes],[$1=no])
276
277         LIBS="$ol_LIBS"
278 ])
279
280         if test $$1 = yes ; then
281                 ol_cv_lib_db=ifelse($2,,yes,$2)
282         fi
283 fi
284 ])
285 dnl
286 dnl --------------------------------------------------------------------
287 dnl Try to locate appropriate library
288 AC_DEFUN([OL_BERKELEY_DB_LINK],
289 [ol_cv_lib_db=no
290 OL_BERKELEY_DB_TRY(ol_cv_db_none)
291 OL_BERKELEY_DB_TRY(ol_cv_db_db,[-ldb])
292 OL_BERKELEY_DB_TRY(ol_cv_db_db3,[-ldb3])
293 OL_BERKELEY_DB_TRY(ol_cv_db_db2,[-ldb2])
294 OL_BERKELEY_DB_TRY(ol_cv_db_db1,[-ldb1])
295 ])
296 dnl
297 dnl --------------------------------------------------------------------
298 dnl Check if Berkeley DB supports DB_THREAD
299 AC_DEFUN([OL_BERKELEY_DB_THREAD],
300 [AC_CACHE_CHECK([for Berkeley DB thread support], [ol_cv_berkeley_db_thread], [
301         ol_LIBS="$LIBS"
302         if test $ol_cv_lib_db != yes ; then
303                 LIBS="$ol_cv_lib_db"
304         fi
305
306         AC_TRY_RUN([
307 #ifdef HAVE_DB_185_H
308         choke me;
309 #else
310 #include <db.h>
311 #endif
312 #ifndef NULL
313 #define NULL ((void *)0)
314 #endif
315 main()
316 {
317         int rc;
318         u_int32_t flags = DB_CREATE | DB_THREAD;
319
320
321 #if DB_VERSION_MAJOR > 2
322         DB_ENV *env = NULL;
323
324         rc = db_env_create( &env, 0 );
325
326         if( rc == 0 ) {
327                 rc = env->open( env, NULL, NULL, flags, 0 );
328         }
329
330 #else
331         DB_ENV env;
332         memset( &env, '\0', sizeof(env) );
333
334         rc = db_appinit( NULL, NULL, &env, flags );
335
336         if( rc == 0 ) {
337                 db_appexit( &env );
338         }
339 #endif
340
341         return rc;
342 }],
343         [ol_cv_berkeley_db_thread=yes],
344         [ol_cv_berkeley_db_thread=no],
345         [ol_cv_berkeley_db_thread=cross])
346
347         LIBS="$ol_LIBS"
348
349         if test $ol_cv_berkeley_db_thread != no ; then
350                 AC_DEFINE(HAVE_BERKELEY_DB_THREAD, 1,
351                         [define if Berkeley DB has DB_THREAD support])
352         fi
353 ])])dnl
354 dnl
355 dnl --------------------------------------------------------------------
356 dnl Find any DB
357 AC_DEFUN([OL_BERKELEY_DB],
358 [ol_cv_berkeley_db=no
359 AC_CHECK_HEADERS(db.h)
360 if test $ac_cv_header_db_h = yes; then
361         OL_BERKELEY_DB_LINK
362         if test "$ol_cv_lib_db" != no ; then
363                 ol_cv_berkeley_db=yes
364                 OL_BERKELEY_DB_THREAD
365         fi
366 fi
367 ])
368 dnl
369 dnl --------------------------------------------------------------------
370 dnl Find old Berkeley DB 1.85/1.86
371 AC_DEFUN([OL_BERKELEY_COMPAT_DB],
372 [ol_cv_berkeley_db=no
373 AC_CHECK_HEADERS(db_185.h db.h)
374 if test $ac_cv_header_db_185_h = yes -o $ac_cv_header_db_h = yes; then
375         AC_CACHE_CHECK([if Berkeley DB header compatibility], [ol_cv_header_db1],[
376                 AC_EGREP_CPP(__db_version_1,[
377 #if HAVE_DB_185_H
378 #       include <db_185.h>
379 #else
380 #       include <db.h>
381 #endif
382
383  /* this check could be improved */
384 #ifndef DB_VERSION_MAJOR
385 #       define DB_VERSION_MAJOR 1
386 #endif
387
388 #if DB_VERSION_MAJOR == 1 
389         __db_version_1
390 #endif
391 ],      [ol_cv_header_db1=yes], [ol_cv_header_db1=no])])
392
393         if test ol_cv_header_db1=yes ; then
394                 OL_BERKELEY_DB_LINK
395                 if test "$ol_cv_lib_db" != no ; then
396                         ol_cv_berkeley_db=yes
397                 fi
398         fi
399 fi
400 ])
401 dnl
402 dnl ====================================================================
403 dnl Check if GDBM library exists
404 dnl Check for gdbm_open in standard libraries or -lgdbm
405 dnl
406 dnl defines ol_cv_lib_gdbm to 'yes' or '-lgdbm' or 'no'
407 dnl             'yes' implies gdbm_open is in $LIBS
408 dnl
409 dnl uses:
410 dnl             AC_CHECK_FUNC(gdbm_open)
411 dnl             AC_CHECK_LIB(gdbm,gdbm_open)
412 dnl
413 AC_DEFUN([OL_LIB_GDBM],
414 [AC_CACHE_CHECK(for GDBM library, [ol_cv_lib_gdbm],
415 [       ol_LIBS="$LIBS"
416         AC_CHECK_FUNC(gdbm_open,[ol_cv_lib_gdbm=yes], [
417                 AC_CHECK_LIB(gdbm,gdbm_open,[ol_cv_lib_gdbm=-lgdbm],[ol_cv_lib_gdbm=no])
418         ])
419         LIBS="$ol_LIBS"
420 ])
421 ])dnl
422 dnl
423 dnl --------------------------------------------------------------------
424 dnl Check if GDBM exists
425 dnl
426 dnl defines ol_cv_gdbm to 'yes' or 'no'
427 dnl 
428 dnl uses:
429 dnl             OL_LIB_GDBM
430 dnl             AC_CHECK_HEADERS(gdbm.h)
431 dnl
432 AC_DEFUN([OL_GDBM],
433 [AC_REQUIRE([OL_LIB_GDBM])
434  AC_CHECK_HEADERS(gdbm.h)
435  AC_CACHE_CHECK(for db, [ol_cv_gdbm], [
436         if test $ol_cv_lib_gdbm = no -o $ac_cv_header_gdbm_h = no ; then
437                 ol_cv_gdbm=no
438         else
439                 ol_cv_gdbm=yes
440         fi
441 ])
442  if test $ol_cv_gdbm = yes ; then
443         AC_DEFINE(HAVE_GDBM,1, [define if GNU DBM is available])
444  fi
445 ])dnl
446 dnl
447 dnl ====================================================================
448 dnl Check if MDBM library exists
449 dnl Check for mdbm_open in standard libraries or -lmdbm
450 dnl
451 dnl defines ol_cv_lib_mdbm to 'yes' or '-lmdbm' or 'no'
452 dnl             'yes' implies mdbm_open is in $LIBS
453 dnl
454 dnl uses:
455 dnl             AC_CHECK_FUNC(mdbm_set_chain)
456 dnl             AC_CHECK_LIB(mdbm,mdbm_set_chain)
457 dnl
458 AC_DEFUN([OL_LIB_MDBM],
459 [AC_CACHE_CHECK(for MDBM library, [ol_cv_lib_mdbm],
460 [       ol_LIBS="$LIBS"
461         AC_CHECK_FUNC(mdbm_set_chain,[ol_cv_lib_mdbm=yes], [
462                 AC_CHECK_LIB(mdbm,mdbm_set_chain,[ol_cv_lib_mdbm=-lmdbm],[ol_cv_lib_mdbm=no])
463         ])
464         LIBS="$ol_LIBS"
465 ])
466 ])dnl
467 dnl
468 dnl --------------------------------------------------------------------
469 dnl Check if MDBM exists
470 dnl
471 dnl defines ol_cv_mdbm to 'yes' or 'no'
472 dnl 
473 dnl uses:
474 dnl             OL_LIB_MDBM
475 dnl             AC_CHECK_HEADERS(mdbm.h)
476 dnl
477 AC_DEFUN([OL_MDBM],
478 [AC_REQUIRE([OL_LIB_MDBM])
479  AC_CHECK_HEADERS(mdbm.h)
480  AC_CACHE_CHECK(for db, [ol_cv_mdbm], [
481         if test $ol_cv_lib_mdbm = no -o $ac_cv_header_mdbm_h = no ; then
482                 ol_cv_mdbm=no
483         else
484                 ol_cv_mdbm=yes
485         fi
486 ])
487  if test $ol_cv_mdbm = yes ; then
488         AC_DEFINE(HAVE_MDBM,1, [define if MDBM is available])
489  fi
490 ])dnl
491 dnl
492 dnl ====================================================================
493 dnl Check if NDBM library exists
494 dnl Check for dbm_open in standard libraries or -lndbm or -ldbm
495 dnl
496 dnl defines ol_cv_lib_ndbm to 'yes' or '-lndbm' or -ldbm or 'no'
497 dnl             'yes' implies ndbm_open is in $LIBS
498 dnl
499 dnl uses:
500 dnl             AC_CHECK_FUNC(dbm_open)
501 dnl             AC_CHECK_LIB(ndbm,dbm_open)
502 dnl             AC_CHECK_LIB(dbm,dbm_open)
503 dnl
504 dnl restrictions:
505 dnl             should also check SVR4 case: dbm_open() in -lucb but that
506 dnl             would requiring dealing with -L/usr/ucblib
507 dnl
508 AC_DEFUN([OL_LIB_NDBM],
509 [AC_CACHE_CHECK(for NDBM library, [ol_cv_lib_ndbm],
510 [       ol_LIBS="$LIBS"
511         AC_CHECK_FUNC(dbm_open,[ol_cv_lib_ndbm=yes], [
512                 AC_CHECK_LIB(ndbm,dbm_open,[ol_cv_lib_ndbm=-lndbm], [
513                         AC_CHECK_LIB(dbm,dbm_open,[ol_cv_lib_ndbm=-ldbm],
514                                 [ol_cv_lib_ndbm=no])dnl
515                 ])
516         ])
517         LIBS="$ol_LIBS"
518 ])
519 ])dnl
520 dnl
521 dnl --------------------------------------------------------------------
522 dnl Check if NDBM exists
523 dnl
524 dnl defines ol_cv_ndbm to 'yes' or 'no'
525 dnl 
526 dnl uses:
527 dnl             OL_LIB_NDBM
528 dnl             AC_CHECK_HEADERS(ndbm.h)
529 dnl
530 dnl restrictions:
531 dnl             Doesn't handle SVR4 case (see above)
532 dnl
533 AC_DEFUN([OL_NDBM],
534 [AC_REQUIRE([OL_LIB_NDBM])
535  AC_CHECK_HEADERS(ndbm.h)
536  AC_CACHE_CHECK(for db, [ol_cv_ndbm], [
537         if test $ol_cv_lib_ndbm = no -o $ac_cv_header_ndbm_h = no ; then
538                 ol_cv_ndbm=no
539         else
540                 ol_cv_ndbm=yes
541         fi
542 ])
543  if test $ol_cv_ndbm = yes ; then
544         AC_DEFINE(HAVE_NDBM,1, [define if NDBM is available])
545  fi
546 ])dnl
547 dnl
548 dnl ====================================================================
549 dnl Check POSIX Thread version 
550 dnl
551 dnl defines ol_cv_posix_version to 'final' or 'draft' or 'unknown'
552 dnl     'unknown' implies that the version could not be detected
553 dnl             or that pthreads.h does exist.  Existance of pthreads.h
554 dnl             should be tested separately.
555 dnl
556 AC_DEFUN([OL_POSIX_THREAD_VERSION],
557 [AC_CACHE_CHECK([POSIX thread version],[ol_cv_pthread_version],[
558         AC_EGREP_CPP(pthread_version_final,[
559 #               include <pthread.h>
560                 /* this check could be improved */
561 #               ifdef PTHREAD_ONCE_INIT
562                         pthread_version_final;
563 #               endif
564         ], ol_pthread_final=yes, ol_pthread_final=no)
565
566         AC_EGREP_CPP(pthread_version_draft4,[
567 #               include <pthread.h>
568                 /* this check could be improved */
569 #               ifdef pthread_once_init
570                         pthread_version_draft4;
571 #               endif
572         ], ol_pthread_draft4=yes, ol_pthread_draft4=no)
573
574         if test $ol_pthread_final = yes -a $ol_pthread_draft4 = no; then
575                 ol_cv_pthread_version=final
576         elif test $ol_pthread_final = no -a $ol_pthread_draft4 = yes; then
577                 ol_cv_pthread_version=draft4
578         else
579                 ol_cv_pthread_version=unknown
580         fi
581 ])
582 ])dnl
583 dnl
584 dnl --------------------------------------------------------------------
585 AC_DEFUN([OL_PTHREAD_TEST_INCLUDES],
586 [/* pthread test headers */
587 #include <pthread.h>
588 #ifndef NULL
589 #define NULL (void*)0
590 #endif
591
592 static void *task(p)
593         void *p;
594 {
595         return (void *) (p == NULL);
596 }
597 ])
598 AC_DEFUN([OL_PTHREAD_TEST_FUNCTION],[
599         /* pthread test function */
600         pthread_t t;
601         int status;
602 #if HAVE_PTHREADS_FINAL && defined(PTHREAD_CREATE_UNDETACHED)
603         /* This system (e.g. AIX) defaults detached; must override */
604         pthread_attr_t attr;
605
606         status = pthread_attr_init(&attr);
607         if( status ) exit( status );
608
609         status = pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_UNDETACHED);
610         if( status ) exit( status );
611
612 #define ATTR    &attr
613 #else
614 #if HAVE_PTHREADS_D4
615 #define ATTR    pthread_attr_default
616 #else
617 #define ATTR    NULL
618 #endif
619 #endif
620         /* make sure pthread_create() isn't just a stub */
621         status = pthread_create(&t, ATTR, task, NULL);
622         if( status ) exit( status );
623
624         /* make sure pthread_detach() isn't just a stub */
625 #if HAVE_PTHREADS_D4
626         status = pthread_detach( &t );
627 #else
628         status = pthread_detach( t );
629 #endif
630
631 #ifdef HAVE_LINUX_THREADS
632         pthread_kill_other_threads_np();
633 #endif
634
635         exit( status );
636 ])
637
638 AC_DEFUN([OL_PTHREAD_TEST_PROGRAM],
639 [OL_PTHREAD_TEST_INCLUDES
640
641 int main(argc, argv)
642         int argc;
643         char **argv;
644 {
645 OL_PTHREAD_TEST_FUNCTION
646 }
647 ])
648 dnl --------------------------------------------------------------------
649 AC_DEFUN([OL_PTHREAD_TRY], [# Pthread try link: $1 ($2)
650 if test "$ol_link_threads" = no ; then
651         # try $1
652         AC_CACHE_CHECK([for pthread link with $1], [$2], [
653                 # save the flags
654                 ol_LIBS="$LIBS"
655                 LIBS="$1 $LIBS"
656
657                 AC_TRY_RUN(OL_PTHREAD_TEST_PROGRAM,
658                         [$2=yes], [$2=no],
659                         [AC_TRY_LINK(OL_PTHREAD_TEST_INCLUDES,OL_PTHREAD_TEST_FUNCTION,
660                                 [$2=yes], [$2=no])])
661
662                 # restore the LIBS
663                 LIBS="$ol_LIBS"
664         ])
665
666         if test $$2 = yes ; then
667                 ol_link_pthreads="$1"
668                 ol_link_threads=posix
669         fi
670 fi
671 ])
672 dnl
673 dnl ====================================================================
674 dnl Check GNU Pth pthread Header
675 dnl
676 dnl defines ol_cv_header linux_threads to 'yes' or 'no'
677 dnl             'no' implies pthreads.h is not LinuxThreads or pthreads.h
678 dnl             doesn't exists.  Existance of pthread.h should separately
679 dnl             checked.
680 dnl 
681 AC_DEFUN([OL_HEADER_GNU_PTH_PTHREAD_H], [
682         AC_CACHE_CHECK([for GNU Pth pthread.h],
683                 [ol_cv_header_gnu_pth_pthread_h],
684                 [AC_EGREP_CPP(__gnu_pth__,
685                         [#include <pthread.h>
686 #ifdef _POSIX_THREAD_IS_GNU_PTH
687         __gnu_pth__;
688 #endif
689 ],
690                         [ol_cv_header_gnu_pth_pthread_h=yes],
691                         [ol_cv_header_gnu_pth_pthread_h=no])
692                 ])
693 ])dnl
694 dnl ====================================================================
695 dnl Check for NT Threads
696 AC_DEFUN([OL_NT_THREADS], [
697         AC_CACHE_CHECK([for NT Threads], [ol_cv_nt_threads], [
698                 AC_CHECK_FUNC(_beginthread,
699                         [ol_cv_nt_threads=yes],
700                         [ol_cv_nt_threads=no])
701         ])
702
703         if test $ol_cv_nt_threads = yes ; then
704                 AC_DEFINE(HAVE_NT_THREADS,1,[if you have NT Threads])
705         fi
706 ])
707 dnl ====================================================================
708 dnl Check LinuxThreads Header
709 dnl
710 dnl defines ol_cv_header linux_threads to 'yes' or 'no'
711 dnl             'no' implies pthreads.h is not LinuxThreads or pthreads.h
712 dnl             doesn't exists.  Existance of pthread.h should separately
713 dnl             checked.
714 dnl 
715 AC_DEFUN([OL_HEADER_LINUX_THREADS], [
716         AC_CACHE_CHECK([for LinuxThreads pthread.h],
717                 [ol_cv_header_linux_threads],
718                 [AC_EGREP_CPP(pthread_kill_other_threads_np,
719                         [#include <pthread.h>],
720                         [ol_cv_header_linux_threads=yes],
721                         [ol_cv_header_linux_threads=no])
722                 ])
723         if test $ol_cv_header_linux_threads = yes; then
724                 AC_DEFINE(HAVE_LINUX_THREADS,1,[if you have LinuxThreads])
725         fi
726 ])dnl
727 dnl --------------------------------------------------------------------
728 dnl     Check LinuxThreads Implementation
729 dnl
730 dnl     defines ol_cv_sys_linux_threads to 'yes' or 'no'
731 dnl     'no' implies pthreads implementation is not LinuxThreads.
732 dnl 
733 AC_DEFUN([OL_SYS_LINUX_THREADS], [
734         AC_CHECK_FUNC(pthread_kill_other_threads_np)
735         AC_CACHE_CHECK([for LinuxThreads implementation],
736                 [ol_cv_sys_linux_threads],
737                 [ol_cv_sys_linux_threads=$ac_cv_func_pthread_kill_other_threads_np])
738 ])dnl
739 dnl
740 dnl --------------------------------------------------------------------
741 dnl Check LinuxThreads consistency
742 AC_DEFUN([OL_LINUX_THREADS], [
743         AC_REQUIRE([OL_HEADER_LINUX_THREADS])
744         AC_REQUIRE([OL_SYS_LINUX_THREADS])
745         AC_CACHE_CHECK([for LinuxThreads consistency], [ol_cv_linux_threads], [
746                 if test $ol_cv_header_linux_threads = yes -a \
747                         $ol_cv_sys_linux_threads = yes; then
748                         ol_cv_linux_threads=yes
749                 elif test $ol_cv_header_linux_threads = no -a \
750                         $ol_cv_sys_linux_threads = no; then
751                         ol_cv_linux_threads=no
752                 else
753                         ol_cv_linux_threads=error
754                 fi
755         ])
756 ])dnl
757 dnl
758 dnl ====================================================================
759 dnl Check for POSIX Regex
760 AC_DEFUN([OL_POSIX_REGEX], [
761 AC_CACHE_CHECK([for compatible POSIX regex],ol_cv_c_posix_regex,[
762         AC_TRY_RUN([
763 #include <sys/types.h>
764 #include <regex.h>
765 static char *pattern, *string;
766 main()
767 {
768         int rc;
769         regex_t re;
770
771         pattern = "^A";
772
773         if(regcomp(&re, pattern, 0)) {
774                 return -1;
775         }
776         
777         string = "ALL MATCH";
778         
779         rc = regexec(&re, string, 0, (void*)0, 0);
780
781         regfree(&re);
782
783         return rc;
784 }],
785         [ol_cv_c_posix_regex=yes],
786         [ol_cv_c_posix_regex=no],
787         [ol_cv_c_posix_regex=cross])])
788 ])
789 dnl
790 dnl ====================================================================
791 dnl Check if toupper() requires islower() to be called first
792 AC_DEFUN([OL_C_UPPER_LOWER],
793 [AC_CACHE_CHECK([if toupper() requires islower()],ol_cv_c_upper_lower,[
794         AC_TRY_RUN([
795 #include <ctype.h>
796 main()
797 {
798         if ('C' == toupper('C'))
799                 exit(0);
800         else
801                 exit(1);
802 }],
803         [ol_cv_c_upper_lower=no],
804         [ol_cv_c_upper_lower=yes],
805         [ol_cv_c_upper_lower=safe])])
806 if test $ol_cv_c_upper_lower != no ; then
807         AC_DEFINE(C_UPPER_LOWER,1, [define if toupper() requires islower()])
808 fi
809 ])
810 dnl
811 dnl ====================================================================
812 dnl Check for declaration of sys_errlist in one of stdio.h and errno.h.
813 dnl Declaration of sys_errlist on BSD4.4 interferes with our declaration.
814 dnl Reported by Keith Bostic.
815 AC_DEFUN([OL_SYS_ERRLIST],
816 [AC_CACHE_CHECK([declaration of sys_errlist],ol_cv_dcl_sys_errlist,[
817         AC_TRY_COMPILE([
818 #include <stdio.h>
819 #include <sys/types.h>
820 #include <errno.h>
821 #ifdef WINNT
822 #include <stdlib.h>
823 #endif ],
824         [char *c = (char *) *sys_errlist],
825         [ol_cv_dcl_sys_errlist=yes
826         ol_cv_have_sys_errlist=yes],
827         [ol_cv_dcl_sys_errlist=no])])
828 #
829 # It's possible (for near-UNIX clones) that sys_errlist doesn't exist
830 if test $ol_cv_dcl_sys_errlist = no ; then
831         AC_DEFINE(DECL_SYS_ERRLIST,1,
832                 [define if sys_errlist is not declared in stdio.h or errno.h])
833
834         AC_CACHE_CHECK([existence of sys_errlist],ol_cv_have_sys_errlist,[
835                 AC_TRY_LINK([#include <errno.h>],
836                         [char *c = (char *) *sys_errlist],
837                         [ol_cv_have_sys_errlist=yes],
838                         [ol_cv_have_sys_errlist=no])])
839 fi
840 if test $ol_cv_have_sys_errlist = yes ; then
841         AC_DEFINE(HAVE_SYS_ERRLIST,1,
842                 [define if you actually have sys_errlist in your libs])
843 fi
844 ])dnl
845 dnl
846 dnl ====================================================================
847 dnl Early MIPS compilers (used in Ultrix 4.2) don't like
848 dnl "int x; int *volatile a = &x; *a = 0;"
849 dnl     -- borrowed from PDKSH
850 AC_DEFUN(OL_C_VOLATILE,
851  [AC_CACHE_CHECK(if compiler understands volatile, ol_cv_c_volatile,
852     [AC_TRY_COMPILE([int x, y, z;],
853       [volatile int a; int * volatile b = x ? &y : &z;
854       /* Older MIPS compilers (eg., in Ultrix 4.2) don't like *b = 0 */
855       *b = 0;], ol_cv_c_volatile=yes, ol_cv_c_volatile=no)])
856   if test $ol_cv_c_volatile = yes; then
857     : 
858   else
859     AC_DEFINE(volatile,,[define as empty if volatile is not supported])
860   fi
861  ])dnl
862 dnl
863 dnl ====================================================================
864 dnl Look for fetch(3)
865 AC_DEFUN([OL_LIB_FETCH],
866 [ol_LIBS=$LIBS
867 LIBS="-lfetch -lcom_err $LIBS"
868 AC_CACHE_CHECK([fetch(3) library],ol_cv_lib_fetch,[
869         AC_TRY_LINK([
870 #include <sys/param.h>
871 #include <stdio.h>
872 #include <fetch.h>],
873         [struct url *u = fetchParseURL("file:///"); ],
874         [ol_cv_lib_fetch=yes],
875         [ol_cv_lib_fetch=no])])
876 LIBS=$ol_LIBS
877 if test $ol_cv_lib_fetch != no ; then
878         ol_link_fetch="-lfetch -lcom_err"
879         AC_DEFINE(HAVE_FETCH,1,
880                 [define if you actually have FreeBSD fetch(3)])
881 fi
882 ])dnl
883 dnl
884 dnl ====================================================================
885 dnl Define sig_atomic_t if not defined in signal.h
886 AC_DEFUN(OL_TYPE_SIG_ATOMIC_T,
887  [AC_CACHE_CHECK(for sig_atomic_t, ol_cv_type_sig_atomic_t,
888     [AC_TRY_COMPILE([#include <signal.h>], [sig_atomic_t atomic;],
889                 ol_cv_type_sig_atomic_t=yes, ol_cv_type_sig_atomic_t=no)])
890   if test $ol_cv_type_sig_atomic_t = no; then
891     AC_DEFINE(sig_atomic_t,int,
892                 [define to atomic type if sig_atomic_t is not available])
893   fi
894  ])dnl
895 dnl
896 dnl ====================================================================
897 dnl Define socklen_t if not defined in sys/types.h or sys/socket.h
898 AC_DEFUN(OL_TYPE_SOCKLEN_T,
899  [AC_CACHE_CHECK(for socklen_t, ol_cv_type_socklen_t,
900     [AC_TRY_COMPILE([
901 #ifdef HAVE_SYS_TYPES_H
902 #include <sys/types.h>
903 #endif
904 #ifdef HAVE_SYS_SOCKET_H
905 #include <sys/socket.h>
906 #endif
907 ], [socklen_t len;],
908                 ol_cv_type_socklen_t=yes, ol_cv_type_socklen_t=no)])
909   if test $ol_cv_type_socklen_t = no; then
910     AC_DEFINE(socklen_t, int,
911                 [define to int if socklen_t is not available])
912   fi
913  ])dnl
914 dnl
915 dnl ====================================================================
916 dnl Define inet_aton is available
917 AC_DEFUN(OL_FUNC_INET_ATON,
918  [AC_CACHE_CHECK([for inet_aton()], ol_cv_func_inet_aton,
919     [AC_TRY_LINK([
920 #ifdef HAVE_SYS_TYPES_H
921 #       include <sys/types.h>
922 #endif
923 #ifdef HAVE_SYS_SOCKET_H
924 #       include <sys/socket.h>
925 #       ifdef HAVE_SYS_SELECT_H
926 #               include <sys/select.h>
927 #       endif
928 #       include <netinet/in.h>
929 #       ifdef HAVE_ARPA_INET_H
930 #               include <arpa/inet.h>
931 #       endif
932 #endif
933 ], [struct in_addr in;
934 int rc = inet_aton( "255.255.255.255", &in );],
935                 ol_cv_func_inet_aton=yes, ol_cv_func_inet_aton=no)])
936   if test $ol_cv_func_inet_aton != no; then
937     AC_DEFINE(HAVE_INET_ATON, 1,
938                 [define to you inet_aton(3) is available])
939   fi
940  ])dnl
941 dnl
942 dnl ====================================================================
943 dnl check no of arguments for ctime_r
944 AC_DEFUN(OL_FUNC_CTIME_R_NARGS,
945  [AC_CACHE_CHECK(number of arguments of ctime_r, ol_cv_func_ctime_r_nargs,
946    [AC_TRY_COMPILE([#include <time.h>],
947                 [time_t ti; char *buffer; ctime_r(&ti,buffer,32);],
948                         ol_cv_func_ctime_r_nargs3=yes,
949                         ol_cv_func_ctime_r_nargs3=no)
950
951         AC_TRY_COMPILE([#include <time.h>],
952                 [time_t ti; char *buffer; ctime_r(&ti,buffer);],
953                         ol_cv_func_ctime_r_nargs2=yes,
954                         ol_cv_func_ctime_r_nargs2=no)
955
956         if test $ol_cv_func_ctime_r_nargs3 = yes -a \
957                 $ol_cv_func_ctime_r_nargs2 = no ; then
958
959                 ol_cv_func_ctime_r_nargs=3
960
961         elif test $ol_cv_func_ctime_r_nargs3 = no -a \
962                 $ol_cv_func_ctime_r_nargs2 = yes ; then
963
964                 ol_cv_func_ctime_r_nargs=2
965
966         else
967                 ol_cv_func_ctime_r_nargs=0
968         fi
969   ])
970
971   if test $ol_cv_func_ctime_r_nargs -gt 1 ; then
972         AC_DEFINE_UNQUOTED(CTIME_R_NARGS, $ol_cv_func_ctime_r_nargs,
973                 [set to the number of arguments ctime_r() expects])
974   fi
975 ])dnl
976 dnl
977 dnl --------------------------------------------------------------------
978 dnl check return type of ctime_r()
979 AC_DEFUN(OL_FUNC_CTIME_R_TYPE,
980  [AC_CACHE_CHECK(return type of ctime_r, ol_cv_func_ctime_r_type,
981    [AC_TRY_COMPILE([#include <time.h>],
982                 [extern int (ctime_r)();],
983                         ol_cv_func_ctime_r_type="int", ol_cv_func_ctime_r_type="charp")
984         ])
985   if test $ol_cv_func_ctime_r_type = "int" ; then
986         AC_DEFINE(CTIME_R_RETURNS_INT,1, [define if ctime_r() returns int])
987   fi
988 ])dnl
989 dnl ====================================================================
990 dnl check no of arguments for gethostbyname_r
991 AC_DEFUN(OL_FUNC_GETHOSTBYNAME_R_NARGS,
992  [AC_CACHE_CHECK(number of arguments of gethostbyname_r,
993         ol_cv_func_gethostbyname_r_nargs,
994         [AC_TRY_COMPILE([#include <sys/types.h>
995 #include <sys/socket.h>
996 #include <netinet/in.h>
997 #include <netdb.h>
998 #define BUFSIZE (sizeof(struct hostent)+10)],
999                 [struct hostent hent; char buffer[BUFSIZE];
1000                 int bufsize=BUFSIZE;int h_errno;
1001                 (void)gethostbyname_r("segovia.cs.purdue.edu", &hent,
1002                         buffer, bufsize, &h_errno);],
1003                 ol_cv_func_gethostbyname_r_nargs5=yes, 
1004                 ol_cv_func_gethostbyname_r_nargs5=no)
1005
1006         AC_TRY_COMPILE([#include <sys/types.h>
1007 #include <sys/socket.h>
1008 #include <netinet/in.h>
1009 #include <netdb.h>
1010 #define BUFSIZE (sizeof(struct hostent)+10)],
1011                 [struct hostent hent;struct hostent *rhent;
1012                 char buffer[BUFSIZE];
1013                 int bufsize=BUFSIZE;int h_errno;
1014                 (void)gethostbyname_r("localhost", &hent, buffer, bufsize,
1015                         &rhent, &h_errno);],
1016                 ol_cv_func_gethostbyname_r_nargs6=yes,
1017                 ol_cv_func_gethostbyname_r_nargs6=no)
1018
1019         if test $ol_cv_func_gethostbyname_r_nargs5 = yes -a \
1020                 $ol_cv_func_gethostbyname_r_nargs6 = no ; then
1021
1022                 ol_cv_func_gethostbyname_r_nargs=5
1023
1024         elif test $ol_cv_func_gethostbyname_r_nargs5 = no -a \
1025                 $ol_cv_func_gethostbyname_r_nargs6 = yes ; then
1026
1027                 ol_cv_func_gethostbyname_r_nargs=6
1028
1029         else
1030                 ol_cv_func_gethostbyname_r_nargs=0
1031         fi
1032   ])
1033   if test $ol_cv_func_gethostbyname_r_nargs -gt 1 ; then
1034         AC_DEFINE_UNQUOTED(GETHOSTBYNAME_R_NARGS,
1035                 $ol_cv_func_gethostbyname_r_nargs,
1036                 [set to the number of arguments gethostbyname_r() expects])
1037   fi
1038 ])dnl
1039 dnl
1040 dnl check no of arguments for gethostbyaddr_r
1041 AC_DEFUN(OL_FUNC_GETHOSTBYADDR_R_NARGS,
1042  [AC_CACHE_CHECK(number of arguments of gethostbyaddr_r,
1043         [ol_cv_func_gethostbyaddr_r_nargs],
1044         [AC_TRY_COMPILE([#include <sys/types.h>
1045 #include <sys/socket.h>
1046 #include <netinet/in.h>
1047 #include <netdb.h>
1048 #define BUFSIZE (sizeof(struct hostent)+10)],
1049            [struct hostent hent; char buffer[BUFSIZE]; 
1050             struct in_addr add;
1051             size_t alen=sizeof(struct in_addr);
1052             int bufsize=BUFSIZE;int h_errno;
1053                 (void)gethostbyaddr_r( (void *)&(add.s_addr),
1054                         alen, AF_INET, &hent, buffer, bufsize, &h_errno);],
1055                 ol_cv_func_gethostbyaddr_r_nargs7=yes,
1056                 ol_cv_func_gethostbyaddr_r_nargs7=no)
1057
1058         AC_TRY_COMPILE([#include <sys/types.h>
1059 #include <sys/socket.h>
1060 #include <netinet/in.h>
1061 #include <netdb.h>
1062 #define BUFSIZE (sizeof(struct hostent)+10)],
1063                 [struct hostent hent;
1064                 struct hostent *rhent; char buffer[BUFSIZE]; 
1065                 struct in_addr add;
1066                 size_t alen=sizeof(struct in_addr);
1067                 int bufsize=BUFSIZE;int h_errno;
1068                 (void)gethostbyaddr_r( (void *)&(add.s_addr),
1069                         alen, AF_INET, &hent, buffer, bufsize, 
1070                         &rhent, &h_errno);],
1071                 ol_cv_func_gethostbyaddr_r_nargs8=yes,
1072                 ol_cv_func_gethostbyaddr_r_nargs8=no)
1073
1074         if test $ol_cv_func_gethostbyaddr_r_nargs7 = yes -a \
1075                 $ol_cv_func_gethostbyaddr_r_nargs8 = no ; then
1076
1077                 ol_cv_func_gethostbyaddr_r_nargs=7
1078
1079         elif test $ol_cv_func_gethostbyaddr_r_nargs7 = no -a \
1080                 $ol_cv_func_gethostbyaddr_r_nargs8 = yes ; then
1081
1082                 ol_cv_func_gethostbyaddr_r_nargs=8
1083
1084         else
1085                 ol_cv_func_gethostbyaddr_r_nargs=0
1086         fi
1087   ])
1088   if test $ol_cv_func_gethostbyaddr_r_nargs -gt 1 ; then
1089     AC_DEFINE_UNQUOTED(GETHOSTBYADDR_R_NARGS,
1090                 $ol_cv_func_gethostbyaddr_r_nargs,
1091                 [set to the number of arguments gethostbyaddr_r() expects])
1092   fi
1093 ])dnl
1094 dnl