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