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