]> git.sur5r.net Git - openldap/blob - build/openldap.m4
92cdde3dcd20ca92130ebb748a4191c4aecc5e8c
[openldap] / build / openldap.m4
1 dnl Copyright 1998-1999 The OpenLDAP Foundation,  All Rights Reserved.
2 dnl COPYING RESTRICTIONS APPLY, See COPYRIGHT file
3 dnl
4 dnl OpenLDAP Autoconf Macros
5 dnl
6 dnl --------------------------------------------------------------------
7 dnl Restricted form of AC_ARG_ENABLE that limits user options
8 dnl
9 dnl $1 = option name
10 dnl $2 = help-string
11 dnl $3 = default value  (auto)
12 dnl $4 = allowed values (auto yes no)
13 AC_DEFUN([OL_ARG_ENABLE], [# OpenLDAP --enable-$1
14         AC_ARG_ENABLE($1,[$2 (]ifelse($3,,auto,$3)[)],[
15         ol_arg=invalid
16         for ol_val in ifelse($4,,[auto yes no],[$4]) ; do
17                 if test "$enableval" = "$ol_val" ; then
18                         ol_arg="$ol_val"
19                 fi
20         done
21         if test "$ol_arg" = "invalid" ; then
22                 AC_MSG_ERROR(bad value $enableval for --enable-$1)
23         fi
24         ol_enable_$1="$ol_arg"
25 ],
26 [       ol_enable_$1=ifelse($3,,"auto","$3")])dnl
27 dnl AC_VERBOSE(OpenLDAP -enable-$1 $ol_enable_$1)
28 # end --enable-$1
29 ])dnl
30 dnl
31 dnl --------------------------------------------------------------------
32 dnl Restricted form of AC_ARG_WITH that limits user options
33 dnl
34 dnl $1 = option name
35 dnl $2 = help-string
36 dnl $3 = default value (no)
37 dnl $4 = allowed values (yes or no)
38 AC_DEFUN([OL_ARG_WITH], [# OpenLDAP --with-$1
39         AC_ARG_WITH($1,[$2 (]ifelse($3,,yes,$3)[)],[
40         ol_arg=invalid
41         for ol_val in ifelse($4,,[yes no],[$4]) ; do
42                 if test "$withval" = "$ol_val" ; then
43                         ol_arg="$ol_val"
44                 fi
45         done
46         if test "$ol_arg" = "invalid" ; then
47                 AC_MSG_ERROR(bad value $withval for --with-$1)
48         fi
49         ol_with_$1="$ol_arg"
50 ],
51 [       ol_with_$1=ifelse($3,,"no","$3")])dnl
52 dnl AC_VERBOSE(OpenLDAP --with-$1 $ol_with_$1)
53 # end --with-$1
54 ])dnl
55 dnl
56 dnl ====================================================================
57 dnl check if hard links are supported.
58 dnl
59 AC_DEFUN([OL_PROG_LN_H], [# test for ln hardlink support
60 AC_MSG_CHECKING(whether ln works)
61 AC_CACHE_VAL(ol_cv_prog_LN_H,
62 [rm -f conftest.src conftest.dst
63 echo "conftest" > conftest.src
64 if ln conftest.src conftest.dst 2>/dev/null
65 then
66   ol_cv_prog_LN_H="ln"
67 else
68   ol_cv_prog_LN_H="cp"
69 fi
70 rm -f conftest.src conftest.dst
71 ])dnl
72 LN_H="$ol_cv_prog_LN_H"
73 if test "$ol_cv_prog_LN_H" = "ln"; then
74         AC_MSG_RESULT(yes)
75 else
76         AC_MSG_RESULT(no)
77 fi
78 AC_SUBST(LN_H)dnl
79 ])dnl
80 dnl
81 dnl ====================================================================
82 dnl Check for dependency generation flag
83 AC_DEFUN([OL_MKDEPEND], [# test for make depend flag
84 OL_MKDEP=
85 OL_MKDEP_FLAGS=
86 if test -z "${MKDEP}"; then
87         OL_MKDEP="${CC-cc}"
88         if test -z "${MKDEP_FLAGS}"; then
89                 AC_CACHE_CHECK([for ${OL_MKDEP} depend flag], ol_cv_mkdep, [
90                         ol_cv_mkdep=no
91                         for flag in "-M" "-xM"; do
92                                 cat > conftest.c <<EOF
93  noCode;
94 EOF
95                                 if AC_TRY_COMMAND($OL_MKDEP $flag conftest.c) \
96                                         | egrep '^conftest\.'"${ac_objext}" >/dev/null 2>&1
97                                 then
98                                         if test ! -f conftest."${ac_object}" ; then
99                                                 ol_cv_mkdep=$flag
100                                                 OL_MKDEP_FLAGS="$flag"
101                                                 break
102                                         fi
103                                 fi
104                         done
105                         rm -f conftest*
106                 ])
107         else
108                 cc_cv_mkdep=yes
109                 OL_MKDEP_FLAGS="${MKDEP_FLAGS}"
110         fi
111 else
112         cc_cv_mkdep=yes
113         OL_MKDEP="${MKDEP}"
114         OL_MKDEP_FLAGS="${MKDEP_FLAGS}"
115 fi
116 AC_SUBST(OL_MKDEP)
117 AC_SUBST(OL_MKDEP_FLAGS)
118 ])
119 dnl
120 dnl ====================================================================
121 dnl Check if system uses EBCDIC instead of ASCII
122 AC_DEFUN([OL_CPP_EBCDIC], [# test for EBCDIC
123 AC_MSG_CHECKING([for EBCDIC])
124 AC_CACHE_VAL(ol_cv_cpp_ebcdic,[
125         AC_TRY_CPP([
126 #if !('M' == 0xd4)
127 #include <__ASCII__/generate_error.h>
128 #endif
129 ],
130         [ol_cv_cpp_ebcdic=yes],
131         [ol_cv_cpp_ebcdic=no])])
132 AC_MSG_RESULT($ol_cv_cpp_ebcdic)
133 if test $ol_cv_cpp_ebcdic = yes ; then
134         AC_DEFINE(HAVE_EBCDIC,1, [define if system uses EBCDIC instead of ASCII])
135 fi
136 ])
137 dnl
138 dnl --------------------------------------------------------------------
139 dnl OpenLDAP version of STDC header check w/ EBCDIC support
140 AC_DEFUN(OL_HEADER_STDC,
141 [AC_REQUIRE_CPP()dnl
142 AC_REQUIRE([OL_CPP_EBCDIC])dnl
143 AC_CACHE_CHECK([for ANSI C header files], ol_cv_header_stdc,
144 [AC_TRY_CPP([#include <stdlib.h>
145 #include <stdarg.h>
146 #include <string.h>
147 #include <float.h>], ol_cv_header_stdc=yes, ol_cv_header_stdc=no)
148
149 if test $ol_cv_header_stdc = yes; then
150   # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
151 AC_EGREP_HEADER(memchr, string.h, , ol_cv_header_stdc=no)
152 fi
153
154 if test $ol_cv_header_stdc = yes; then
155   # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
156 AC_EGREP_HEADER(free, stdlib.h, , ol_cv_header_stdc=no)
157 fi
158
159 if test $ol_cv_header_stdc = yes; then
160   # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
161 AC_TRY_RUN([#include <ctype.h>
162 #ifndef HAVE_EBCDIC
163 #       define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
164 #       define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
165 #else
166 #       define ISLOWER(c) (('a' <= (c) && (c) <= 'i') \
167                 || ('j' <= (c) && (c) <= 'r') \
168                 || ('s' <= (c) && (c) <= 'z'))
169 #       define TOUPPER(c)       (ISLOWER(c) ? ((c) | 0x40) : (c))
170 #endif
171 #define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
172 int main () { int i; for (i = 0; i < 256; i++)
173 if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2);
174 exit (0); }
175 ], , ol_cv_header_stdc=no, :)
176 fi])
177 if test $ol_cv_header_stdc = yes; then
178   AC_DEFINE(STDC_HEADERS)
179 fi
180 ac_cv_header_stdc=disable
181 ])
182 dnl
183 dnl ====================================================================
184 dnl Check if struct passwd has pw_gecos
185 AC_DEFUN([OL_STRUCT_PASSWD_PW_GECOS], [# test for pw_gecos in struct passwd
186 AC_MSG_CHECKING([struct passwd for pw_gecos])
187 AC_CACHE_VAL(ol_cv_struct_passwd_pw_gecos,[
188         AC_TRY_COMPILE([#include <pwd.h>],[
189         struct passwd pwd;
190         pwd.pw_gecos = pwd.pw_name;
191 ],
192         [ol_cv_struct_passwd_pw_gecos=yes],
193         [ol_cv_struct_passwd_pw_gecos=no])])
194 AC_MSG_RESULT($ol_cv_struct_passwd_pw_gecos)
195 if test $ol_cv_struct_passwd_pw_gecos = yes ; then
196         AC_DEFINE(HAVE_PW_GECOS,1, [define if struct passwd has pw_gecos])
197 fi
198 ])
199 dnl
200 dnl --------------------------------------------------------------------
201 dnl Check if struct passwd has pw_gecos
202 AC_DEFUN([OL_STRUCT_PASSWD_PW_PASSWD], [# test for pw_passwd in struct passwd
203 AC_MSG_CHECKING([struct passwd for pw_passwd])
204 AC_CACHE_VAL(ol_cv_struct_passwd_pw_passwd,[
205         AC_TRY_COMPILE([#include <pwd.h>],[
206         struct passwd pwd;
207         pwd.pw_passwd = pwd.pw_name;
208 ],
209         [ol_cv_struct_passwd_pw_passwd=yes],
210         [ol_cv_struct_passwd_pw_passwd=no])])
211 AC_MSG_RESULT($ol_cv_struct_passwd_pw_passwd)
212 if test $ol_cv_struct_passwd_pw_passwd = yes ; then
213         AC_DEFINE(HAVE_PW_PASSWD,1, [define if struct passwd has pw_passwd])
214 fi
215 ])
216 dnl
217 dnl ====================================================================
218 dnl Check if db.h is Berkeley DB2
219 dnl
220 dnl defines ol_cv_header_db2 to 'yes' or 'no'
221 dnl
222 dnl uses:
223 dnl             AC_CHECK_HEADERS(db.h)
224 dnl
225 AC_DEFUN([OL_HEADER_BERKELEY_DB2],
226 [AC_CHECK_HEADERS(db.h)
227 if test $ac_cv_header_db_h = yes ; then
228         AC_CACHE_CHECK([if db.h is DB2], [ol_cv_header_db2],[
229                 AC_EGREP_CPP(__db_version_2,[
230 #                       include <db.h>
231                         /* this check could be improved */
232 #                       ifdef DB_VERSION_MAJOR
233 #                               if DB_VERSION_MAJOR == 2
234                                         __db_version_2
235 #                               endif
236 #                       endif
237                 ], ol_cv_header_db2=yes, ol_cv_header_db2=no)])
238 else
239         ol_cv_header_db2=no
240 fi
241 ])dnl
242 dnl --------------------------------------------------------------------
243 dnl Check if Berkeley DB2 library exists
244 dnl Check for dbopen in standard libraries or -ldb
245 dnl
246 dnl defines ol_cv_lib_db2 to '-ldb' or 'no'
247 dnl
248 dnl uses:
249 dnl             AC_CHECK_LIB(db,db_open)
250 dnl
251 AC_DEFUN([OL_LIB_BERKELEY_DB2],
252 [AC_CACHE_CHECK([for DB2 library], [ol_cv_lib_db2],
253 [       ol_LIBS="$LIBS"
254         AC_CHECK_LIB(db,db_open,[ol_cv_lib_db2=-ldb],[ol_cv_lib_db2=no])
255         LIBS="$ol_LIBS"
256 ])
257 ])dnl
258 dnl
259 dnl --------------------------------------------------------------------
260 dnl Check if Berkeley db2 exists
261 dnl
262 dnl defines ol_cv_berkeley_db2 to 'yes' or 'no'
263 dnl 
264 dnl uses:
265 dnl             OL_LIB_BERKELEY_DB2
266 dnl             OL_HEADER_BERKELEY_DB2
267 dnl
268 AC_DEFUN([OL_BERKELEY_DB2],
269 [AC_REQUIRE([OL_LIB_BERKELEY_DB2])
270  AC_REQUIRE([OL_HEADER_BERKELEY_DB2])
271  AC_CACHE_CHECK([for Berkeley DB2], [ol_cv_berkeley_db2], [
272         if test "$ol_cv_lib_db2" = no -o "$ol_cv_header_db2" = no ; then
273                 ol_cv_berkeley_db2=no
274         else
275                 ol_cv_berkeley_db2=yes
276         fi
277 ])
278  if test $ol_cv_berkeley_db2 = yes ; then
279         AC_DEFINE(HAVE_BERKELEY_DB2,1, [define if Berkeley DBv2 is available])
280  fi
281 ])dnl
282 dnl
283 dnl ====================================================================
284 dnl Check for db.h/db_185.h is Berkeley DB
285 dnl
286 dnl defines ol_cv_header_db to 'yes' or 'no'
287 dnl
288 dnl uses:
289 dnl             OL_HEADER_BERKELEY_DB2
290 dnl             AC_CHECK_HEADERS(db_185.h)
291 dnl
292 AC_DEFUN([OL_HEADER_BERKELEY_DB],
293 [AC_REQUIRE([OL_HEADER_BERKELEY_DB2])
294 AC_CHECK_HEADERS(db_185.h)
295 if test "$ol_cv_header_db2" = yes ; then
296         dnl db.h is db2! 
297
298         ol_cv_header_db=$ac_cv_header_db_185_h
299 else
300         ol_cv_header_db=$ac_cv_header_db_h
301 fi
302 ])dnl
303 dnl
304 dnl --------------------------------------------------------------------
305 dnl Check if Berkeley DB library exists
306 dnl Check for dbopen in standard libraries or -ldb
307 dnl
308 dnl defines ol_cv_lib_db to 'yes' or '-ldb' or 'no'
309 dnl             'yes' implies dbopen is in $LIBS
310 dnl
311 dnl uses:
312 dnl             AC_CHECK_FUNC(dbopen)
313 dnl             AC_CHECK_LIB(db,dbopen)
314 dnl
315 AC_DEFUN([OL_LIB_BERKELEY_DB],
316 [AC_CACHE_CHECK([for Berkeley DB library], [ol_cv_lib_db],
317 [
318         AC_CHECK_HEADERS(db1/db.h)
319         ol_LIBS="$LIBS"
320         AC_CHECK_FUNC(dbopen,[ol_cv_lib_db=yes], [
321                 AC_CHECK_LIB(db1,dbopen,[ol_cv_lib_db=-ldb1],[
322                         AC_CHECK_LIB(db,dbopen,[ol_cv_lib_db=-ldb],
323                         [ol_cv_lib_db=no])
324                 ])
325         ])
326         LIBS="$ol_LIBS"
327 ])
328 ])dnl
329 dnl
330 dnl --------------------------------------------------------------------
331 dnl Check if Berkeley DB exists
332 dnl
333 dnl defines ol_cv_berkeley_db to 'yes' or 'no'
334 dnl 
335 dnl uses:
336 dnl             OL_LIB_BERKELEY_DB
337 dnl             OL_HEADER_BERKELEY_DB
338 dnl
339 AC_DEFUN([OL_BERKELEY_DB],
340 [AC_REQUIRE([OL_LIB_BERKELEY_DB])
341  AC_REQUIRE([OL_HEADER_BERKELEY_DB])
342  AC_CACHE_CHECK([for Berkeley DB], [ol_cv_berkeley_db], [
343         if test "$ol_cv_lib_db" = no -o "$ol_cv_header_db" = no ; then
344                 ol_cv_berkeley_db=no
345         else
346                 ol_cv_berkeley_db=yes
347         fi
348 ])
349  if test $ol_cv_berkeley_db = yes ; then
350         AC_DEFINE(HAVE_BERKELEY_DB,1, [define if Berkeley DB is available])
351  fi
352 ])dnl
353 dnl
354 dnl ====================================================================
355 dnl Check if GDBM library exists
356 dnl Check for gdbm_open in standard libraries or -lgdbm
357 dnl
358 dnl defines ol_cv_lib_gdbm to 'yes' or '-lgdbm' or 'no'
359 dnl             'yes' implies gdbm_open is in $LIBS
360 dnl
361 dnl uses:
362 dnl             AC_CHECK_FUNC(gdbm_open)
363 dnl             AC_CHECK_LIB(gdbm,gdbm_open)
364 dnl
365 AC_DEFUN([OL_LIB_GDBM],
366 [AC_CACHE_CHECK(for GDBM library, [ol_cv_lib_gdbm],
367 [       ol_LIBS="$LIBS"
368         AC_CHECK_FUNC(gdbm_open,[ol_cv_lib_gdbm=yes], [
369                 AC_CHECK_LIB(gdbm,gdbm_open,[ol_cv_lib_gdbm=-lgdbm],[ol_cv_lib_gdbm=no])
370         ])
371         LIBS="$ol_LIBS"
372 ])
373 ])dnl
374 dnl
375 dnl --------------------------------------------------------------------
376 dnl Check if GDBM exists
377 dnl
378 dnl defines ol_cv_gdbm to 'yes' or 'no'
379 dnl 
380 dnl uses:
381 dnl             OL_LIB_GDBM
382 dnl             AC_CHECK_HEADERS(gdbm.h)
383 dnl
384 AC_DEFUN([OL_GDBM],
385 [AC_REQUIRE([OL_LIB_GDBM])
386  AC_CHECK_HEADERS(gdbm.h)
387  AC_CACHE_CHECK(for db, [ol_cv_gdbm], [
388         if test $ol_cv_lib_gdbm = no -o $ac_cv_header_gdbm_h = no ; then
389                 ol_cv_gdbm=no
390         else
391                 ol_cv_gdbm=yes
392         fi
393 ])
394  if test $ol_cv_gdbm = yes ; then
395         AC_DEFINE(HAVE_GDBM,1, [define if GNU DBM is available])
396  fi
397 ])dnl
398 dnl
399 dnl ====================================================================
400 dnl Check if MDBM library exists
401 dnl Check for mdbm_open in standard libraries or -lmdbm
402 dnl
403 dnl defines ol_cv_lib_mdbm to 'yes' or '-lmdbm' or 'no'
404 dnl             'yes' implies mdbm_open is in $LIBS
405 dnl
406 dnl uses:
407 dnl             AC_CHECK_FUNC(mdbm_set_chain)
408 dnl             AC_CHECK_LIB(mdbm,mdbm_set_chain)
409 dnl
410 AC_DEFUN([OL_LIB_MDBM],
411 [AC_CACHE_CHECK(for MDBM library, [ol_cv_lib_mdbm],
412 [       ol_LIBS="$LIBS"
413         AC_CHECK_FUNC(mdbm_set_chain,[ol_cv_lib_mdbm=yes], [
414                 AC_CHECK_LIB(mdbm,mdbm_set_chain,[ol_cv_lib_mdbm=-lmdbm],[ol_cv_lib_mdbm=no])
415         ])
416         LIBS="$ol_LIBS"
417 ])
418 ])dnl
419 dnl
420 dnl --------------------------------------------------------------------
421 dnl Check if MDBM exists
422 dnl
423 dnl defines ol_cv_mdbm to 'yes' or 'no'
424 dnl 
425 dnl uses:
426 dnl             OL_LIB_MDBM
427 dnl             AC_CHECK_HEADERS(mdbm.h)
428 dnl
429 AC_DEFUN([OL_MDBM],
430 [AC_REQUIRE([OL_LIB_MDBM])
431  AC_CHECK_HEADERS(mdbm.h)
432  AC_CACHE_CHECK(for db, [ol_cv_mdbm], [
433         if test $ol_cv_lib_mdbm = no -o $ac_cv_header_mdbm_h = no ; then
434                 ol_cv_mdbm=no
435         else
436                 ol_cv_mdbm=yes
437         fi
438 ])
439  if test $ol_cv_mdbm = yes ; then
440         AC_DEFINE(HAVE_MDBM,1, [define if MDBM is available])
441  fi
442 ])dnl
443 dnl
444 dnl ====================================================================
445 dnl Check if NDBM library exists
446 dnl Check for dbm_open in standard libraries or -lndbm or -ldbm
447 dnl
448 dnl defines ol_cv_lib_ndbm to 'yes' or '-lndbm' or -ldbm or 'no'
449 dnl             'yes' implies ndbm_open is in $LIBS
450 dnl
451 dnl uses:
452 dnl             AC_CHECK_FUNC(dbm_open)
453 dnl             AC_CHECK_LIB(ndbm,dbm_open)
454 dnl             AC_CHECK_LIB(dbm,dbm_open)
455 dnl
456 dnl restrictions:
457 dnl             should also check SVR4 case: dbm_open() in -lucb but that
458 dnl             would requiring dealing with -L/usr/ucblib
459 dnl
460 AC_DEFUN([OL_LIB_NDBM],
461 [AC_CACHE_CHECK(for NDBM library, [ol_cv_lib_ndbm],
462 [       ol_LIBS="$LIBS"
463         AC_CHECK_FUNC(dbm_open,[ol_cv_lib_ndbm=yes], [
464                 AC_CHECK_LIB(ndbm,dbm_open,[ol_cv_lib_ndbm=-lndbm], [
465                         AC_CHECK_LIB(dbm,dbm_open,[ol_cv_lib_ndbm=-ldbm],
466                                 [ol_cv_lib_ndbm=no])dnl
467                 ])
468         ])
469         LIBS="$ol_LIBS"
470 ])
471 ])dnl
472 dnl
473 dnl --------------------------------------------------------------------
474 dnl Check if NDBM exists
475 dnl
476 dnl defines ol_cv_ndbm to 'yes' or 'no'
477 dnl 
478 dnl uses:
479 dnl             OL_LIB_NDBM
480 dnl             AC_CHECK_HEADERS(ndbm.h)
481 dnl
482 dnl restrictions:
483 dnl             Doesn't handle SVR4 case (see above)
484 dnl
485 AC_DEFUN([OL_NDBM],
486 [AC_REQUIRE([OL_LIB_NDBM])
487  AC_CHECK_HEADERS(ndbm.h)
488  AC_CACHE_CHECK(for db, [ol_cv_ndbm], [
489         if test $ol_cv_lib_ndbm = no -o $ac_cv_header_ndbm_h = no ; then
490                 ol_cv_ndbm=no
491         else
492                 ol_cv_ndbm=yes
493         fi
494 ])
495  if test $ol_cv_ndbm = yes ; then
496         AC_DEFINE(HAVE_NDBM,1, [define if NDBM is available])
497  fi
498 ])dnl
499 dnl
500 dnl ====================================================================
501 dnl Check POSIX Thread version 
502 dnl
503 dnl defines ol_cv_posix_version to 'final' or 'draft' or 'unknown'
504 dnl     'unknown' implies that the version could not be detected
505 dnl             or that pthreads.h does exist.  Existance of pthreads.h
506 dnl             should be tested separately.
507 dnl
508 AC_DEFUN([OL_POSIX_THREAD_VERSION],
509 [AC_CACHE_CHECK([POSIX thread version],[ol_cv_pthread_version],[
510         AC_EGREP_CPP(pthread_version_final,[
511 #               include <pthread.h>
512                 /* this check could be improved */
513 #               ifdef PTHREAD_ONCE_INIT
514                         pthread_version_final
515 #               endif
516         ], ol_pthread_final=yes, ol_pthread_final=no)
517
518         AC_EGREP_CPP(pthread_version_draft4,[
519 #               include <pthread.h>
520                 /* this check could be improved */
521 #               ifdef pthread_once_init
522                         pthread_version_draft4
523 #               endif
524         ], ol_pthread_draft4=yes, ol_pthread_draft4=no)
525
526         if test $ol_pthread_final = yes -a $ol_pthread_draft4 = no; then
527                 ol_cv_pthread_version=final
528         elif test $ol_pthread_final = no -a $ol_pthread_draft4 = yes; then
529                 ol_cv_pthread_version=draft4
530         else
531                 ol_cv_pthread_version=unknown
532         fi
533 ])
534 ])dnl
535 dnl
536 dnl --------------------------------------------------------------------
537 AC_DEFUN([OL_PTHREAD_TRY_LINK], [# Pthread try link: $1 ($2)
538         if test "$ol_link_threads" = no ; then
539                 # try $1
540                 AC_CACHE_CHECK([for pthread link with $1], [$2], [
541                         # save the flags
542                         ol_LIBS="$LIBS"
543                         LIBS="$1 $LIBS"
544
545                         AC_TRY_LINK([
546 #include <pthread.h>
547 #ifndef NULL
548 #define NULL (void*)0
549 #endif
550 ],[
551         pthread_t t;
552
553 #if HAVE_PTHREADS_D4
554         pthread_create(&t, pthread_attr_default, NULL, NULL);
555         pthread_detach( &t );
556 #else
557         pthread_create(&t, NULL, NULL, NULL);
558         pthread_detach( t );
559 #endif
560 #ifdef HAVE_LINUX_THREADS
561         pthread_kill_other_threads_np();
562 #endif
563 ], [$2=yes], [$2=no])
564
565                 # restore the LIBS
566                 LIBS="$ol_LIBS"
567                 ])
568
569                 if test $$2 = yes ; then
570                         ol_link_pthreads="$1"
571                         ol_link_threads=posix
572                 fi
573         fi
574 ])
575 dnl
576 dnl ====================================================================
577 dnl Check LinuxThreads Header
578 dnl
579 dnl defines ol_cv_header linux_threads to 'yes' or 'no'
580 dnl             'no' implies pthreads.h is not LinuxThreads or pthreads.h
581 dnl             doesn't exists.  Existance of pthread.h should separately
582 dnl             checked.
583 dnl 
584 AC_DEFUN([OL_HEADER_LINUX_THREADS], [
585         AC_CACHE_CHECK([for LinuxThreads pthread.h],
586                 [ol_cv_header_linux_threads],
587                 [AC_EGREP_CPP(pthread_kill_other_threads_np,
588                         [#include <pthread.h>],
589                         [ol_cv_header_linux_threads=yes],
590                         [ol_cv_header_linux_threads=no])
591                 ])
592         if test $ol_cv_header_linux_threads = yes; then
593                 AC_DEFINE(HAVE_LINUX_THREADS,1,[if you have LinuxThreads])
594         fi
595 ])dnl
596 dnl --------------------------------------------------------------------
597 dnl     Check LinuxThreads Implementation
598 dnl
599 dnl     defines ol_cv_sys_linux_threads to 'yes' or 'no'
600 dnl     'no' implies pthreads implementation is not LinuxThreads.
601 dnl 
602 AC_DEFUN([OL_SYS_LINUX_THREADS], [
603         AC_CHECK_FUNC(pthread_kill_other_threads_np)
604         AC_CACHE_CHECK([for LinuxThreads implementation],
605                 [ol_cv_sys_linux_threads],
606                 [ol_cv_sys_linux_threads=$ac_cv_func_pthread_kill_other_threads_np])
607 ])dnl
608 dnl
609 dnl --------------------------------------------------------------------
610 dnl Check LinuxThreads consistency
611 AC_DEFUN([OL_LINUX_THREADS], [
612         AC_REQUIRE([OL_HEADER_LINUX_THREADS])
613         AC_REQUIRE([OL_SYS_LINUX_THREADS])
614         AC_CACHE_CHECK([for LinuxThreads consistency], [ol_cv_linux_threads], [
615                 if test $ol_cv_header_linux_threads = yes -a \
616                         $ol_cv_sys_linux_threads = yes; then
617                         ol_cv_linux_threads=yes
618                 elif test $ol_cv_header_linux_threads = no -a \
619                         $ol_cv_sys_linux_threads = no; then
620                         ol_cv_linux_threads=no
621                 else
622                         ol_cv_linux_threads=error
623                 fi
624         ])
625 ])dnl
626 dnl
627 dnl ====================================================================
628 dnl Check for POSIX Regex
629 AC_DEFUN([OL_POSIX_REGEX], [
630 AC_MSG_CHECKING([for compatible POSIX regex])
631 AC_CACHE_VAL(ol_cv_c_posix_regex,[
632         AC_TRY_RUN([
633 #include <sys/types.h>
634 #include <regex.h>
635 static char *pattern, *string;
636 main()
637 {
638         int rc;
639         regex_t re;
640
641         pattern = "^A";
642
643         if(regcomp(&re, pattern, 0)) {
644                 return -1;
645         }
646         
647         string = "ALL MATCH";
648         
649         rc = regexec(&re, string, 0, (void*)0, 0);
650
651         regfree(&re);
652
653         return rc;
654 }],
655         [ol_cv_c_posix_regex=yes],
656         [ol_cv_c_posix_regex=no],
657         [ol_cv_c_posix_regex=cross])])
658 AC_MSG_RESULT($ol_cv_c_posix_regex)
659 ])
660 dnl
661 dnl ====================================================================
662 dnl Check if toupper() requires islower() to be called first
663 AC_DEFUN([OL_C_UPPER_LOWER],
664 [
665 AC_MSG_CHECKING([if toupper() requires islower()])
666 AC_CACHE_VAL(ol_cv_c_upper_lower,[
667         AC_TRY_RUN([
668 #include <ctype.h>
669 main()
670 {
671         if ('C' == toupper('C'))
672                 exit(0);
673         else
674                 exit(1);
675 }],
676         [ol_cv_c_upper_lower=no],
677         [ol_cv_c_upper_lower=yes],
678         [ol_cv_c_upper_lower=safe])])
679 AC_MSG_RESULT($ol_cv_c_upper_lower)
680 if test $ol_cv_c_upper_lower != no ; then
681         AC_DEFINE(C_UPPER_LOWER,1, [define if toupper() requires islower()])
682 fi
683 ])
684 dnl
685 dnl ====================================================================
686 dnl Check for declaration of sys_errlist in one of stdio.h and errno.h.
687 dnl Declaration of sys_errlist on BSD4.4 interferes with our declaration.
688 dnl Reported by Keith Bostic.
689 AC_DEFUN([OL_SYS_ERRLIST],
690 [
691 AC_MSG_CHECKING([declaration of sys_errlist])
692 AC_CACHE_VAL(ol_cv_dcl_sys_errlist,[
693         AC_TRY_COMPILE([
694 #include <stdio.h>
695 #include <sys/types.h>
696 #include <errno.h> ],
697         [char *c = (char *) *sys_errlist],
698         [ol_cv_dcl_sys_errlist=yes],
699         [ol_cv_dcl_sys_errlist=no])])
700 AC_MSG_RESULT($ol_cv_dcl_sys_errlist)
701 # It's possible (for near-UNIX clones) that sys_errlist doesn't exist
702 if test $ol_cv_dcl_sys_errlist = no ; then
703         AC_DEFINE(DECL_SYS_ERRLIST,1,
704                 [define if sys_errlist is not declared in stdio.h or errno.h])
705         AC_MSG_CHECKING([existence of sys_errlist])
706         AC_CACHE_VAL(ol_cv_have_sys_errlist,[
707                 AC_TRY_LINK([#include <errno.h>],
708                         [char *c = (char *) *sys_errlist],
709                         [ol_cv_have_sys_errlist=yes],
710                         [ol_cv_have_sys_errlist=no])])
711         AC_MSG_RESULT($ol_cv_have_sys_errlist)
712         if test $ol_cv_have_sys_errlist = yes ; then
713                 AC_DEFINE(HAVE_SYS_ERRLIST,1,
714                         [define if you actually have sys_errlist in your libs])
715         fi
716 fi
717 ])dnl
718 dnl
719 dnl ====================================================================
720 dnl Early MIPS compilers (used in Ultrix 4.2) don't like
721 dnl "int x; int *volatile a = &x; *a = 0;"
722 dnl     -- borrowed from PDKSH
723 AC_DEFUN(OL_C_VOLATILE,
724  [AC_CACHE_CHECK(if compiler understands volatile, ol_cv_c_volatile,
725     [AC_TRY_COMPILE([int x, y, z;],
726       [volatile int a; int * volatile b = x ? &y : &z;
727       /* Older MIPS compilers (eg., in Ultrix 4.2) don't like *b = 0 */
728       *b = 0;], ol_cv_c_volatile=yes, ol_cv_c_volatile=no)])
729   if test $ol_cv_c_volatile = yes; then
730     : 
731   else
732     AC_DEFINE(volatile,)
733   fi
734  ])dnl
735 dnl
736 dnl ====================================================================
737 dnl Define sig_atomic_t if not defined in signal.h
738 AC_DEFUN(OL_TYPE_SIG_ATOMIC_T,
739  [AC_CACHE_CHECK(for sig_atomic_t, ol_cv_type_sig_atomic_t,
740     [AC_TRY_COMPILE([#include <signal.h>], [sig_atomic_t atomic;],
741                 ol_cv_type_sig_atomic_t=yes, ol_cv_type_sig_atomic_t=no)])
742   if test $ol_cv_type_sig_atomic_t = no; then
743     AC_DEFINE(sig_atomic_t, int)
744   fi
745  ])dnl
746 dnl
747 dnl ====================================================================
748 dnl check no of arguments for ctime_r
749 AC_DEFUN(OL_FUNC_CTIME_R_NARGS,
750  [AC_CACHE_CHECK(number of arguments of ctime_r, ol_cv_func_ctime_r_nargs,
751    [AC_TRY_COMPILE([#include <time.h>],
752                 [time_t ti; char *buffer; ctime_r(&ti,buffer,32);],
753                         ol_cv_func_ctime_r_nargs=3,
754                         [AC_TRY_COMPILE([#include <time.h>],
755                                 [time_t ti; char *buffer; ctime_r(&ti,buffer);],
756                                         ol_cv_func_ctime_r_nargs=2,
757                                         ol_cv_func_ctime_r_nargs=0)])])
758   if test $ol_cv_func_ctime_r_nargs -gt 1 ; then
759     AC_DEFINE_UNQUOTED(CTIME_R_NARGS, $ol_cv_func_ctime_r_nargs,
760                 [set to the number of arguments ctime_r() expects])
761   fi
762 ])dnl
763 dnl
764 dnl --------------------------------------------------------------------
765 dnl check return type of ctime_r()
766 AC_DEFUN(OL_FUNC_CTIME_R_TYPE,
767  [AC_CACHE_CHECK(return type of ctime_r, ol_cv_func_ctime_r_type,
768    [AC_TRY_COMPILE([#include <time.h>],
769                 [extern int (ctime_r)();],
770                         ol_cv_func_ctime_r_type="int", ol_cv_func_ctime_r_type="charp")
771         ])
772   if test $ol_cv_func_ctime_r_type = "int" ; then
773         AC_DEFINE(CTIME_R_RETURNS_INT,1, [define if ctime_r() returns int])
774   fi
775 ])dnl
776 dnl ====================================================================
777 dnl check no of arguments for gethostbyname_r
778 AC_DEFUN(OL_FUNC_GETHOSTBYNAME_R_NARGS,
779  [AC_CACHE_CHECK(number of arguments of gethostbyname_r,
780         ol_cv_func_gethostbyname_r_nargs,
781         [AC_TRY_COMPILE([#include <sys/types.h>
782 #include <sys/socket.h>
783 #include <netinet/in.h>
784 #include <netdb.h>
785 #define BUFSIZE (sizeof(struct hostent)+10)],
786                 [struct hostent hent; char buffer[BUFSIZE];
787                 int bufsize=BUFSIZE;int h_errno;
788                 (void)gethostbyname_r("segovia.cs.purdue.edu", &hent,
789                         buffer, bufsize, &h_errno);],
790                 ol_cv_func_gethostbyname_r_nargs=5, 
791                 [AC_TRY_COMPILE([#include <sys/types.h>
792 #include <sys/socket.h>
793 #include <netinet/in.h>
794 #include <netdb.h>
795 #define BUFSIZE (sizeof(struct hostent)+10)],
796                         [struct hostent hent;struct hostent *rhent;
797                         char buffer[BUFSIZE];
798                         int bufsize=BUFSIZE;int h_errno;
799                         (void)gethostbyname_r("localhost", &hent, buffer, bufsize,
800                                 &rhent, &h_errno);],
801                         ol_cv_func_gethostbyname_r_nargs=6,
802                         ol_cv_func_gethostbyname_r_nargs=0)])])
803   if test $ol_cv_func_gethostbyname_r_nargs -gt 1 ; then
804         AC_DEFINE_UNQUOTED(GETHOSTBYNAME_R_NARGS,
805                 $ol_cv_func_gethostbyname_r_nargs,
806                 [set to the number of arguments gethostbyname_r() expects])
807   fi
808 ])dnl
809 dnl
810 dnl check no of arguments for gethostbyaddr_r
811 AC_DEFUN(OL_FUNC_GETHOSTBYADDR_R_NARGS,
812  [AC_CACHE_CHECK(number of arguments of gethostbyaddr_r,
813         [ol_cv_func_gethostbyaddr_r_nargs],
814         [AC_TRY_COMPILE([#include <sys/types.h>
815 #include <sys/socket.h>
816 #include <netinet/in.h>
817 #include <netdb.h>
818 #define BUFSIZE (sizeof(struct hostent)+10)],
819            [struct hostent hent; char buffer[BUFSIZE]; 
820             struct in_addr add;
821             size_t alen=sizeof(struct in_addr);
822             int bufsize=BUFSIZE;int h_errno;
823                 (void)gethostbyaddr_r( (void *)&(add.s_addr),
824                         alen, AF_INET, &hent, buffer, bufsize, &h_errno);],
825                 ol_cv_func_gethostbyaddr_r_nargs=7,
826                 [AC_TRY_COMPILE([#include <sys/types.h>
827 #include <sys/socket.h>
828 #include <netinet/in.h>
829 #include <netdb.h>
830 #define BUFSIZE (sizeof(struct hostent)+10)],
831                         [struct hostent hent;
832                         struct hostent *rhent; char buffer[BUFSIZE]; 
833                         struct in_addr add;
834                         size_t alen=sizeof(struct in_addr);
835                         int bufsize=BUFSIZE;int h_errno;
836                         (void)gethostbyaddr_r( (void *)&(add.s_addr),
837                                 alen, AF_INET, &hent, buffer, bufsize, 
838                                 &rhent, &h_errno);],
839                         ol_cv_func_gethostbyaddr_r_nargs=8,
840                         ol_cv_func_gethostbyaddr_r_nargs=0)])])
841   if test $ol_cv_func_gethostbyaddr_r_nargs -gt 1 ; then
842     AC_DEFINE_UNQUOTED(GETHOSTBYADDR_R_NARGS,
843                 $ol_cv_func_gethostbyaddr_r_nargs,
844                 [set to the number of arguments gethostbyaddr_r() expects])
845   fi
846 ])dnl
847 dnl