]> git.sur5r.net Git - openldap/blob - build/openldap.m4
bb5260d26d8019e3537efa15ab28e9cc587c33ed
[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,changequote(<,>)<$2 [>ifelse($3,,auto,$3)<]>changequote([,]),[
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,changequote(<,>)<$2 [>ifelse($3,,yes,$3)<]>changequote([,]),[
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_INIT_CDB | DB_INIT_MPOOL |
319 #ifdef DB_PRIVATE
320                 DB_PRIVATE |
321 #endif
322 #ifdef DB_MPOOL_PRIVATE
323                 DB_MPOOL_PRIVATE |
324 #endif
325                 DB_THREAD;
326
327 #if DB_VERSION_MAJOR > 2
328         DB_ENV *env = NULL;
329
330         rc = db_env_create( &env, 0 );
331
332         if( rc ) return rc;
333
334 #ifdef DB_CDB_ALLDB
335         rc = env->set_flags( env, DB_CDB_ALLDB, 1 );
336         if( rc ) goto done;
337 #endif
338
339 #if (DB_VERSION_MAJOR > 3) || (DB_VERSION_MINOR >= 1)
340         rc = env->open( env, NULL, flags, 0 );
341 #else
342         rc = env->open( env, NULL, NULL, flags, 0 );
343 #endif
344
345 #ifdef DB_CDB_ALLDB
346 done:
347 #endif
348 #if (DB_VERSION_MAJOR > 3) || (DB_VERSION_MINOR >= 1)
349         env->remove( env, NULL, DB_FORCE);
350 #else
351         env->remove( env, NULL, NULL, DB_FORCE);
352 #endif
353
354 #else
355         DB_ENV env;
356         memset( &env, '\0', sizeof(env) );
357
358         rc = db_appinit( NULL, NULL, &env, flags );
359
360         if( rc == 0 ) {
361                 db_appexit( &env );
362         }
363 #endif
364
365         return rc;
366 }],
367         [ol_cv_berkeley_db_thread=yes],
368         [ol_cv_berkeley_db_thread=no],
369         [ol_cv_berkeley_db_thread=cross])
370
371         LIBS="$ol_LIBS"
372
373         if test $ol_cv_berkeley_db_thread != no ; then
374                 AC_DEFINE(HAVE_BERKELEY_DB_THREAD, 1,
375                         [define if Berkeley DB has DB_THREAD support])
376         fi
377 ])])dnl
378 dnl
379 dnl --------------------------------------------------------------------
380 dnl Find any DB
381 AC_DEFUN([OL_BERKELEY_DB],
382 [ol_cv_berkeley_db=no
383 AC_CHECK_HEADERS(db.h)
384 if test $ac_cv_header_db_h = yes; then
385         OL_BERKELEY_DB_LINK
386         if test "$ol_cv_lib_db" != no ; then
387                 ol_cv_berkeley_db=yes
388                 OL_BERKELEY_DB_THREAD
389         fi
390 fi
391 ])
392 dnl
393 dnl --------------------------------------------------------------------
394 dnl Find old Berkeley DB 1.85/1.86
395 AC_DEFUN([OL_BERKELEY_COMPAT_DB],
396 [ol_cv_berkeley_db=no
397 AC_CHECK_HEADERS(db_185.h db.h)
398 if test $ac_cv_header_db_185_h = yes -o $ac_cv_header_db_h = yes; then
399         AC_CACHE_CHECK([if Berkeley DB header compatibility], [ol_cv_header_db1],[
400                 AC_EGREP_CPP(__db_version_1,[
401 #if HAVE_DB_185_H
402 #       include <db_185.h>
403 #else
404 #       include <db.h>
405 #endif
406
407  /* this check could be improved */
408 #ifndef DB_VERSION_MAJOR
409 #       define DB_VERSION_MAJOR 1
410 #endif
411
412 #if DB_VERSION_MAJOR == 1 
413         __db_version_1
414 #endif
415 ],      [ol_cv_header_db1=yes], [ol_cv_header_db1=no])])
416
417         if test ol_cv_header_db1=yes ; then
418                 OL_BERKELEY_DB_LINK
419                 if test "$ol_cv_lib_db" != no ; then
420                         ol_cv_berkeley_db=yes
421                 fi
422         fi
423 fi
424 ])
425 dnl
426 dnl ====================================================================
427 dnl Check if GDBM library exists
428 dnl Check for gdbm_open in standard libraries or -lgdbm
429 dnl
430 dnl defines ol_cv_lib_gdbm to 'yes' or '-lgdbm' or 'no'
431 dnl             'yes' implies gdbm_open is in $LIBS
432 dnl
433 dnl uses:
434 dnl             AC_CHECK_FUNC(gdbm_open)
435 dnl             AC_CHECK_LIB(gdbm,gdbm_open)
436 dnl
437 AC_DEFUN([OL_LIB_GDBM],
438 [AC_CACHE_CHECK(for GDBM library, [ol_cv_lib_gdbm],
439 [       ol_LIBS="$LIBS"
440         AC_CHECK_FUNC(gdbm_open,[ol_cv_lib_gdbm=yes], [
441                 AC_CHECK_LIB(gdbm,gdbm_open,[ol_cv_lib_gdbm=-lgdbm],[ol_cv_lib_gdbm=no])
442         ])
443         LIBS="$ol_LIBS"
444 ])
445 ])dnl
446 dnl
447 dnl --------------------------------------------------------------------
448 dnl Check if GDBM exists
449 dnl
450 dnl defines ol_cv_gdbm to 'yes' or 'no'
451 dnl 
452 dnl uses:
453 dnl             OL_LIB_GDBM
454 dnl             AC_CHECK_HEADERS(gdbm.h)
455 dnl
456 AC_DEFUN([OL_GDBM],
457 [AC_REQUIRE([OL_LIB_GDBM])
458  AC_CHECK_HEADERS(gdbm.h)
459  AC_CACHE_CHECK(for db, [ol_cv_gdbm], [
460         if test $ol_cv_lib_gdbm = no -o $ac_cv_header_gdbm_h = no ; then
461                 ol_cv_gdbm=no
462         else
463                 ol_cv_gdbm=yes
464         fi
465 ])
466  if test $ol_cv_gdbm = yes ; then
467         AC_DEFINE(HAVE_GDBM,1, [define if GNU DBM is available])
468  fi
469 ])dnl
470 dnl
471 dnl ====================================================================
472 dnl Check if MDBM library exists
473 dnl Check for mdbm_open in standard libraries or -lmdbm
474 dnl
475 dnl defines ol_cv_lib_mdbm to 'yes' or '-lmdbm' or 'no'
476 dnl             'yes' implies mdbm_open is in $LIBS
477 dnl
478 dnl uses:
479 dnl             AC_CHECK_FUNC(mdbm_set_chain)
480 dnl             AC_CHECK_LIB(mdbm,mdbm_set_chain)
481 dnl
482 AC_DEFUN([OL_LIB_MDBM],
483 [AC_CACHE_CHECK(for MDBM library, [ol_cv_lib_mdbm],
484 [       ol_LIBS="$LIBS"
485         AC_CHECK_FUNC(mdbm_set_chain,[ol_cv_lib_mdbm=yes], [
486                 AC_CHECK_LIB(mdbm,mdbm_set_chain,[ol_cv_lib_mdbm=-lmdbm],[ol_cv_lib_mdbm=no])
487         ])
488         LIBS="$ol_LIBS"
489 ])
490 ])dnl
491 dnl
492 dnl --------------------------------------------------------------------
493 dnl Check if MDBM exists
494 dnl
495 dnl defines ol_cv_mdbm to 'yes' or 'no'
496 dnl 
497 dnl uses:
498 dnl             OL_LIB_MDBM
499 dnl             AC_CHECK_HEADERS(mdbm.h)
500 dnl
501 AC_DEFUN([OL_MDBM],
502 [AC_REQUIRE([OL_LIB_MDBM])
503  AC_CHECK_HEADERS(mdbm.h)
504  AC_CACHE_CHECK(for db, [ol_cv_mdbm], [
505         if test $ol_cv_lib_mdbm = no -o $ac_cv_header_mdbm_h = no ; then
506                 ol_cv_mdbm=no
507         else
508                 ol_cv_mdbm=yes
509         fi
510 ])
511  if test $ol_cv_mdbm = yes ; then
512         AC_DEFINE(HAVE_MDBM,1, [define if MDBM is available])
513  fi
514 ])dnl
515 dnl
516 dnl ====================================================================
517 dnl Check if NDBM library exists
518 dnl Check for dbm_open in standard libraries or -lndbm or -ldbm
519 dnl
520 dnl defines ol_cv_lib_ndbm to 'yes' or '-lndbm' or -ldbm or 'no'
521 dnl             'yes' implies ndbm_open is in $LIBS
522 dnl
523 dnl uses:
524 dnl             AC_CHECK_FUNC(dbm_open)
525 dnl             AC_CHECK_LIB(ndbm,dbm_open)
526 dnl             AC_CHECK_LIB(dbm,dbm_open)
527 dnl
528 dnl restrictions:
529 dnl             should also check SVR4 case: dbm_open() in -lucb but that
530 dnl             would requiring dealing with -L/usr/ucblib
531 dnl
532 AC_DEFUN([OL_LIB_NDBM],
533 [AC_CACHE_CHECK(for NDBM library, [ol_cv_lib_ndbm],
534 [       ol_LIBS="$LIBS"
535         AC_CHECK_FUNC(dbm_open,[ol_cv_lib_ndbm=yes], [
536                 AC_CHECK_LIB(ndbm,dbm_open,[ol_cv_lib_ndbm=-lndbm], [
537                         AC_CHECK_LIB(dbm,dbm_open,[ol_cv_lib_ndbm=-ldbm],
538                                 [ol_cv_lib_ndbm=no])dnl
539                 ])
540         ])
541         LIBS="$ol_LIBS"
542 ])
543 ])dnl
544 dnl
545 dnl --------------------------------------------------------------------
546 dnl Check if NDBM exists
547 dnl
548 dnl defines ol_cv_ndbm to 'yes' or 'no'
549 dnl 
550 dnl uses:
551 dnl             OL_LIB_NDBM
552 dnl             AC_CHECK_HEADERS(ndbm.h)
553 dnl
554 dnl restrictions:
555 dnl             Doesn't handle SVR4 case (see above)
556 dnl
557 AC_DEFUN([OL_NDBM],
558 [AC_REQUIRE([OL_LIB_NDBM])
559  AC_CHECK_HEADERS(ndbm.h)
560  AC_CACHE_CHECK(for db, [ol_cv_ndbm], [
561         if test $ol_cv_lib_ndbm = no -o $ac_cv_header_ndbm_h = no ; then
562                 ol_cv_ndbm=no
563         else
564                 ol_cv_ndbm=yes
565         fi
566 ])
567  if test $ol_cv_ndbm = yes ; then
568         AC_DEFINE(HAVE_NDBM,1, [define if NDBM is available])
569  fi
570 ])dnl
571 dnl
572 dnl ====================================================================
573 dnl Check POSIX Thread version 
574 dnl
575 dnl defines ol_cv_posix_version to 'final' or 'draft' or 'unknown'
576 dnl     'unknown' implies that the version could not be detected
577 dnl             or that pthreads.h does exist.  Existance of pthreads.h
578 dnl             should be tested separately.
579 dnl
580 AC_DEFUN([OL_POSIX_THREAD_VERSION],
581 [AC_CACHE_CHECK([POSIX thread version],[ol_cv_pthread_version],[
582         AC_EGREP_CPP(pthread_version_final,[
583 #               include <pthread.h>
584                 /* this check could be improved */
585 #               ifdef PTHREAD_ONCE_INIT
586                         pthread_version_final;
587 #               endif
588         ], ol_pthread_final=yes, ol_pthread_final=no)
589
590         AC_EGREP_CPP(pthread_version_draft4,[
591 #               include <pthread.h>
592                 /* this check could be improved */
593 #               ifdef pthread_once_init
594                         pthread_version_draft4;
595 #               endif
596         ], ol_pthread_draft4=yes, ol_pthread_draft4=no)
597
598         if test $ol_pthread_final = yes -a $ol_pthread_draft4 = no; then
599                 ol_cv_pthread_version=final
600         elif test $ol_pthread_final = no -a $ol_pthread_draft4 = yes; then
601                 ol_cv_pthread_version=draft4
602         else
603                 ol_cv_pthread_version=unknown
604         fi
605 ])
606 ])dnl
607 dnl
608 dnl --------------------------------------------------------------------
609 AC_DEFUN([OL_PTHREAD_TEST_INCLUDES],
610 [/* pthread test headers */
611 #include <pthread.h>
612 #ifndef NULL
613 #define NULL (void*)0
614 #endif
615
616 static void *task(p)
617         void *p;
618 {
619         return (void *) (p == NULL);
620 }
621 ])
622 AC_DEFUN([OL_PTHREAD_TEST_FUNCTION],[
623         /* pthread test function */
624         pthread_t t;
625         int status;
626 #if HAVE_PTHREADS_FINAL && defined(PTHREAD_CREATE_UNDETACHED)
627         /* This system (e.g. AIX) defaults detached; must override */
628         pthread_attr_t attr;
629
630         status = pthread_attr_init(&attr);
631         if( status ) exit( status );
632
633         status = pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_UNDETACHED);
634         if( status ) exit( status );
635
636 #       define  ATTR    &attr
637 #elif defined( HAVE_PTHREADS_D4 )
638 #       define  ATTR    pthread_attr_default
639 #else
640 #       define  ATTR    NULL
641 #endif
642
643         /* make sure pthread_create() isn't just a stub */
644         status = pthread_create(&t, ATTR, task, NULL);
645         if( status ) exit( status );
646
647         /* give the thread a chance to complete...
648      * it should remain joinable and hence detachable
649          */
650         sleep( 1 );
651
652         /* make sure pthread_detach() isn't just a stub */
653 #if HAVE_PTHREADS_D4
654         status = pthread_detach( &t );
655 #else
656         status = pthread_detach( t );
657 #endif
658
659 #ifdef HAVE_LINUX_THREADS
660         pthread_kill_other_threads_np();
661 #endif
662
663         exit( status );
664 ])
665
666 AC_DEFUN([OL_PTHREAD_TEST_PROGRAM],
667 [OL_PTHREAD_TEST_INCLUDES
668
669 int main(argc, argv)
670         int argc;
671         char **argv;
672 {
673 OL_PTHREAD_TEST_FUNCTION
674 }
675 ])
676 dnl --------------------------------------------------------------------
677 AC_DEFUN([OL_PTHREAD_TRY], [# Pthread try link: $1 ($2)
678 if test "$ol_link_threads" = no ; then
679         # try $1
680         AC_CACHE_CHECK([for pthread link with $1], [$2], [
681                 # save the flags
682                 ol_LIBS="$LIBS"
683                 LIBS="$1 $LIBS"
684
685                 AC_TRY_RUN(OL_PTHREAD_TEST_PROGRAM,
686                         [$2=yes], [$2=no],
687                         [AC_TRY_LINK(OL_PTHREAD_TEST_INCLUDES,OL_PTHREAD_TEST_FUNCTION,
688                                 [$2=yes], [$2=no])])
689
690                 # restore the LIBS
691                 LIBS="$ol_LIBS"
692         ])
693
694         if test $$2 = yes ; then
695                 ol_link_pthreads="$1"
696                 ol_link_threads=posix
697         fi
698 fi
699 ])
700 dnl
701 dnl ====================================================================
702 dnl Check GNU Pth pthread Header
703 dnl
704 dnl defines ol_cv_header linux_threads to 'yes' or 'no'
705 dnl             'no' implies pthreads.h is not LinuxThreads or pthreads.h
706 dnl             doesn't exists.  Existance of pthread.h should separately
707 dnl             checked.
708 dnl 
709 AC_DEFUN([OL_HEADER_GNU_PTH_PTHREAD_H], [
710         AC_CACHE_CHECK([for GNU Pth pthread.h],
711                 [ol_cv_header_gnu_pth_pthread_h],
712                 [AC_EGREP_CPP(__gnu_pth__,
713                         [#include <pthread.h>
714 #ifdef _POSIX_THREAD_IS_GNU_PTH
715         __gnu_pth__;
716 #endif
717 ],
718                         [ol_cv_header_gnu_pth_pthread_h=yes],
719                         [ol_cv_header_gnu_pth_pthread_h=no])
720                 ])
721 ])dnl
722 dnl ====================================================================
723 dnl Check for NT Threads
724 AC_DEFUN([OL_NT_THREADS], [
725         AC_CHECK_FUNC(_beginthread)
726
727         if test $ac_cv_func__beginthread = yes ; then
728                 AC_DEFINE(HAVE_NT_THREADS,1,[if you have NT Threads])
729         fi
730 ])
731 dnl ====================================================================
732 dnl Check LinuxThreads Header
733 dnl
734 dnl defines ol_cv_header linux_threads to 'yes' or 'no'
735 dnl             'no' implies pthreads.h is not LinuxThreads or pthreads.h
736 dnl             doesn't exists.  Existance of pthread.h should separately
737 dnl             checked.
738 dnl 
739 AC_DEFUN([OL_HEADER_LINUX_THREADS], [
740         AC_CACHE_CHECK([for LinuxThreads pthread.h],
741                 [ol_cv_header_linux_threads],
742                 [AC_EGREP_CPP(pthread_kill_other_threads_np,
743                         [#include <pthread.h>],
744                         [ol_cv_header_linux_threads=yes],
745                         [ol_cv_header_linux_threads=no])
746                 ])
747         if test $ol_cv_header_linux_threads = yes; then
748                 AC_DEFINE(HAVE_LINUX_THREADS,1,[if you have LinuxThreads])
749         fi
750 ])dnl
751 dnl --------------------------------------------------------------------
752 dnl     Check LinuxThreads Implementation
753 dnl
754 dnl     defines ol_cv_sys_linux_threads to 'yes' or 'no'
755 dnl     'no' implies pthreads implementation is not LinuxThreads.
756 dnl 
757 AC_DEFUN([OL_SYS_LINUX_THREADS], [
758         AC_CHECK_FUNCS(pthread_kill_other_threads_np)
759         AC_CACHE_CHECK([for LinuxThreads implementation],
760                 [ol_cv_sys_linux_threads],
761                 [ol_cv_sys_linux_threads=$ac_cv_func_pthread_kill_other_threads_np])
762 ])dnl
763 dnl
764 dnl --------------------------------------------------------------------
765 dnl Check LinuxThreads consistency
766 AC_DEFUN([OL_LINUX_THREADS], [
767         AC_REQUIRE([OL_HEADER_LINUX_THREADS])
768         AC_REQUIRE([OL_SYS_LINUX_THREADS])
769         AC_CACHE_CHECK([for LinuxThreads consistency], [ol_cv_linux_threads], [
770                 if test $ol_cv_header_linux_threads = yes -a \
771                         $ol_cv_sys_linux_threads = yes; then
772                         ol_cv_linux_threads=yes
773                 elif test $ol_cv_header_linux_threads = no -a \
774                         $ol_cv_sys_linux_threads = no; then
775                         ol_cv_linux_threads=no
776                 else
777                         ol_cv_linux_threads=error
778                 fi
779         ])
780 ])dnl
781 dnl
782 dnl ====================================================================
783 dnl Check for POSIX Regex
784 AC_DEFUN([OL_POSIX_REGEX], [
785 AC_CACHE_CHECK([for compatible POSIX regex],ol_cv_c_posix_regex,[
786         AC_TRY_RUN([
787 #include <sys/types.h>
788 #include <regex.h>
789 static char *pattern, *string;
790 main()
791 {
792         int rc;
793         regex_t re;
794
795         pattern = "^A";
796
797         if(regcomp(&re, pattern, 0)) {
798                 return -1;
799         }
800         
801         string = "ALL MATCH";
802         
803         rc = regexec(&re, string, 0, (void*)0, 0);
804
805         regfree(&re);
806
807         return rc;
808 }],
809         [ol_cv_c_posix_regex=yes],
810         [ol_cv_c_posix_regex=no],
811         [ol_cv_c_posix_regex=cross])])
812 ])
813 dnl
814 dnl ====================================================================
815 dnl Check if toupper() requires islower() to be called first
816 AC_DEFUN([OL_C_UPPER_LOWER],
817 [AC_CACHE_CHECK([if toupper() requires islower()],ol_cv_c_upper_lower,[
818         AC_TRY_RUN([
819 #include <ctype.h>
820 main()
821 {
822         if ('C' == toupper('C'))
823                 exit(0);
824         else
825                 exit(1);
826 }],
827         [ol_cv_c_upper_lower=no],
828         [ol_cv_c_upper_lower=yes],
829         [ol_cv_c_upper_lower=safe])])
830 if test $ol_cv_c_upper_lower != no ; then
831         AC_DEFINE(C_UPPER_LOWER,1, [define if toupper() requires islower()])
832 fi
833 ])
834 dnl
835 dnl ====================================================================
836 dnl Check for declaration of sys_errlist in one of stdio.h and errno.h.
837 dnl Declaration of sys_errlist on BSD4.4 interferes with our declaration.
838 dnl Reported by Keith Bostic.
839 AC_DEFUN([OL_SYS_ERRLIST],
840 [AC_CACHE_CHECK([declaration of sys_errlist],ol_cv_dcl_sys_errlist,[
841         AC_TRY_COMPILE([
842 #include <stdio.h>
843 #include <sys/types.h>
844 #include <errno.h>
845 #ifdef WINNT
846 #include <stdlib.h>
847 #endif ],
848         [char *c = (char *) *sys_errlist],
849         [ol_cv_dcl_sys_errlist=yes
850         ol_cv_have_sys_errlist=yes],
851         [ol_cv_dcl_sys_errlist=no])])
852 #
853 # It's possible (for near-UNIX clones) that sys_errlist doesn't exist
854 if test $ol_cv_dcl_sys_errlist = no ; then
855         AC_DEFINE(DECL_SYS_ERRLIST,1,
856                 [define if sys_errlist is not declared in stdio.h or errno.h])
857
858         AC_CACHE_CHECK([existence of sys_errlist],ol_cv_have_sys_errlist,[
859                 AC_TRY_LINK([#include <errno.h>],
860                         [char *c = (char *) *sys_errlist],
861                         [ol_cv_have_sys_errlist=yes],
862                         [ol_cv_have_sys_errlist=no])])
863 fi
864 if test $ol_cv_have_sys_errlist = yes ; then
865         AC_DEFINE(HAVE_SYS_ERRLIST,1,
866                 [define if you actually have sys_errlist in your libs])
867 fi
868 ])dnl
869 dnl
870 dnl ====================================================================
871 dnl Early MIPS compilers (used in Ultrix 4.2) don't like
872 dnl "int x; int *volatile a = &x; *a = 0;"
873 dnl     -- borrowed from PDKSH
874 AC_DEFUN(OL_C_VOLATILE,
875  [AC_CACHE_CHECK(if compiler understands volatile, ol_cv_c_volatile,
876     [AC_TRY_COMPILE([int x, y, z;],
877       [volatile int a; int * volatile b = x ? &y : &z;
878       /* Older MIPS compilers (eg., in Ultrix 4.2) don't like *b = 0 */
879       *b = 0;], ol_cv_c_volatile=yes, ol_cv_c_volatile=no)])
880   if test $ol_cv_c_volatile = yes; then
881     : 
882   else
883     AC_DEFINE(volatile,,[define as empty if volatile is not supported])
884   fi
885  ])dnl
886 dnl
887 dnl ====================================================================
888 dnl Look for fetch(3)
889 AC_DEFUN([OL_LIB_FETCH],
890 [ol_LIBS=$LIBS
891 LIBS="-lfetch -lcom_err $LIBS"
892 AC_CACHE_CHECK([fetch(3) library],ol_cv_lib_fetch,[
893         AC_TRY_LINK([
894 #include <sys/param.h>
895 #include <stdio.h>
896 #include <fetch.h>],
897         [struct url *u = fetchParseURL("file:///"); ],
898         [ol_cv_lib_fetch=yes],
899         [ol_cv_lib_fetch=no])])
900 LIBS=$ol_LIBS
901 if test $ol_cv_lib_fetch != no ; then
902         ol_link_fetch="-lfetch -lcom_err"
903         AC_DEFINE(HAVE_FETCH,1,
904                 [define if you actually have FreeBSD fetch(3)])
905 fi
906 ])dnl
907 dnl
908 dnl ====================================================================
909 dnl Define sig_atomic_t if not defined in signal.h
910 AC_DEFUN(OL_TYPE_SIG_ATOMIC_T,
911  [AC_CACHE_CHECK(for sig_atomic_t, ol_cv_type_sig_atomic_t,
912     [AC_TRY_COMPILE([#include <signal.h>], [sig_atomic_t atomic;],
913                 ol_cv_type_sig_atomic_t=yes, ol_cv_type_sig_atomic_t=no)])
914   if test $ol_cv_type_sig_atomic_t = no; then
915     AC_DEFINE(sig_atomic_t,int,
916                 [define to atomic type if sig_atomic_t is not available])
917   fi
918  ])dnl
919 dnl
920 dnl ====================================================================
921 dnl Define socklen_t if not defined in sys/types.h or sys/socket.h
922 AC_DEFUN(OL_TYPE_SOCKLEN_T,
923  [AC_CACHE_CHECK(for socklen_t, ol_cv_type_socklen_t,
924     [AC_TRY_COMPILE([
925 #ifdef HAVE_SYS_TYPES_H
926 #include <sys/types.h>
927 #endif
928 #ifdef HAVE_SYS_SOCKET_H
929 #include <sys/socket.h>
930 #endif
931 ], [socklen_t len;],
932                 ol_cv_type_socklen_t=yes, ol_cv_type_socklen_t=no)])
933   if test $ol_cv_type_socklen_t = no; then
934     AC_DEFINE(socklen_t, int,
935                 [define to int if socklen_t is not available])
936   fi
937  ])dnl
938 dnl
939 dnl ====================================================================
940 dnl Define inet_aton is available
941 AC_DEFUN(OL_FUNC_INET_ATON,
942  [AC_CACHE_CHECK([for inet_aton()], ol_cv_func_inet_aton,
943     [AC_TRY_LINK([
944 #ifdef HAVE_SYS_TYPES_H
945 #       include <sys/types.h>
946 #endif
947 #ifdef HAVE_SYS_SOCKET_H
948 #       include <sys/socket.h>
949 #       ifdef HAVE_SYS_SELECT_H
950 #               include <sys/select.h>
951 #       endif
952 #       include <netinet/in.h>
953 #       ifdef HAVE_ARPA_INET_H
954 #               include <arpa/inet.h>
955 #       endif
956 #endif
957 ], [struct in_addr in;
958 int rc = inet_aton( "255.255.255.255", &in );],
959                 ol_cv_func_inet_aton=yes, ol_cv_func_inet_aton=no)])
960   if test $ol_cv_func_inet_aton != no; then
961     AC_DEFINE(HAVE_INET_ATON, 1,
962                 [define to you inet_aton(3) is available])
963   fi
964  ])dnl
965 dnl
966 dnl ====================================================================
967 dnl check no of arguments for ctime_r
968 AC_DEFUN(OL_FUNC_CTIME_R_NARGS,
969  [AC_CACHE_CHECK(number of arguments of ctime_r, ol_cv_func_ctime_r_nargs,
970    [AC_TRY_COMPILE([#include <time.h>],
971                 [time_t ti; char *buffer; ctime_r(&ti,buffer,32);],
972                         ol_cv_func_ctime_r_nargs3=yes,
973                         ol_cv_func_ctime_r_nargs3=no)
974
975         AC_TRY_COMPILE([#include <time.h>],
976                 [time_t ti; char *buffer; ctime_r(&ti,buffer);],
977                         ol_cv_func_ctime_r_nargs2=yes,
978                         ol_cv_func_ctime_r_nargs2=no)
979
980         if test $ol_cv_func_ctime_r_nargs3 = yes -a \
981                 $ol_cv_func_ctime_r_nargs2 = no ; then
982
983                 ol_cv_func_ctime_r_nargs=3
984
985         elif test $ol_cv_func_ctime_r_nargs3 = no -a \
986                 $ol_cv_func_ctime_r_nargs2 = yes ; then
987
988                 ol_cv_func_ctime_r_nargs=2
989
990         else
991                 ol_cv_func_ctime_r_nargs=0
992         fi
993   ])
994
995   if test $ol_cv_func_ctime_r_nargs -gt 1 ; then
996         AC_DEFINE_UNQUOTED(CTIME_R_NARGS, $ol_cv_func_ctime_r_nargs,
997                 [set to the number of arguments ctime_r() expects])
998   fi
999 ])dnl
1000 dnl
1001 dnl --------------------------------------------------------------------
1002 dnl check return type of ctime_r()
1003 AC_DEFUN(OL_FUNC_CTIME_R_TYPE,
1004  [AC_CACHE_CHECK(return type of ctime_r, ol_cv_func_ctime_r_type,
1005    [AC_TRY_COMPILE([#include <time.h>],
1006                 [extern int (ctime_r)();],
1007                         ol_cv_func_ctime_r_type="int", ol_cv_func_ctime_r_type="charp")
1008         ])
1009   if test $ol_cv_func_ctime_r_type = "int" ; then
1010         AC_DEFINE(CTIME_R_RETURNS_INT,1, [define if ctime_r() returns int])
1011   fi
1012 ])dnl
1013 dnl ====================================================================
1014 dnl check no of arguments for gethostbyname_r
1015 AC_DEFUN(OL_FUNC_GETHOSTBYNAME_R_NARGS,
1016  [AC_CACHE_CHECK(number of arguments of gethostbyname_r,
1017         ol_cv_func_gethostbyname_r_nargs,
1018         [AC_TRY_COMPILE([#include <sys/types.h>
1019 #include <sys/socket.h>
1020 #include <netinet/in.h>
1021 #include <netdb.h>
1022 #define BUFSIZE (sizeof(struct hostent)+10)],
1023                 [struct hostent hent; char buffer[BUFSIZE];
1024                 int bufsize=BUFSIZE;int h_errno;
1025                 (void)gethostbyname_r("segovia.cs.purdue.edu", &hent,
1026                         buffer, bufsize, &h_errno);],
1027                 ol_cv_func_gethostbyname_r_nargs5=yes, 
1028                 ol_cv_func_gethostbyname_r_nargs5=no)
1029
1030         AC_TRY_COMPILE([#include <sys/types.h>
1031 #include <sys/socket.h>
1032 #include <netinet/in.h>
1033 #include <netdb.h>
1034 #define BUFSIZE (sizeof(struct hostent)+10)],
1035                 [struct hostent hent;struct hostent *rhent;
1036                 char buffer[BUFSIZE];
1037                 int bufsize=BUFSIZE;int h_errno;
1038                 (void)gethostbyname_r("localhost", &hent, buffer, bufsize,
1039                         &rhent, &h_errno);],
1040                 ol_cv_func_gethostbyname_r_nargs6=yes,
1041                 ol_cv_func_gethostbyname_r_nargs6=no)
1042
1043         if test $ol_cv_func_gethostbyname_r_nargs5 = yes -a \
1044                 $ol_cv_func_gethostbyname_r_nargs6 = no ; then
1045
1046                 ol_cv_func_gethostbyname_r_nargs=5
1047
1048         elif test $ol_cv_func_gethostbyname_r_nargs5 = no -a \
1049                 $ol_cv_func_gethostbyname_r_nargs6 = yes ; then
1050
1051                 ol_cv_func_gethostbyname_r_nargs=6
1052
1053         else
1054                 ol_cv_func_gethostbyname_r_nargs=0
1055         fi
1056   ])
1057   if test $ol_cv_func_gethostbyname_r_nargs -gt 1 ; then
1058         AC_DEFINE_UNQUOTED(GETHOSTBYNAME_R_NARGS,
1059                 $ol_cv_func_gethostbyname_r_nargs,
1060                 [set to the number of arguments gethostbyname_r() expects])
1061   fi
1062 ])dnl
1063 dnl
1064 dnl check no of arguments for gethostbyaddr_r
1065 AC_DEFUN(OL_FUNC_GETHOSTBYADDR_R_NARGS,
1066  [AC_CACHE_CHECK(number of arguments of gethostbyaddr_r,
1067         [ol_cv_func_gethostbyaddr_r_nargs],
1068         [AC_TRY_COMPILE([#include <sys/types.h>
1069 #include <sys/socket.h>
1070 #include <netinet/in.h>
1071 #include <netdb.h>
1072 #define BUFSIZE (sizeof(struct hostent)+10)],
1073            [struct hostent hent; char buffer[BUFSIZE]; 
1074             struct in_addr add;
1075             size_t alen=sizeof(struct in_addr);
1076             int bufsize=BUFSIZE;int h_errno;
1077                 (void)gethostbyaddr_r( (void *)&(add.s_addr),
1078                         alen, AF_INET, &hent, buffer, bufsize, &h_errno);],
1079                 ol_cv_func_gethostbyaddr_r_nargs7=yes,
1080                 ol_cv_func_gethostbyaddr_r_nargs7=no)
1081
1082         AC_TRY_COMPILE([#include <sys/types.h>
1083 #include <sys/socket.h>
1084 #include <netinet/in.h>
1085 #include <netdb.h>
1086 #define BUFSIZE (sizeof(struct hostent)+10)],
1087                 [struct hostent hent;
1088                 struct hostent *rhent; char buffer[BUFSIZE]; 
1089                 struct in_addr add;
1090                 size_t alen=sizeof(struct in_addr);
1091                 int bufsize=BUFSIZE;int h_errno;
1092                 (void)gethostbyaddr_r( (void *)&(add.s_addr),
1093                         alen, AF_INET, &hent, buffer, bufsize, 
1094                         &rhent, &h_errno);],
1095                 ol_cv_func_gethostbyaddr_r_nargs8=yes,
1096                 ol_cv_func_gethostbyaddr_r_nargs8=no)
1097
1098         if test $ol_cv_func_gethostbyaddr_r_nargs7 = yes -a \
1099                 $ol_cv_func_gethostbyaddr_r_nargs8 = no ; then
1100
1101                 ol_cv_func_gethostbyaddr_r_nargs=7
1102
1103         elif test $ol_cv_func_gethostbyaddr_r_nargs7 = no -a \
1104                 $ol_cv_func_gethostbyaddr_r_nargs8 = yes ; then
1105
1106                 ol_cv_func_gethostbyaddr_r_nargs=8
1107
1108         else
1109                 ol_cv_func_gethostbyaddr_r_nargs=0
1110         fi
1111   ])
1112   if test $ol_cv_func_gethostbyaddr_r_nargs -gt 1 ; then
1113     AC_DEFINE_UNQUOTED(GETHOSTBYADDR_R_NARGS,
1114                 $ol_cv_func_gethostbyaddr_r_nargs,
1115                 [set to the number of arguments gethostbyaddr_r() expects])
1116   fi
1117 ])dnl
1118 dnl