import from HEAD
[freeradius.git] / aclocal.m4
1 # aclocal.m4
2 # This line will prevent autoreconf from running aclocal again.
3 # generated automatically by aclocal 1.9.5 -*- Autoconf -*-
4
5 m4_include([libtool.m4])
6
7 dnl See whether we need a declaration for a function.
8 dnl RADIUSD_NEED_DECLARATION(FUNCTION [, EXTRA-HEADER-FILES])
9 AC_DEFUN(RADIUSD_NEED_DECLARATION,
10 [AC_MSG_CHECKING([whether $1 must be declared])
11 AC_CACHE_VAL(radius_cv_decl_needed_$1,
12 [AC_TRY_COMPILE([
13 #include <stdio.h>
14 #include <string.h>
15 #ifdef HAVE_UNISTD_H
16 #include <unistd.h>
17 #endif
18 #ifdef HAVE_CRYPT_H
19 #include <crypt.h>
20 #endif
21 #ifdef HAVE_ERRNO_H
22 #include <errno.h>
23 #endif
24 #ifdef HAVE_RESOURCE_H
25 #include <resource.h>
26 #endif
27 #ifdef HAVE_GETOPT_H
28 #include <getopt.h>
29 #endif
30 #ifdef HAVE_MALLOC_H
31 #include <malloc.h>
32 #endif
33 #ifdef HAVE_UTMP_H
34 #include <utmp.h>
35 #endif
36 #ifdef HAVE_UTMPX_H
37 #include <utmpx.h>
38 #endif
39 #ifdef HAVE_SYS_SELECT_H
40 #include <sys/select.h>
41 #endif
42 #ifdef HAVE_DLFCN_H
43 #include <dlfcn.h>
44 #endif
45 #ifdef HAVE_REGEX_H
46 #include <regex.h>
47 #endif
48 #ifdef HAVE_SYSLOG_H
49 #include <syslog.h>
50 #endif
51 #ifdef HAVE_INTTYPES_H
52 #include <inttypes.h>
53 #endif
54 #ifdef HAVE_STDINT_H
55 #include <stdint.h>
56 #endif
57 #ifdef HAVE_ARPA_INET_H
58 #include <arpa/inet.h>
59 #endif
60 $2],
61 [char *(*pfn) = (char *(*)) $1],
62 eval "radius_cv_decl_needed_$1=no", eval "radius_cv_decl_needed_$1=yes")])
63 if eval "test \"`echo '$radius_cv_decl_needed_'$1`\" = yes"; then
64   AC_MSG_RESULT(yes)
65   radius_tr_decl=NEED_DECLARATION_`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
66   AC_DEFINE_UNQUOTED($radius_tr_decl)
67 else
68   AC_MSG_RESULT(no)
69 fi
70 ])dnl
71
72 dnl Check multiple functions to see whether each needs a declaration.
73 dnl RADIUSD_NEED_DECLARATIONS(FUNCTION... [, EXTRA-HEADER-FILES])
74 AC_DEFUN(RADIUSD_NEED_DECLARATIONS,
75 [for ac_func in $1
76 do
77 RADIUSD_NEED_DECLARATION($ac_func, $2)
78 done
79 ])
80
81 dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY)
82 dnl The program must properly implement --version.
83 AC_DEFUN(AM_MISSING_PROG,
84 [AC_MSG_CHECKING(for working $2)
85 # Run test in a subshell; some versions of sh will print an error if
86 # an executable is not found, even if stderr is redirected.
87 # Redirect stdin to placate older versions of autoconf.  Sigh.
88 if ($2 --version) < /dev/null > /dev/null 2>&1; then
89    $1=$2
90    AC_MSG_RESULT(found)
91 else
92    $1="$3/missing $2"
93    AC_MSG_RESULT(missing)
94 fi
95 AC_SUBST($1)])
96
97
98 dnl Checks to see if this is SUNPro we're building with
99 dnl Usage:
100 dnl AC_PROG_CC_SUNPRO
101 AC_DEFUN(AC_PROG_CC_SUNPRO,
102 [AC_CACHE_CHECK(whether we are using SUNPro C, ac_cv_prog_suncc,
103 [dnl The semicolon is to pacify NeXT's syntax-checking cpp.
104 cat > conftest.c <<EOF
105 #ifdef __SUNPRO_C
106   yes;
107 #endif
108 EOF
109 if AC_TRY_COMMAND(${CC-cc} -E conftest.c) | egrep yes >/dev/null 2>&1; then
110   ac_cv_prog_suncc=yes
111 else
112   ac_cv_prog_suncc=no
113 fi])])
114
115 dnl #
116 dnl # AC_CHECK_TYPE_INCLUDE([#includes ...], type, default-C-types)
117 dnl #
118 dnl # This function is like AC_CHECK_TYPE, but you can give this one
119 dnl # a list of include files to check.
120 dnl #
121 AC_DEFUN(AC_CHECK_TYPE_INCLUDE,
122 [
123   AC_CACHE_CHECK(for $2, ac_cv_type_$2,
124     [ ac_cv_type_$2=no
125       AC_TRY_COMPILE($1,
126         [$2 foo],
127         ac_cv_type_$2=yes,
128       )
129     ]
130   )
131
132   if test "$ac_cv_type_$2" != "yes"; then
133          AC_DEFINE($2, $3)
134   fi
135 ])
136
137 dnl #######################################################################
138 dnl #
139 dnl #  Look for SNMP in a variety of places.
140 dnl #
141 AC_DEFUN(SNMP_CHECKS, [
142         AC_SUBST(SNMP_LIBS)
143         AC_SUBST(SNMP_INCLUDE)
144
145 AC_MSG_CHECKING([for asn1.h,snmp.h,snmp_impl.h])
146
147 dnl #
148 dnl #  First, see if we can build it WITHOUT using any special includes and in ucd-snmp
149 dnl #
150 AC_TRY_COMPILE([
151 #ifdef HAVE_SYS_TYPES_H
152 #include <sys/types.h>
153 #endif
154 #ifdef HAVE_STDINT_H
155 #include <stdint.h>
156 #endif
157 #ifdef HAVE_STDIO_H
158 #include <stdio.h>
159 #endif
160 #ifdef HAVE_NETDB_H
161 #include <netdb.h>
162 #endif
163 #ifdef HAVE_UNISTD_H
164 #include <unistd.h>
165 #endif
166 #include <ucd-snmp/ucd-snmp-config.h>
167 #include <ucd-snmp/asn1.h>
168 #include <ucd-snmp/snmp.h>
169 #include <ucd-snmp/snmp_impl.h>],
170                [ int a = 1;],
171                SNMP_INCLUDE="";ucdsnmp=yes,
172                ucdsnmp=)
173
174 dnl #
175 dnl #  If not, look for it in a number of directories and in ucd-snmp.
176 dnl #
177 if test "x$ucdsnmp" = "x"; then
178   old_CFLAGS="$CFLAGS"
179   for try in /usr/include /usr/local/include $with_snmp_include_dir; do
180     CFLAGS="$old_CFLAGS -I$try"
181     AC_TRY_COMPILE([
182 #ifdef HAVE_SYS_TYPES_H
183 #include <sys/types.h>
184 #endif
185 #ifdef HAVE_STDINT_H
186 #include <stdint.h>
187 #endif
188 #ifdef HAVE_STDIO_H
189 #include <stdio.h>
190 #endif
191 #ifdef HAVE_NETDB_H
192 #include <netdb.h>
193 #endif
194 #ifdef HAVE_UNISTD_H
195 #include <unistd.h>
196 #endif
197 #include <ucd-snmp/ucd-snmp-config.h>
198 #include <ucd-snmp/asn1.h>
199 #include <ucd-snmp/snmp.h>
200 #include <ucd-snmp/snmp_impl.h>],
201                    [ int a = 1;],
202                    SNMP_INCLUDE="-I$try";ucdsnmp=yes,
203                    ucdsnmp=)
204     if test "x$ucdsnmp" != "x"; then
205       break;
206     fi
207   done
208   CFLAGS="$old_CFLAGS"
209 fi
210
211 if test "x$ucdsnmp" = "x"; then
212   old_CFLAGS="$CFLAGS"
213   for try in /usr/include/ucd-snmp /usr/local/include/ucd-snmp $with_snmp_include_dir; do
214     CFLAGS="$old_CFLAGS -I$try"
215 dnl #
216 dnl #  First, see if we can build it WITHOUT using any special includes and without ucd-snmp
217 dnl #
218 AC_TRY_COMPILE([
219 #ifdef HAVE_SYS_TYPES_H
220 #include <sys/types.h>
221 #endif
222 #ifdef HAVE_STDINT_H
223 #include <stdint.h>
224 #endif
225 #ifdef HAVE_STDIO_H
226 #include <stdio.h>
227 #endif
228 #ifdef HAVE_NETDB_H
229 #include <netdb.h>
230 #endif
231 #ifdef HAVE_UNISTD_H
232 #include <unistd.h>
233 #endif
234 #include <asn1.h>
235 #include <snmp.h>
236 #include <snmp_impl.h>],
237                [ int a = 1;],
238                SNMP_INCLUDE="";ucdsnmp=no,
239                ucdsnmp=)
240     if test "x$ucdsnmp" != "x"; then
241       break;
242     fi
243   done
244   CFLAGS="$old_CFLAGS"
245 fi
246
247 dnl #
248 dnl #  If not, look for it in a number of directories and without ucd-snmp
249 dnl #
250 if test "x$ucdsnmp" = "x"; then
251   old_CFLAGS="$CFLAGS"
252   for try in /usr/include/ucd-snmp /usr/local/include/ucd-snmp $with_snmp_include_dir; do
253     CFLAGS="$old_CFLAGS -I$try"
254     AC_TRY_COMPILE([
255 #ifdef HAVE_SYS_TYPES_H
256 #include <sys/types.h>
257 #endif
258 #ifdef HAVE_STDINT_H
259 #include <stdint.h>
260 #endif
261 #ifdef HAVE_STDIO_H
262 #include <stdio.h>
263 #endif
264 #ifdef HAVE_NETDB_H
265 #include <netdb.h>
266 #endif
267 #ifdef HAVE_UNISTD_H
268 #include <unistd.h>
269 #endif
270 #include <asn1.h>
271 #include <snmp.h>
272 #include <snmp_impl.h>],
273                    [ int a = 1;],
274                    SNMP_INCLUDE="-I$try";ucdsnmp=no,
275                    ucdsnmp=)
276     if test "x$ucdsnmp" != "x"; then
277       break;
278     fi
279   done
280   CFLAGS="$old_CFLAGS"
281 fi
282
283 if test "x$ucdsnmp" = "x"; then
284   AC_MSG_RESULT(no)
285 else
286   if test "x$ucdsnmp" = "xyes"; then
287     AC_MSG_RESULT((ucd-snmp)yes)
288     AC_DEFINE(HAVE_UCD_SNMP_ASN1_SNMP_SNMPIMPL_H)
289   else
290     AC_MSG_RESULT(yes)
291     AC_DEFINE(HAVE_ASN1_SNMP_SNMPIMPL_H)
292   fi
293 dnl #
294 dnl #  Now do the same thing, looking for the SNMP library directory
295 dnl #
296   AC_MSG_CHECKING([for snmp_build_var_op in -lsnmp])
297
298 dnl #
299 dnl #  First, see if we can build it WITHOUT using any special includes
300 dnl #
301   old_LIBS="$LIBS"
302   LIBS="$old_LIBS -lsnmp"
303   AC_TRY_LINK([extern char snmp_build_var_op();],
304               [ snmp_build_var_op()],
305               SNMP_LIBS="-lsnmp",
306               SNMP_LIBS=)
307
308   if test "x$SNMP_LIBS" = "x"; then
309     for try in /usr/lib /usr/local/lib /usr/local/snmp/lib $with_snmp_lib_dir; do
310       LIBS="$old_LIBS -L$try -lsnmp"
311       AC_TRY_LINK([extern char snmp_build_var_op();],
312                   [ snmp_build_var_op()],
313                   SNMP_LIBS="-L$try -lsnmp",
314                   SNMP_LIBS=)
315       if test "x$SNMP_LIBS" != "x"; then
316         break;
317       fi
318 dnl   #
319 dnl   #  That didn't work.  Try adding the '-lcrypto' line.
320 dnl   #  Some SNMP libraries are linked against SSL...
321 dnl   #
322       LIBS="$old_LIBS -L$try -lsnmp -lcrypto"
323       AC_TRY_LINK([extern char snmp_build_var_op();],
324                   [ snmp_build_var_op()],
325                   SNMP_LIBS="-L$try -lsnmp -lcrypto",
326                   SNMP_LIBS=)
327       if test "x$SNMP_LIBS" != "x"; then
328         break;
329       fi
330 dnl   #
331 dnl   #  That didn't work.  Try adding the '-lkstat' line.
332 dnl   #  Some SNMP libraries are linked against Kernel Statistics,
333 dnl   #  in particular, Solaris 9...
334 dnl   #
335       LIBS="$old_LIBS -L$try -lsnmp -lcrypto -lkstat"
336       AC_TRY_LINK([extern char snmp_build_var_op();],
337                   [ snmp_build_var_op()],
338                   SNMP_LIBS="-L$try -lsnmp -lcrypto -lkstat",
339                   SNMP_LIBS=)
340       if test "x$SNMP_LIBS" != "x"; then
341         break;
342       fi
343     done
344   fi
345   LIBS="$old_LIBS"
346
347   dnl #
348   dnl #  If one or the other isn't found, disable them both..
349   dnl #  If both are found, enable them both.
350   dnl #
351   CFLAGS="$old_CFLAGS"
352   if test "x$SNMP_LIBS" = "x"; then
353     AC_MSG_RESULT(no)
354     SNMP_INCLUDE=
355   else
356     AC_MSG_RESULT(yes)
357     AC_DEFINE(WITH_SNMP)
358     AC_DEFINE(HAVE_LIBSNMP)
359   fi
360 fi
361 ])
362
363
364 dnl #
365 dnl #  Locate the directory in which a particular file is found.
366 dnl #
367 dnl #  Usage: AC_LOCATE_DIR(MYSQLLIB_DIR, libmysqlclient.a)
368 dnl #
369 dnl #    Defines the variable MYSQLLIB_DIR to be the directory(s) in
370 dnl #    which the file libmysqlclient.a is to be found.
371 dnl #
372 dnl #
373 AC_DEFUN(AC_LOCATE_DIR,
374 [
375 dnl # If we have the program 'locate', then the problem of finding a
376 dnl # particular file becomes MUCH easier.
377 dnl #
378
379 dnl #
380 dnl #  No 'locate' defined, do NOT do anything.
381 dnl #
382 if test "x$LOCATE" != "x"; then
383   dnl #
384   dnl #  Root through a series of directories, looking for the given file.
385   dnl #
386   DIRS=
387   file=$2
388
389   for x in `${LOCATE} $file 2>/dev/null`; do
390     dnl #
391     dnl #  When asked for 'foo', locate will also find 'foo_bar', which we
392     dnl #  don't want.  We want that EXACT filename.
393     dnl #
394     dnl #  We ALSO want to be able to look for files like 'mysql/mysql.h',
395     dnl #  and properly match them, too.  So we try to strip off the last
396     dnl #  part of the filename, using the name of the file we're looking
397     dnl #  for.  If we CANNOT strip it off, then the name will be unchanged.
398     dnl #
399     base=`echo $x | sed "s%/${file}%%"`
400     if test "x$x" = "x$base"; then
401       continue;
402     fi
403
404     dir=`${DIRNAME} $x 2>/dev/null`
405     dnl #
406     dnl #  Exclude a number of directories.
407     dnl #
408     exclude=`echo ${dir} | ${GREP} /home`
409     if test "x$exclude" != "x"; then
410       continue
411     fi
412
413     dnl #
414     dnl #  OK, we have an exact match.  Let's be sure that we only find ONE
415     dnl #  matching directory.
416     dnl #
417     already=`echo \$$1 ${DIRS} | ${GREP} ${dir}`
418     if test "x$already" = "x"; then
419       DIRS="$DIRS $dir"
420     fi
421   done
422 fi
423
424 dnl #
425 dnl #  And remember the directory in which we found the file.
426 dnl #
427 eval "$1=\"\$$1 $DIRS\""
428 ])
429
430
431 dnl #######################################################################
432 dnl #
433 dnl #  Look for a library in a number of places.
434 dnl #
435 dnl #  AC_SMART_CHECK_LIB(library, function)
436 dnl #
437 AC_DEFUN(AC_SMART_CHECK_LIB, [
438
439 sm_lib_safe=`echo "$1" | sed 'y%./+-%__p_%'`
440 sm_func_safe=`echo "$2" | sed 'y%./+-%__p_%'`
441 AC_MSG_CHECKING([for $2 in -l$1])
442
443 old_LIBS="$LIBS"
444 smart_lib=
445 smart_lib_dir=
446
447 dnl #
448 dnl #  Try first any user-specified directory, otherwise we may pick up
449 dnl #  the wrong version.
450 dnl #
451 if test "x$smart_try_dir" != "x"; then
452   for try in $smart_try_dir; do
453     LIBS="-L$try -l$1 $old_LIBS"
454     AC_TRY_LINK([extern char $2();],
455                 [ $2()],
456                 smart_lib="-L$try -l$1")
457     if test "x$smart_lib" != "x"; then
458       break;
459     fi
460   done
461   LIBS="$old_LIBS"
462 fi
463
464 dnl #
465 dnl #  Try using the default library path.
466 dnl #
467 if test "x$smart_lib" = "x"; then
468   LIBS="-l$1 $old_LIBS"
469   AC_TRY_LINK([extern char $2();],
470               [ $2()],
471               smart_lib="-l$1")
472   LIBS="$old_LIBS"
473 fi
474
475 dnl #
476 dnl #  Try to guess possible locations.
477 dnl #
478 if test "x$smart_lib" = "x"; then
479   AC_LOCATE_DIR(smart_lib_dir,[lib$1${libltdl_cv_shlibext}])
480   AC_LOCATE_DIR(smart_lib_dir,[lib$1.a])
481
482   for try in $smart_lib_dir /usr/local/lib /opt/lib; do
483     LIBS="-L$try -l$1 $old_LIBS"
484     AC_TRY_LINK([extern char $2();],
485                 [ $2()],
486                 smart_lib="-L$try -l$1")
487     if test "x$smart_lib" != "x"; then
488       break;
489     fi
490   done
491   LIBS="$old_LIBS"
492 fi
493
494 dnl #
495 dnl #  Found it, set the appropriate variable.
496 dnl #
497 if test "x$smart_lib" != "x"; then
498   AC_MSG_RESULT(yes)
499   eval "ac_cv_lib_${sm_lib_safe}_${sm_func_safe}=yes"
500   LIBS="$smart_lib $old_LIBS"
501   SMART_LIBS="$smart_lib $SMART_LIBS"
502 else
503   AC_MSG_RESULT(no)
504 fi
505 ])
506
507 dnl #######################################################################
508 dnl #
509 dnl #  Look for a header file in a number of places.
510 dnl #
511 dnl #  AC_SMART_CHECK_INCLUDE(foo.h, [ #include <other.h> ])
512 dnl #
513 AC_DEFUN(AC_SMART_CHECK_INCLUDE, [
514
515 ac_safe=`echo "$1" | sed 'y%./+-%__pm%'`
516 AC_MSG_CHECKING([for $1])
517
518 old_CFLAGS="$CFLAGS"
519 smart_include=
520 smart_include_dir=
521
522 dnl #
523 dnl #  Try first any user-specified directory, otherwise we may pick up
524 dnl #  the wrong version.
525 dnl #
526 if test "x$smart_try_dir" != "x"; then
527   for try in $smart_try_dir; do
528     CFLAGS="$old_CFLAGS -I$try"
529     AC_TRY_COMPILE([$2
530                     #include <$1>],
531                    [ int a = 1;],
532                    smart_include="-I$try",
533                    smart_include=)
534     if test "x$smart_include" != "x"; then
535       break;
536     fi
537   done
538   CFLAGS="$old_CFLAGS"
539 fi
540
541 dnl #
542 dnl #  Try using the default includes
543 dnl #
544 if test "x$smart_include" = "x"; then
545   AC_TRY_COMPILE([$2
546                   #include <$1>],
547                  [ int a = 1;],
548                  smart_include=" ",
549                  smart_include=)
550 fi
551
552 dnl #
553 dnl #  Try to guess possible locations.
554 dnl #
555 if test "x$smart_include" = "x"; then
556   AC_LOCATE_DIR(smart_include_dir,$1)
557
558   for try in $smart_include_dir /usr/local/include /opt/include; do
559     CFLAGS="$old_CFLAGS -I$try"
560     AC_TRY_COMPILE([$2
561                     #include <$1>],
562                    [ int a = 1;],
563                    smart_include="-I$try",
564                    smart_include=)
565     if test "x$smart_include" != "x"; then
566       break;
567     fi
568   done
569   CFLAGS="$old_CFLAGS"
570 fi
571
572 dnl #
573 dnl #  Found it, set the appropriate variable.
574 dnl #
575 if test "x$smart_include" != "x"; then
576   AC_MSG_RESULT(yes)
577   eval "ac_cv_header_$ac_safe=yes"
578   CFLAGS="$old_CFLAGS $smart_include"
579   SMART_CFLAGS="$SMART_CFLAGS $smart_include"
580 else
581   AC_MSG_RESULT(no)
582 fi
583 ])
584
585 dnl #######################################################################
586 dnl #
587 dnl #  Look for a header file in a number of places.
588 dnl #
589 dnl #  Usage:  AC_CHECK_STRUCT_HAS_MEMBER([#include <foo.h>], [struct foo], member)
590 dnl #  If the member is defined, then the variable
591 dnl #     ac_cv_type_struct_foo_has_member is set to 'yes'
592 dnl #
593 AC_DEFUN(AC_CHECK_STRUCT_HAS_MEMBER, [
594   AC_MSG_CHECKING([for $3 in $2])
595
596 dnl BASED on 'offsetof':
597 dnl #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
598 dnl
599
600   AC_TRY_COMPILE([
601 $1
602 #ifndef offsetof
603 #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
604 #endif
605 ],
606                  [ int foo = offsetof($2, $3) ],
607                  has_element=" ",
608                  has_element=)
609
610   ac_safe_type=`echo "$2" | sed 'y% %_%'`
611   if test "x$has_element" != "x"; then
612     AC_MSG_RESULT(yes)
613     eval "ac_cv_type_${ac_safe_type}_has_$3=yes"
614   else
615     AC_MSG_RESULT(no) 
616     eval "ac_cv_type_${ac_safe_type}_has_$3="
617  fi
618 ])