ttls: return channel bindings on half round trip success
[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 #  Locate the directory in which a particular file is found.
116 dnl #
117 dnl #  Usage: FR_LOCATE_DIR(MYSQLLIB_DIR, libmysqlclient.a)
118 dnl #
119 dnl #    Defines the variable MYSQLLIB_DIR to be the directory(s) in
120 dnl #    which the file libmysqlclient.a is to be found.
121 dnl #
122 dnl #
123 AC_DEFUN([FR_LOCATE_DIR],
124 [
125 dnl # If we have the program 'locate', then the problem of finding a
126 dnl # particular file becomes MUCH easier.
127 dnl #
128
129 dnl #
130 dnl #  No 'locate' defined, do NOT do anything.
131 dnl #
132 if test "x$LOCATE" != "x"; then
133   dnl #
134   dnl #  Root through a series of directories, looking for the given file.
135   dnl #
136   DIRS=
137   file=$2
138
139   for x in `${LOCATE} $file 2>/dev/null`; do
140     dnl #
141     dnl #  When asked for 'foo', locate will also find 'foo_bar', which we
142     dnl #  don't want.  We want that EXACT filename.
143     dnl #
144     dnl #  We ALSO want to be able to look for files like 'mysql/mysql.h',
145     dnl #  and properly match them, too.  So we try to strip off the last
146     dnl #  part of the filename, using the name of the file we're looking
147     dnl #  for.  If we CANNOT strip it off, then the name will be unchanged.
148     dnl #
149     base=`echo $x | sed "s%/${file}%%"`
150     if test "x$x" = "x$base"; then
151       continue;
152     fi
153
154     dir=`${DIRNAME} $x 2>/dev/null`
155     dnl #
156     dnl #  Exclude a number of directories.
157     dnl #
158     exclude=`echo ${dir} | ${GREP} /home`
159     if test "x$exclude" != "x"; then
160       continue
161     fi
162
163     dnl #
164     dnl #  OK, we have an exact match.  Let's be sure that we only find ONE
165     dnl #  matching directory.
166     dnl #
167     already=`echo \$$1 ${DIRS} | ${GREP} ${dir}`
168     if test "x$already" = "x"; then
169       DIRS="$DIRS $dir"
170     fi
171   done
172 fi
173
174 dnl #
175 dnl #  And remember the directory in which we found the file.
176 dnl #
177 eval "$1=\"\$$1 $DIRS\""
178 ])
179
180
181 dnl #######################################################################
182 dnl #
183 dnl #  Look for a library in a number of places.
184 dnl #
185 dnl #  FR_SMART_CHECK_LIB(library, function)
186 dnl #
187 AC_DEFUN([FR_SMART_CHECK_LIB], [
188
189 sm_lib_safe=`echo "$1" | sed 'y%./+-%__p_%'`
190 sm_func_safe=`echo "$2" | sed 'y%./+-%__p_%'`
191
192 old_LIBS="$LIBS"
193 smart_lib=
194 smart_lib_dir=
195
196 dnl #
197 dnl #  Try first any user-specified directory, otherwise we may pick up
198 dnl #  the wrong version.
199 dnl #
200 if test "x$smart_try_dir" != "x"; then
201   for try in $smart_try_dir; do
202     AC_MSG_CHECKING([for $2 in -l$1 in $try])
203     LIBS="-L$try -l$1 $old_LIBS -Wl,-rpath,$try"
204     AC_TRY_LINK([extern char $2();],
205                 [$2()],
206                 [
207                  smart_lib="-L$try -l$1 -Wl,-rpath,$try"
208                  AC_MSG_RESULT(yes)
209                  break
210                 ],
211                 [AC_MSG_RESULT(no)])
212   done
213   LIBS="$old_LIBS"
214 fi
215
216 dnl #
217 dnl #  Try using the default library path
218 dnl #
219 if test "x$smart_lib" = "x"; then
220   AC_MSG_CHECKING([for $2 in -l$1])
221   LIBS="-l$1 $old_LIBS"
222   AC_TRY_LINK([extern char $2();],
223               [$2()],
224               [
225                 smart_lib="-l$1"
226                 AC_MSG_RESULT(yes)
227               ],
228               [AC_MSG_RESULT(no)])
229   LIBS="$old_LIBS"
230 fi
231
232 dnl #
233 dnl #  Try to guess possible locations.
234 dnl #
235 if test "x$smart_lib" = "x"; then
236   FR_LOCATE_DIR(smart_lib_dir,[lib$1${libltdl_cv_shlibext}])
237   FR_LOCATE_DIR(smart_lib_dir,[lib$1.a])
238
239   for try in $smart_lib_dir /usr/local/lib /opt/lib; do
240     AC_MSG_CHECKING([for $2 in -l$1 in $try])
241     LIBS="-L$try -rpath$try -l$1 $old_LIBS -Wl,-rpath,$try"
242     AC_TRY_LINK([extern char $2();],
243                 [$2()],
244                 [
245                   smart_lib="-L$try -l$1 -Wl,-rpath,$try"
246                   AC_MSG_RESULT(yes)
247                   break
248                 ],
249                 [AC_MSG_RESULT(no)])
250   done
251   LIBS="$old_LIBS"
252 fi
253
254 dnl #
255 dnl #  Found it, set the appropriate variable.
256 dnl #
257 if test "x$smart_lib" != "x"; then
258   eval "ac_cv_lib_${sm_lib_safe}_${sm_func_safe}=yes"
259   LIBS="$smart_lib $old_LIBS"
260   SMART_LIBS="$smart_lib $SMART_LIBS"
261 fi
262 ])
263
264 dnl #######################################################################
265 dnl #
266 dnl #  Look for a header file in a number of places.
267 dnl #
268 dnl #  FR_SMART_CHECK_INCLUDE(foo.h, [ #include <other.h> ])
269 dnl #
270 AC_DEFUN([FR_SMART_CHECK_INCLUDE], [
271
272 ac_safe=`echo "$1" | sed 'y%./+-%__pm%'`
273 old_CFLAGS="$CFLAGS"
274 smart_include=
275 smart_include_dir=
276
277 dnl #
278 dnl #  Try first any user-specified directory, otherwise we may pick up
279 dnl #  the wrong version.
280 dnl #
281 if test "x$smart_try_dir" != "x"; then
282   for try in $smart_try_dir; do
283     AC_MSG_CHECKING([for $1 in $try])
284     CFLAGS="$old_CFLAGS -I$try"
285     AC_TRY_COMPILE([$2
286                     #include <$1>],
287                    [int a = 1;],
288                    [
289                      smart_include="-I$try"
290                      AC_MSG_RESULT(yes)
291                      break
292                    ],
293                    [
294                      smart_include=
295                      AC_MSG_RESULT(no)
296                    ])
297   done
298   CFLAGS="$old_CFLAGS"
299 fi
300
301 dnl #
302 dnl #  Try using the default includes.
303 dnl #
304 if test "x$smart_include" = "x"; then
305   AC_MSG_CHECKING([for $1])
306   AC_TRY_COMPILE([$2
307                   #include <$1>],
308                  [int a = 1;],
309                  [
310                    smart_include=" "
311                    AC_MSG_RESULT(yes)
312                    break
313                  ],
314                  [
315                    smart_include=
316                    AC_MSG_RESULT(no)
317                  ])
318 fi
319
320 dnl #
321 dnl #  Try to guess possible locations.
322 dnl #
323 if test "x$smart_include" = "x"; then
324   FR_LOCATE_DIR(smart_include_dir,$1)
325   for try in $smart_include_dir /usr/local/include /opt/include; do
326     AC_MSG_CHECKING([for $1 in $try])
327     CFLAGS="$old_CFLAGS -I$try"
328     AC_TRY_COMPILE([$2
329                     #include <$1>],
330                    [int a = 1;],
331                    [
332                      smart_include="-I$try"
333                      AC_MSG_RESULT(yes)
334                      break
335                    ],
336                    [
337                      smart_include=
338                      AC_MSG_RESULT(no)
339                    ])
340   done
341   CFLAGS="$old_CFLAGS"
342 fi
343
344 dnl #
345 dnl #  Found it, set the appropriate variable.
346 dnl #
347 if test "x$smart_include" != "x"; then
348   eval "ac_cv_header_$ac_safe=yes"
349   CFLAGS="$old_CFLAGS $smart_include"
350   SMART_CFLAGS="$SMART_CFLAGS $smart_include"
351 fi
352 ])
353
354 dnl #######################################################################
355 dnl #
356 dnl #  Look for a header file in a number of places.
357 dnl #
358 dnl #  Usage:  FR_CHECK_STRUCT_HAS_MEMBER([#include <foo.h>], [struct foo], member)
359 dnl #  If the member is defined, then the variable
360 dnl #     ac_cv_type_struct_foo_has_member is set to 'yes'
361 dnl #
362 AC_DEFUN([FR_CHECK_STRUCT_HAS_MEMBER], [
363   AC_MSG_CHECKING([for $3 in $2])
364
365 dnl BASED on 'offsetof':
366 dnl #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
367 dnl
368
369   AC_TRY_COMPILE([
370 $1
371 #ifdef HAVE_STDDEF_H
372 #include <stddef.h>
373 #endif
374 #ifndef offsetof
375 #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
376 #endif
377 ],
378                  [ int foo = offsetof($2, $3) ],
379                  has_element=" ",
380                  has_element=)
381
382   ac_safe_type=`echo "$2" | sed 'y% %_%'`
383   if test "x$has_element" != "x"; then
384     AC_MSG_RESULT(yes)
385     eval "ac_cv_type_${ac_safe_type}_has_$3=yes"
386   else
387     AC_MSG_RESULT(no) 
388     eval "ac_cv_type_${ac_safe_type}_has_$3="
389  fi
390 ])
391
392 dnl Autoconf 2.61 breaks the support for chained configure scripts
393 dnl in combination with config.cache
394 m4_pushdef([AC_OUTPUT],
395 [
396   unset ac_cv_env_LIBS_set
397   unset ac_cv_env_LIBS_value
398   m4_popdef([AC_OUTPUT])
399   AC_OUTPUT([$1],[$2],[$3])
400 ])
401
402
403 #  See if the compilation works with __thread, for thread-local storage
404 #
405 AC_DEFUN([FR_TLS],
406 [
407     AC_MSG_CHECKING(for TLS)
408     AC_RUN_IFELSE([AC_LANG_SOURCE([[ static __thread int val; int main(int argc, char *argv[]) { return val = argc; } ]])],[have_tls=yes],[have_tls=no],[have_tls=no ])
409     AC_MSG_RESULT($have_tls)
410     if test "$have_tls" = "yes"; then
411         AC_DEFINE([HAVE_THREAD_TLS],[1],[Define if the compiler supports __thread])
412     fi
413 ])
414
415
416 AC_DEFUN([VL_LIB_READLINE], [
417   AC_CACHE_CHECK([for a readline compatible library],
418                  vl_cv_lib_readline, [
419     ORIG_LIBS="$LIBS"
420     for readline_lib in readline edit editline; do
421       for termcap_lib in "" termcap curses ncurses; do
422         if test -z "$termcap_lib"; then
423           TRY_LIB="-l$readline_lib"
424         else
425           TRY_LIB="-l$readline_lib -l$termcap_lib"
426         fi
427         LIBS="$ORIG_LIBS $TRY_LIB"
428         AC_TRY_LINK_FUNC(readline, vl_cv_lib_readline="$TRY_LIB")
429         if test -n "$vl_cv_lib_readline"; then
430           LIBREADLINE="$TRY_LIB"
431           break
432         fi
433       done
434       if test -n "$vl_cv_lib_readline"; then
435         break
436       fi
437     done
438     if test -z "$vl_cv_lib_readline"; then
439       vl_cv_lib_readline="no"
440       LIBS="$ORIG_LIBS"
441     fi
442   ])
443
444   if test "$vl_cv_lib_readline" != "no"; then
445     AC_DEFINE(HAVE_LIBREADLINE, 1,
446               [Define if you have a readline compatible library])
447     AC_CHECK_HEADERS(readline.h readline/readline.h)
448     AC_CACHE_CHECK([whether readline supports history],
449                    [vl_cv_lib_readline_history], [
450       vl_cv_lib_readline_history="no"
451       AC_TRY_LINK_FUNC([add_history], [vl_cv_lib_readline_history="yes"])
452     ])
453     if test "$vl_cv_lib_readline_history" = "yes"; then
454       AC_DEFINE(HAVE_READLINE_HISTORY, 1,
455                 [Define if your readline library has \`add_history'])
456       AC_CHECK_HEADERS(history.h readline/history.h)
457     fi
458   fi
459   AC_SUBST(LIBREADLINE)
460 ])dnl
461
462 AC_INCLUDE(aclocal.m4)