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