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