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