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