Hack AC_LIBLTDL_INSTALLABLE so it sets LIBLTDLPATH (or not)
[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, $4)
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/ucd-snmp-config.h>
144 #include <ucd-snmp/asn1.h>
145 #include <ucd-snmp/snmp.h>
146 #include <ucd-snmp/snmp_impl.h>],
147                [ int a = 1;],
148                SNMP_INCLUDE="";ucdsnmp=yes,
149                ucdsnmp=)
150
151 dnl #
152 dnl #  If not, look for it in a number of directories and in ucd-snmp.
153 dnl #
154 if test "x$ucdsnmp" = "x"; then
155   old_CFLAGS="$CFLAGS"
156   for try in /usr/include /usr/local/include $snmp_include_dir; do
157     CFLAGS="$old_CFLAGS -I$try"
158     AC_TRY_COMPILE([
159 #ifdef HAVE_SYS_TYPES_H
160 #include <sys/types.h>
161 #endif
162 #ifdef HAVE_STDINT_H
163 #include <stdint.h>
164 #endif
165 #ifdef HAVE_STDIO_H
166 #include <stdio.h>
167 #endif
168 #ifdef HAVE_NETDB_H
169 #include <netdb.h>
170 #endif
171 #ifdef HAVE_UNISTD_H
172 #include <unistd.h>
173 #endif
174 #include <ucd-snmp/ucd-snmp-config.h>
175 #include <ucd-snmp/asn1.h>
176 #include <ucd-snmp/snmp.h>
177 #include <ucd-snmp/snmp_impl.h>],
178                    [ int a = 1;],
179                    SNMP_INCLUDE="-I$try";ucdsnmp=yes,
180                    ucdsnmp=)
181     if test "x$ucdsnmp" != "x"; then
182       break;
183     fi
184   done
185   CFLAGS="$old_CFLAGS"
186 fi
187
188 if test "x$ucdsnmp" = "x"; then
189   old_CFLAGS="$CFLAGS"
190   for try in /usr/include/ucd-snmp /usr/local/include/ucd-snmp $snmp_include_dir; do
191     CFLAGS="$old_CFLAGS -I$try"
192 dnl #
193 dnl #  First, see if we can build it WITHOUT using any special includes and without ucd-snmp
194 dnl #
195 AC_TRY_COMPILE([
196 #ifdef HAVE_SYS_TYPES_H
197 #include <sys/types.h>
198 #endif
199 #ifdef HAVE_STDINT_H
200 #include <stdint.h>
201 #endif
202 #ifdef HAVE_STDIO_H
203 #include <stdio.h>
204 #endif
205 #ifdef HAVE_NETDB_H
206 #include <netdb.h>
207 #endif
208 #ifdef HAVE_UNISTD_H
209 #include <unistd.h>
210 #endif
211 #include <asn1.h>
212 #include <snmp.h>
213 #include <snmp_impl.h>],
214                [ int a = 1;],
215                SNMP_INCLUDE="";ucdsnmp=no,
216                ucdsnmp=)
217     if test "x$ucdsnmp" != "x"; then
218       break;
219     fi
220   done
221   CFLAGS="$old_CFLAGS"
222 fi
223
224 dnl #
225 dnl #  If not, look for it in a number of directories and without ucd-snmp
226 dnl #
227 if test "x$ucdsnmp" = "x"; then
228   old_CFLAGS="$CFLAGS"
229   for try in /usr/include/ucd-snmp /usr/local/include/ucd-snmp $snmp_include_dir; do
230     CFLAGS="$old_CFLAGS -I$try"
231     AC_TRY_COMPILE([
232 #ifdef HAVE_SYS_TYPES_H
233 #include <sys/types.h>
234 #endif
235 #ifdef HAVE_STDINT_H
236 #include <stdint.h>
237 #endif
238 #ifdef HAVE_STDIO_H
239 #include <stdio.h>
240 #endif
241 #ifdef HAVE_NETDB_H
242 #include <netdb.h>
243 #endif
244 #ifdef HAVE_UNISTD_H
245 #include <unistd.h>
246 #endif
247 #include <asn1.h>
248 #include <snmp.h>
249 #include <snmp_impl.h>],
250                    [ int a = 1;],
251                    SNMP_INCLUDE="-I$try";ucdsnmp=no,
252                    ucdsnmp=)
253     if test "x$ucdsnmp" != "x"; then
254       break;
255     fi
256   done
257   CFLAGS="$old_CFLAGS"
258 fi
259
260 if test "x$ucdsnmp" = "x"; then
261   AC_MSG_RESULT(no)
262 else
263   if test "x$ucdsnmp" = "xyes"; then
264     AC_MSG_RESULT((ucd-snmp)yes)
265     AC_DEFINE(HAVE_UCD_SNMP_ASN1_SNMP_SNMPIMPL_H, [], [Define if you have the <ucd-snmp/asn1.h>, <ucd-snmp/snmp_impl.h> and <ucd-snmp/snmp.h> header file.])
266   else
267     AC_MSG_RESULT(yes)
268     AC_DEFINE(HAVE_ASN1_SNMP_SNMPIMPL_H, [], [Define if you have the <asn1.h>, <snmp_impl.h> and <snmp.h> header file.])
269   fi
270 dnl #
271 dnl #  Now do the same thing, looking for the SNMP library directory
272 dnl #
273   AC_MSG_CHECKING([for snmp_build_var_op in -lsnmp])
274
275 dnl #
276 dnl #  First, see if we can build it WITHOUT using any special includes
277 dnl #
278   old_LIBS="$LIBS"
279   LIBS="$old_LIBS -lsnmp"
280   AC_TRY_LINK([extern char snmp_build_var_op();],
281               [ snmp_build_var_op()],
282               SNMP_LIBS="-lsnmp",
283               SNMP_LIBS=)
284
285   if test "x$SNMP_LIBS" = "x"; then
286     for try in /usr/lib /usr/local/lib /usr/local/snmp/lib $with_snmp_lib_dir; do
287       LIBS="$old_LIBS -L$try -lsnmp"
288       AC_TRY_LINK([extern char snmp_build_var_op();],
289                   [ snmp_build_var_op()],
290                   SNMP_LIBS="-L$try -lsnmp",
291                   SNMP_LIBS=)
292       if test "x$SNMP_LIBS" != "x"; then
293         break;
294       fi
295 dnl   #
296 dnl   #  That didn't work.  Try adding the '-lcrypto' line.
297 dnl   #  Some SNMP libraries are linked against SSL...
298 dnl   #
299       LIBS="$old_LIBS -L$try -lsnmp -lcrypto"
300       AC_TRY_LINK([extern char snmp_build_var_op();],
301                   [ snmp_build_var_op()],
302                   SNMP_LIBS="-L$try -lsnmp -lcrypto",
303                   SNMP_LIBS=)
304       if test "x$SNMP_LIBS" != "x"; then
305         break;
306       fi
307 dnl   #
308 dnl   #  That didn't work.  Try adding the '-lkstat' line.
309 dnl   #  Some SNMP libraries are linked against Kernel Statistics,
310 dnl   #  in particular, Solaris 9...
311 dnl   #
312       LIBS="$old_LIBS -L$try -lsnmp -lcrypto -lkstat"
313       AC_TRY_LINK([extern char snmp_build_var_op();],
314                   [ snmp_build_var_op()],
315                   SNMP_LIBS="-L$try -lsnmp -lcrypto -lkstat",
316                   SNMP_LIBS=)
317       if test "x$SNMP_LIBS" != "x"; then
318         break;
319       fi
320     done
321   fi
322   LIBS="$old_LIBS"
323
324   dnl #
325   dnl #  If one or the other isn't found, disable them both..
326   dnl #  If both are found, enable them both.
327   dnl #
328   CFLAGS="$old_CFLAGS"
329   if test "x$SNMP_LIBS" = "x"; then
330     AC_MSG_RESULT(no)
331     SNMP_INCLUDE=
332   else
333     AC_MSG_RESULT(yes)
334     AC_DEFINE(WITH_SNMP, [], [Include SNMP subagent])
335     AC_DEFINE(HAVE_LIBSNMP, [], [Define if you have the snmp library (-lsnmp).])
336   fi
337 fi
338 ])
339
340
341 dnl #
342 dnl #  Locate the directory in which a particular file is found.
343 dnl #
344 dnl #  Usage: FR_LOCATE_DIR(MYSQLLIB_DIR, libmysqlclient.a)
345 dnl #
346 dnl #    Defines the variable MYSQLLIB_DIR to be the directory(s) in
347 dnl #    which the file libmysqlclient.a is to be found.
348 dnl #
349 dnl #
350 AC_DEFUN([FR_LOCATE_DIR],
351 [
352 dnl # If we have the program 'locate', then the problem of finding a
353 dnl # particular file becomes MUCH easier.
354 dnl #
355
356 dnl #
357 dnl #  No 'locate' defined, do NOT do anything.
358 dnl #
359 if test "x$LOCATE" != "x"; then
360   dnl #
361   dnl #  Root through a series of directories, looking for the given file.
362   dnl #
363   DIRS=
364   file=$2
365
366   for x in `${LOCATE} $file 2>/dev/null`; do
367     dnl #
368     dnl #  When asked for 'foo', locate will also find 'foo_bar', which we
369     dnl #  don't want.  We want that EXACT filename.
370     dnl #
371     dnl #  We ALSO want to be able to look for files like 'mysql/mysql.h',
372     dnl #  and properly match them, too.  So we try to strip off the last
373     dnl #  part of the filename, using the name of the file we're looking
374     dnl #  for.  If we CANNOT strip it off, then the name will be unchanged.
375     dnl #
376     base=`echo $x | sed "s%/${file}%%"`
377     if test "x$x" = "x$base"; then
378       continue;
379     fi
380
381     dir=`${DIRNAME} $x 2>/dev/null`
382     dnl #
383     dnl #  Exclude a number of directories.
384     dnl #
385     exclude=`echo ${dir} | ${GREP} /home`
386     if test "x$exclude" != "x"; then
387       continue
388     fi
389
390     dnl #
391     dnl #  OK, we have an exact match.  Let's be sure that we only find ONE
392     dnl #  matching directory.
393     dnl #
394     already=`echo \$$1 ${DIRS} | ${GREP} ${dir}`
395     if test "x$already" = "x"; then
396       DIRS="$DIRS $dir"
397     fi
398   done
399 fi
400
401 dnl #
402 dnl #  And remember the directory in which we found the file.
403 dnl #
404 eval "$1=\"\$$1 $DIRS\""
405 ])
406
407
408 dnl #######################################################################
409 dnl #
410 dnl #  Look for a library in a number of places.
411 dnl #
412 AC_DEFUN([FR_SMART_CHECK_LIB], [
413
414 sm_lib_safe=`echo "$1" | sed 'y%./+-%__p_%'`
415 sm_func_safe=`echo "$2" | sed 'y%./+-%__p_%'`
416 AC_MSG_CHECKING([for $2 in -l$1])
417
418 smart_lib=
419 smart_lib_dir=
420
421 dnl #
422 dnl #  Try to link it first, using the default libs && library paths
423 dnl #
424   old_LIBS="$LIBS"
425   LIBS="$LIBS -l$1"
426   AC_TRY_LINK([extern char $2();],
427               [ $2()],
428               smart_lib="-l$1")
429
430   if test "x$smart_lib" = "x"; then
431     FR_LOCATE_DIR(smart_lib_dir,[lib$1${libltdl_cv_shlibext}])
432     FR_LOCATE_DIR(smart_lib_dir,[lib$1.a])
433
434     for try in $smart_try_dir $smart_lib_dir /usr/local/lib/ /opt/lib; do
435       LIBS="$old_LIBS -L$try -l$1"
436
437       AC_TRY_LINK([extern char $2();],
438                   [ $2()],
439                   smart_lib="-L$try -l$1")
440       if test "x$smart_lib" != "x"; then
441         break;
442       fi
443     done
444     LIBS="$old_LIBS"
445   fi
446
447   dnl #
448   dnl #  Found it, set the appropriate variable.
449   dnl #
450   if test "x$smart_lib" != "x"; then
451     AC_MSG_RESULT(yes)
452     eval "ac_cv_lib_${sm_lib_safe}_${sm_func_safe}=yes"
453     LIBS="$old_LIBS $smart_lib"
454     SMART_LIBS="$SMART_LIBS $smart_lib"
455   else
456     AC_MSG_RESULT(no) 
457 fi
458 ])
459
460 dnl #######################################################################
461 dnl #
462 dnl #  Look for a header file in a number of places.
463 dnl #
464 dnl #  FR_SMART_CHECK_INCLUDE(foo.h, [ #include <other.h> ])
465 dnl #
466 AC_DEFUN([FR_SMART_CHECK_INCLUDE], [
467
468 ac_safe=`echo "$1" | sed 'y%./+-%__pm%'`
469 AC_MSG_CHECKING([for $1])
470
471 smart_include=
472 smart_include_dir=
473
474 dnl #
475 dnl #  Try to link it first, using the default includes
476 dnl #
477   old_CFLAGS="$CFLAGS"
478   AC_TRY_COMPILE([$2
479                   #include <$1>],
480                  [ int a = 1;],
481                  smart_include=" ",
482                  smart_include=)
483
484   if test "x$smart_include" = "x"; then
485     FR_LOCATE_DIR(smart_include_dir,$1)
486
487     for try in $smart_try_dir $smart_include_dir /usr/local/include/ /opt/include; do
488       CFLAGS="$old_CFLAGS -I$try"
489
490       AC_TRY_COMPILE([$2
491                        #include <$1>],
492                      [ int a = 1;],
493                      smart_include="-I$try",
494                      smart_include=)
495
496       if test "x$smart_include" != "x"; then
497         break;
498       fi
499     done
500     CFLAGS="$old_CFLAGS"
501   fi
502
503   dnl #
504   dnl #  Found it, set the appropriate variable.
505   dnl #
506   if test "x$smart_include" != "x"; then
507     AC_MSG_RESULT(yes)
508     eval "ac_cv_header_$ac_safe=yes"
509     CFLAGS="$old_CFLAGS $smart_include"
510     SMART_CFLAGS="$SMART_CFLAGS $smart_include"
511   else
512     AC_MSG_RESULT(no) 
513 fi
514 ])
515
516 dnl #######################################################################
517 dnl #
518 dnl #  Look for a header file in a number of places.
519 dnl #
520 dnl #  Usage:  FR_CHECK_STRUCT_HAS_MEMBER([#include <foo.h>], [struct foo], member)
521 dnl #  If the member is defined, then the variable
522 dnl #     ac_cv_type_struct_foo_has_member is set to 'yes'
523 dnl #
524 AC_DEFUN([FR_CHECK_STRUCT_HAS_MEMBER], [
525   AC_MSG_CHECKING([for $3 in $2])
526
527 dnl BASED on 'offsetof':
528 dnl #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
529 dnl
530
531   AC_TRY_COMPILE([
532 $1
533 #ifndef offsetof
534 #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
535 #endif
536 ],
537                  [ int foo = offsetof($2, $3) ],
538                  has_element=" ",
539                  has_element=)
540
541   ac_safe_type=`echo "$2" | sed 'y% %_%'`
542   if test "x$has_element" != "x"; then
543     AC_MSG_RESULT(yes)
544     eval "ac_cv_type_${ac_safe_type}_has_$3=yes"
545   else
546     AC_MSG_RESULT(no) 
547     eval "ac_cv_type_${ac_safe_type}_has_$3="
548  fi
549 ])
550
551 AC_INCLUDE(aclocal.m4)