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