]> git.sur5r.net Git - openldap/blob - build/openldap.m4
Patch to support to determine the number of args of the
[openldap] / build / openldap.m4
1 dnl Copyright 1998 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 builtin(include, build/libtool.m4)dnl
7 dnl --------------------------------------------------------------------
8 dnl Restricted form of AC_ARG_ENABLE that limits user options
9 dnl
10 dnl $1 = option name
11 dnl $2 = help-string
12 dnl $3 = default value  (auto)
13 dnl $4 = allowed values (auto yes no)
14 AC_DEFUN([OL_ARG_ENABLE], [# OpenLDAP --enable-$1
15         AC_ARG_ENABLE($1,[$2 (]ifelse($3,,auto,$3)[)],[
16         ol_arg=invalid
17         for ol_val in ifelse($4,,[auto yes no],[$4]) ; do
18                 if test "$enableval" = "$ol_val" ; then
19                         ol_arg="$ol_val"
20                 fi
21         done
22         if test "$ol_arg" = "invalid" ; then
23                 AC_MSG_ERROR(bad value $enableval for --enable-$1)
24         fi
25         ol_enable_$1="$ol_arg"
26 ],
27 [       ol_enable_$1=ifelse($3,,"auto","$3")])dnl
28 dnl AC_VERBOSE(OpenLDAP -enable-$1 $ol_enable_$1)
29 # end --enable-$1
30 ])dnl
31 dnl
32 dnl --------------------------------------------------------------------
33 dnl Restricted form of AC_ARG_WITH that limits user options
34 dnl
35 dnl $1 = option name
36 dnl $2 = help-string
37 dnl $3 = default value (no)
38 dnl $4 = allowed values (yes or no)
39 AC_DEFUN([OL_ARG_WITH], [# OpenLDAP --with-$1
40         AC_ARG_WITH($1,[$2 (]ifelse($3,,yes,$3)[)],[
41         ol_arg=invalid
42         for ol_val in ifelse($4,,[yes no],[$4]) ; do
43                 if test "$withval" = "$ol_val" ; then
44                         ol_arg="$ol_val"
45                 fi
46         done
47         if test "$ol_arg" = "invalid" ; then
48                 AC_MSG_ERROR(bad value $withval for --with-$1)
49         fi
50         ol_with_$1="$ol_arg"
51 ],
52 [       ol_with_$1=ifelse($3,,"no","$3")])dnl
53 dnl AC_VERBOSE(OpenLDAP --with-$1 $ol_with_$1)
54 # end --with-$1
55 ])dnl
56 dnl
57 dnl ====================================================================
58 dnl Check if db.h is Berkeley DB2
59 dnl
60 dnl defines ol_cv_header_db2 to 'yes' or 'no'
61 dnl
62 dnl uses:
63 dnl             AC_CHECK_HEADERS(db.h)
64 dnl
65 AC_DEFUN([OL_HEADER_BERKELEY_DB2],
66 [AC_CHECK_HEADERS(db.h)
67 if test $ac_cv_header_db_h = yes ; then
68         AC_CACHE_CHECK([if db.h is DB2], [ol_cv_header_db2],[
69                 AC_EGREP_CPP(__db_version_2,[
70 #                       include <db.h>
71                         /* this check could be improved */
72 #                       ifdef DB_VERSION_MAJOR
73 #                               if DB_VERSION_MAJOR == 2
74                                         __db_version_2
75 #                               endif
76 #                       endif
77                 ], ol_cv_header_db2=yes, ol_cv_header_db2=no)])
78 else
79         ol_cv_header_db2=no
80 fi
81 ])dnl
82 dnl --------------------------------------------------------------------
83 dnl Check if Berkeley DB2 library exists
84 dnl Check for dbopen in standard libraries or -ldb
85 dnl
86 dnl defines ol_cv_lib_db2 to '-ldb' or 'no'
87 dnl
88 dnl uses:
89 dnl             AC_CHECK_LIB(db,db_open)
90 dnl
91 AC_DEFUN([OL_LIB_BERKELEY_DB2],
92 [AC_CACHE_CHECK([for DB2 library], [ol_cv_lib_db2],
93 [       ol_LIBS="$LIBS"
94         AC_CHECK_LIB(db,db_open,[ol_cv_lib_db2=-ldb],[ol_cv_lib_db2=no])
95         LIBS="$ol_LIBS"
96 ])
97 ])dnl
98 dnl
99 dnl --------------------------------------------------------------------
100 dnl Check if Berkeley db2 exists
101 dnl
102 dnl defines ol_cv_berkeley_db2 to 'yes' or 'no'
103 dnl 
104 dnl uses:
105 dnl             OL_LIB_BERKELEY_DB2
106 dnl             OL_HEADER_BERKELEY_DB2
107 dnl
108 AC_DEFUN([OL_BERKELEY_DB2],
109 [AC_REQUIRE([OL_LIB_BERKELEY_DB2])
110  AC_REQUIRE([OL_HEADER_BERKELEY_DB2])
111  AC_CACHE_CHECK([for Berkeley DB2], [ol_cv_berkeley_db2], [
112         if test "$ol_cv_lib_db2" = no -o "$ol_cv_header_db2" = no ; then
113                 ol_cv_berkeley_db2=no
114         else
115                 ol_cv_berkeley_db2=yes
116         fi
117 ])
118  if test $ol_cv_berkeley_db2 = yes ; then
119         AC_DEFINE(HAVE_BERKELEY_DB2,1)
120  fi
121 ])dnl
122 dnl
123 dnl ====================================================================
124 dnl Check for db.h/db_185.h is Berkeley DB
125 dnl
126 dnl defines ol_cv_header_db to 'yes' or 'no'
127 dnl
128 dnl uses:
129 dnl             OL_HEADER_BERKELEY_DB2
130 dnl             AC_CHECK_HEADERS(db_185.h)
131 dnl
132 AC_DEFUN([OL_HEADER_BERKELEY_DB],
133 [AC_REQUIRE([OL_HEADER_BERKELEY_DB2])
134 AC_CHECK_HEADERS(db_185.h)
135 if test "$ol_cv_header_db2" = yes ; then
136         dnl db.h is db2! 
137
138         ol_cv_header_db=$ac_cv_header_db_185_h
139 else
140         ol_cv_header_db=$ac_cv_header_db_h
141 fi
142 ])dnl
143 dnl
144 dnl --------------------------------------------------------------------
145 dnl Check if Berkeley DB library exists
146 dnl Check for dbopen in standard libraries or -ldb
147 dnl
148 dnl defines ol_cv_lib_db to 'yes' or '-ldb' or 'no'
149 dnl             'yes' implies dbopen is in $LIBS
150 dnl
151 dnl uses:
152 dnl             AC_CHECK_FUNC(dbopen)
153 dnl             AC_CHECK_LIB(db,dbopen)
154 dnl
155 AC_DEFUN([OL_LIB_BERKELEY_DB],
156 [AC_CACHE_CHECK([for Berkeley DB library], [ol_cv_lib_db],
157 [       ol_LIBS="$LIBS"
158         AC_CHECK_FUNC(dbopen,[ol_cv_lib_db=yes], [
159                 AC_CHECK_LIB(db,dbopen,[ol_cv_lib_db=-ldb],[ol_cv_lib_db=no])
160         ])
161         LIBS="$ol_LIBS"
162 ])
163 ])dnl
164 dnl
165 dnl --------------------------------------------------------------------
166 dnl Check if Berkeley DB exists
167 dnl
168 dnl defines ol_cv_berkeley_db to 'yes' or 'no'
169 dnl 
170 dnl uses:
171 dnl             OL_LIB_BERKELEY_DB
172 dnl             OL_HEADER_BERKELEY_DB
173 dnl
174 AC_DEFUN([OL_BERKELEY_DB],
175 [AC_REQUIRE([OL_LIB_BERKELEY_DB])
176  AC_REQUIRE([OL_HEADER_BERKELEY_DB])
177  AC_CACHE_CHECK([for Berkeley DB], [ol_cv_berkeley_db], [
178         if test "$ol_cv_lib_db" = no -o "$ol_cv_header_db" = no ; then
179                 ol_cv_berkeley_db=no
180         else
181                 ol_cv_berkeley_db=yes
182         fi
183 ])
184  if test $ol_cv_berkeley_db = yes ; then
185         AC_DEFINE(HAVE_BERKELEY_DB,1)
186  fi
187 ])dnl
188 dnl
189 dnl ====================================================================
190 dnl Check if GDBM library exists
191 dnl Check for gdbm_open in standard libraries or -lgdbm
192 dnl
193 dnl defines ol_cv_lib_gdbm to 'yes' or '-lgdbm' or 'no'
194 dnl             'yes' implies gdbm_open is in $LIBS
195 dnl
196 dnl uses:
197 dnl             AC_CHECK_FUNC(gdbm_open)
198 dnl             AC_CHECK_LIB(gdbm,gdbm_open)
199 dnl
200 AC_DEFUN([OL_LIB_GDBM],
201 [AC_CACHE_CHECK(for GDBM library, [ol_cv_lib_gdbm],
202 [       ol_LIBS="$LIBS"
203         AC_CHECK_FUNC(gdbm_open,[ol_cv_lib_gdbm=yes], [
204                 AC_CHECK_LIB(gdbm,gdbm_open,[ol_cv_lib_gdbm=-lgdbm],[ol_cv_lib_gdbm=no])
205         ])
206         LIBS="$ol_LIBS"
207 ])
208 ])dnl
209 dnl
210 dnl --------------------------------------------------------------------
211 dnl Check if GDBM exists
212 dnl
213 dnl defines ol_cv_gdbm to 'yes' or 'no'
214 dnl 
215 dnl uses:
216 dnl             OL_LIB_GDBM
217 dnl             AC_CHECK_HEADERS(gdbm.h)
218 dnl
219 AC_DEFUN([OL_GDBM],
220 [AC_REQUIRE([OL_LIB_GDBM])
221  AC_CHECK_HEADERS(gdbm.h)
222  AC_CACHE_CHECK(for db, [ol_cv_gdbm], [
223         if test $ol_cv_lib_gdbm = no -o $ac_cv_header_gdbm_h = no ; then
224                 ol_cv_gdbm=no
225         else
226                 ol_cv_gdbm=yes
227         fi
228 ])
229  if test $ol_cv_gdbm = yes ; then
230         AC_DEFINE(HAVE_GDBM,1)
231  fi
232 ])dnl
233 dnl
234 dnl ====================================================================
235 dnl Check if NDBM library exists
236 dnl Check for dbm_open in standard libraries or -lndbm or -ldbm
237 dnl
238 dnl defines ol_cv_lib_ndbm to 'yes' or '-lndbm' or -ldbm or 'no'
239 dnl             'yes' implies ndbm_open is in $LIBS
240 dnl
241 dnl uses:
242 dnl             AC_CHECK_FUNC(dbm_open)
243 dnl             AC_CHECK_LIB(ndbm,dbm_open)
244 dnl             AC_CHECK_LIB(dbm,dbm_open)
245 dnl
246 dnl restrictions:
247 dnl             should also check SVR4 case: dbm_open() in -lucb but that
248 dnl             would requiring dealing with -L/usr/ucblib
249 dnl
250 AC_DEFUN([OL_LIB_NDBM],
251 [AC_CACHE_CHECK(for NDBM library, [ol_cv_lib_ndbm],
252 [       ol_LIBS="$LIBS"
253         AC_CHECK_FUNC(dbm_open,[ol_cv_lib_ndbm=yes], [
254                 AC_CHECK_LIB(ndbm,dbm_open,[ol_cv_lib_ndbm=-lndbm], [
255                         AC_CHECK_LIB(dbm,dbm_open,[ol_cv_lib_ndbm=-ldbm],
256                                 [ol_cv_lib_ndbm=no])dnl
257                 ])
258         ])
259         LIBS="$ol_LIBS"
260 ])
261 ])dnl
262 dnl
263 dnl --------------------------------------------------------------------
264 dnl Check if NDBM exists
265 dnl
266 dnl defines ol_cv_ndbm to 'yes' or 'no'
267 dnl 
268 dnl uses:
269 dnl             OL_LIB_NDBM
270 dnl             AC_CHECK_HEADERS(ndbm.h)
271 dnl
272 dnl restrictions:
273 dnl             Doesn't handle SVR4 case (see above)
274 dnl
275 AC_DEFUN([OL_NDBM],
276 [AC_REQUIRE([OL_LIB_NDBM])
277  AC_CHECK_HEADERS(ndbm.h)
278  AC_CACHE_CHECK(for db, [ol_cv_ndbm], [
279         if test $ol_cv_lib_ndbm = no -o $ac_cv_header_ndbm_h = no ; then
280                 ol_cv_ndbm=no
281         else
282                 ol_cv_ndbm=yes
283         fi
284 ])
285  if test $ol_cv_ndbm = yes ; then
286         AC_DEFINE(HAVE_NDBM,1)
287  fi
288 ])dnl
289 dnl
290 dnl ====================================================================
291 dnl Check POSIX Thread version 
292 dnl
293 dnl defines ol_cv_posix_version to 'final' or 'draft' or 'unknown'
294 dnl     'unknown' implies that the version could not be detected
295 dnl             or that pthreads.h does exist.  Existance of pthreads.h
296 dnl             should be tested separately.
297 dnl
298 AC_DEFUN([OL_POSIX_THREAD_VERSION],
299 [AC_CACHE_CHECK([POSIX thread version],[ol_cv_pthread_version],[
300         AC_EGREP_CPP(pthread_version_final,[
301 #               include <pthread.h>
302                 /* this check could be improved */
303 #               ifdef PTHREAD_ONCE_INIT
304                         pthread_version_final
305 #               endif
306         ], ol_pthread_final=yes, ol_pthread_final=no)
307
308         AC_EGREP_CPP(pthread_version_draft4,[
309 #               include <pthread.h>
310                 /* this check could be improved */
311 #               ifdef pthread_once_init
312                         pthread_version_draft4
313 #               endif
314         ], ol_pthread_draft4=yes, ol_pthread_draft4=no)
315
316         if test $ol_pthread_final = yes -a $ol_pthread_draft4 = no; then
317                 ol_cv_pthread_version=final
318         elif test $ol_pthread_final = no -a $ol_pthread_draft4 = yes; then
319                 ol_cv_pthread_version=draft4
320         else
321                 ol_cv_pthread_version=unknown
322         fi
323 ])
324 ])dnl
325 dnl
326 dnl --------------------------------------------------------------------
327 dnl Check LinuxThread
328 dnl
329 dnl defines ol_cv_linux_threads to 'yes' or 'no'
330 dnl             'no' implies pthreads.h is not LinuxThreads or pthreads.h
331 dnl             doesn't exists.  Existance of pthread.h should separately
332 dnl             checked.
333 dnl 
334 AC_DEFUN([OL_LINUX_THREADS],
335 [
336 AC_CACHE_CHECK([for LinuxThreads], [ol_cv_linux_threads], [
337         res=`grep Linuxthreads /usr/include/pthread.h 2>/dev/null | wc -l`
338         if test "$res" -gt 0 ; then
339                 ol_cv_linux_threads=yes
340         else
341                 ol_cv_linux_threads=no
342         fi
343 ])
344 ])dnl
345 dnl
346 dnl ====================================================================
347 dnl Check if toupper() requires islower() to be called first
348 AC_DEFUN([OL_C_UPPER_LOWER],
349 [
350 AC_MSG_CHECKING([if toupper() requires islower()])
351 AC_CACHE_VAL(ol_cv_c_upper_lower,[
352         AC_TRY_RUN([
353 #include <ctype.h>
354 main()
355 {
356         if ('C' == toupper('C'))
357                 exit(0);
358         else
359                 exit(1);
360 }],
361         [ol_cv_c_upper_lower=no],
362         [ol_cv_c_upper_lower=yes],
363         [ol_cv_c_upper_lower=safe])])
364 AC_MSG_RESULT($ol_cv_c_upper_lower)
365 if test $ol_cv_c_upper_lower != no ; then
366         AC_DEFINE(C_UPPER_LOWER,1)
367 fi
368 ])
369
370 dnl ====================================================================
371 dnl Check for declaration of sys_errlist in one of stdio.h and errno.h.
372 dnl Declaration of sys_errlist on BSD4.4 interferes with our declaration.
373 dnl Reported by Keith Bostic.
374 AC_DEFUN([OL_SYS_ERRLIST],
375 [
376 AC_MSG_CHECKING([declaration of sys_errlist])
377 AC_CACHE_VAL(ol_cv_dcl_sys_errlist,[
378         AC_TRY_COMPILE([
379 #include <stdio.h>
380 #include <sys/types.h>
381 #include <errno.h> ],
382         [char *c = (char *) *sys_errlist],
383         [ol_cv_dcl_sys_errlist=yes],
384         [ol_cv_dcl_sys_errlist=no])])
385 AC_MSG_RESULT($ol_cv_dcl_sys_errlist)
386
387 # It's possible (for near-UNIX clones) that sys_errlist doesn't exist
388 if test $ol_cv_dcl_sys_errlist = no ; then
389         AC_DEFINE(DECL_SYS_ERRLIST,1)
390         AC_MSG_CHECKING([existence of sys_errlist])
391         AC_CACHE_VAL(ol_cv_have_sys_errlist,[
392                 AC_TRY_LINK([#include <errno.h>],
393                         [char *c = (char *) *sys_errlist],
394                         [ol_cv_have_sys_errlist=yes],
395                         [ol_cv_have_sys_errlist=no])])
396         AC_MSG_RESULT($ol_cv_have_sys_errlist)
397 fi
398 ])dnl
399
400 dnl ====================================================================
401 dnl Early MIPS compilers (used in Ultrix 4.2) don't like
402 dnl "int x; int *volatile a = &x; *a = 0;"
403 dnl     -- borrowed from PDKSH
404 AC_DEFUN(OL_C_VOLATILE,
405  [AC_CACHE_CHECK(if compiler understands volatile, ol_cv_c_volatile,
406     [AC_TRY_COMPILE([int x, y, z;],
407       [volatile int a; int * volatile b = x ? &y : &z;
408       /* Older MIPS compilers (eg., in Ultrix 4.2) don't like *b = 0 */
409       *b = 0;], ol_cv_c_volatile=yes, ol_cv_c_volatile=no)])
410   if test $ol_cv_c_volatile = yes; then
411     : 
412   else
413     AC_DEFINE(volatile, )
414   fi
415  ])dnl
416
417 dnl ====================================================================
418 dnl Define sig_atomic_t if not defined in signal.h
419 AC_DEFUN(OL_TYPE_SIG_ATOMIC_T,
420  [AC_CACHE_CHECK(for sig_atomic_t, ol_cv_type_sig_atomic_t,
421     [AC_TRY_COMPILE([#include <signal.h>], [sig_atomic_t atomic;],
422                 ol_cv_type_sig_atomic_t=yes, ol_cv_type_sig_atomic_t=no)])
423   if test $ol_cv_type_sig_atomic_t = no; then
424     AC_DEFINE(sig_atomic_t, int)
425   fi
426  ])dnl
427
428 dnl ====================================================================
429 dnl check no of arguments for ctime_r
430 AC_DEFUN(OL_FUNC_CTIME_R_NARGS,
431  [AC_CACHE_CHECK(number of arguments of ctime_r, ol_cv_func_ctime_r_nargs,
432    [AC_TRY_COMPILE([#include <time.h>],
433                 [time_t ti; char *buffer; ctime_r(&ti,buffer,32);],
434                         ol_cv_func_ctime_r_nargs=3, ol_cv_func_ctime_r_nargs=0)
435                 if test $ol_cv_func_ctime_r_nargs = 0 ; then
436                         AC_TRY_COMPILE([#include <time.h>],
437                                 [time_t ti; char *buffer;
438                                         ctime_r(&ti,buffer);],
439                                 ol_cv_func_ctime_r_nargs=2, ol_cv_func_ctime_r_nargs=0)
440                 fi
441         ])
442   if test $ol_cv_func_ctime_r_nargs -gt 1 ; then
443     AC_DEFINE_UNQUOTED(CTIME_R_NARGS, $ol_cv_func_ctime_r_nargs)
444   fi
445 ])dnl
446 dnl ====================================================================
447 dnl check no of arguments for gethostbyname_r
448 AC_DEFUN(OL_FUNC_GETHOSTBYNAME_R_NARGS,
449  [AC_CACHE_CHECK(number of arguments of gethostbyname_r, ol_cv_func_gethostbyname_r_nargs,
450    [AC_TRY_COMPILE([#include <sys/types.h>
451                     #include <sys/socket.h>
452                     #include <netinet/in.h>
453                     #include <netdb.h>
454                     #define BUFSIZE (sizeof(struct hostent)+10)],
455                    [struct hostent hent; char buffer[BUFSIZE];
456                     int bufsize=BUFSIZE;int h_errno;
457                     (void)gethostbyname_r( "segovia.cs.purdue.edu", &hent, buffer, bufsize, &h_errno);
458                     return 0;],
459                 ol_cv_func_gethostbyname_r_nargs=5, ol_cv_func_gethostbyname_r_nargs=0)
460                 if test $ol_cv_func_gethostbyname_r_nargs = 0 ; then
461                         AC_TRY_COMPILE([#include <sys/types.h>
462                     #include <sys/socket.h>
463                     #include <netinet/in.h>
464                     #include <netdb.h>
465                     #define BUFSIZE (sizeof(struct hostent)+10)],
466                    [struct hostent hent;struct hostent *rhent;
467                     char buffer[BUFSIZE];
468                     int bufsize=BUFSIZE;int h_errno;
469                      (void)gethostbyname_r( "segovia.cs.purdue.edu", &hent, buffer, bufsize, &rhent, &h_errno);
470                     return 0;],
471                    ol_cv_func_gethostbyname_r_nargs=6, ol_cv_func_gethostbyname_r_nargs=0)
472                 fi
473         ])
474   if test $ol_cv_func_gethostbyname_r_nargs -gt 1 ; then
475     AC_DEFINE_UNQUOTED(GETHOSTBYNAME_R_NARGS, $ol_cv_func_gethostbyname_r_nargs)
476   fi
477 ])dnl
478 dnl check no of arguments for gethostbyaddr_r
479 AC_DEFUN(OL_FUNC_GETHOSTBYADDR_R_NARGS,
480  [AC_CACHE_CHECK(number of arguments of gethostbyaddr_r, ol_cv_func_gethostbyaddr_r_nargs,
481    [AC_TRY_COMPILE([#include <sys/types.h>
482                     #include <sys/socket.h>
483                     #include <netinet/in.h>
484                     #include <netdb.h>
485                     #define BUFSIZE (sizeof(struct hostent)+10)],
486                    [struct hostent hent; char buffer[BUFSIZE]; 
487                     struct in_addr add={0x70707070};
488                     size_t alen=sizeof(struct in_addr);
489                     int bufsize=BUFSIZE;int h_errno;
490                     (void)gethostbyaddr_r( (void *)&(add.s_addr),
491                                 alen, AF_INET, &hent, buffer, bufsize, &h_errno);
492                     return 0;],
493                     ol_cv_func_gethostbyaddr_r_nargs=7,
494                     ol_cv_func_gethostbyaddr_r_nargs=0)
495                 if test $ol_cv_func_gethostbyaddr_r_nargs = 0 ; then
496                         AC_TRY_COMPILE([#include <sys/types.h>
497                     #include <sys/socket.h>
498                     #include <netinet/in.h>
499                     #include <netdb.h>
500                     #define BUFSIZE (sizeof(struct hostent)+10)],
501                    [struct hostent hent; struct hostent *rhent; char buffer[BUFSIZE]; 
502                     struct in_addr add={0x70707070};
503                     size_t alen=sizeof(struct in_addr);
504                     int bufsize=BUFSIZE;int h_errno;
505                     (void)gethostbyaddr_r( (void *)&(add.s_addr),
506                                 alen, AF_INET, &hent, buffer, bufsize, 
507                                 &rhent, &h_errno);
508                     return 0;],
509                     ol_cv_func_gethostbyaddr_r_nargs=8,
510                     ol_cv_func_gethostbyaddr_r_nargs=0)
511                 fi
512         ])
513   if test $ol_cv_func_gethostbyaddr_r_nargs -gt 1 ; then
514     AC_DEFINE_UNQUOTED(GETHOSTBYADDR_R_NARGS, $ol_cv_func_gethostbyaddr_r_nargs)
515   fi
516 ])dnl
517