xref: /freebsd/crypto/openssh/aclocal.m4 (revision 9a14aa017b21c292740c00ee098195cd46642730)
1dnl $Id: aclocal.m4,v 1.8 2011/05/20 01:45:25 djm Exp $
2dnl
3dnl OpenSSH-specific autoconf macros
4dnl
5
6dnl OSSH_CHECK_CFLAG_COMPILE(check_flag[, define_flag])
7dnl Check that $CC accepts a flag 'check_flag'. If it is supported append
8dnl 'define_flag' to $CFLAGS. If 'define_flag' is not specified, then append
9dnl 'check_flag'.
10AC_DEFUN([OSSH_CHECK_CFLAG_COMPILE], [{
11	AC_MSG_CHECKING([if $CC supports $1])
12	saved_CFLAGS="$CFLAGS"
13	CFLAGS="$CFLAGS $1"
14	_define_flag="$2"
15	test "x$_define_flag" = "x" && _define_flag="$1"
16	AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int main(void) { return 0; }]])],
17		[ AC_MSG_RESULT([yes])
18		  CFLAGS="$saved_CFLAGS $_define_flag"],
19		[ AC_MSG_RESULT([no])
20		  CFLAGS="$saved_CFLAGS" ]
21	)
22}])
23
24
25dnl OSSH_CHECK_HEADER_FOR_FIELD(field, header, symbol)
26dnl Does AC_EGREP_HEADER on 'header' for the string 'field'
27dnl If found, set 'symbol' to be defined. Cache the result.
28dnl TODO: This is not foolproof, better to compile and read from there
29AC_DEFUN(OSSH_CHECK_HEADER_FOR_FIELD, [
30# look for field '$1' in header '$2'
31	dnl This strips characters illegal to m4 from the header filename
32	ossh_safe=`echo "$2" | sed 'y%./+-%__p_%'`
33	dnl
34	ossh_varname="ossh_cv_$ossh_safe""_has_"$1
35	AC_MSG_CHECKING(for $1 field in $2)
36	AC_CACHE_VAL($ossh_varname, [
37		AC_EGREP_HEADER($1, $2, [ dnl
38			eval "$ossh_varname=yes" dnl
39		], [ dnl
40			eval "$ossh_varname=no" dnl
41		]) dnl
42	])
43	ossh_result=`eval 'echo $'"$ossh_varname"`
44	if test -n "`echo $ossh_varname`"; then
45		AC_MSG_RESULT($ossh_result)
46		if test "x$ossh_result" = "xyes"; then
47			AC_DEFINE($3, 1, [Define if you have $1 in $2])
48		fi
49	else
50		AC_MSG_RESULT(no)
51	fi
52])
53
54dnl Check for socklen_t: historically on BSD it is an int, and in
55dnl POSIX 1g it is a type of its own, but some platforms use different
56dnl types for the argument to getsockopt, getpeername, etc.  So we
57dnl have to test to find something that will work.
58AC_DEFUN([TYPE_SOCKLEN_T],
59[
60   AC_CHECK_TYPE([socklen_t], ,[
61      AC_MSG_CHECKING([for socklen_t equivalent])
62      AC_CACHE_VAL([curl_cv_socklen_t_equiv],
63      [
64	 # Systems have either "struct sockaddr *" or
65	 # "void *" as the second argument to getpeername
66	 curl_cv_socklen_t_equiv=
67	 for arg2 in "struct sockaddr" void; do
68	    for t in int size_t unsigned long "unsigned long"; do
69	       AC_TRY_COMPILE([
70		  #include <sys/types.h>
71		  #include <sys/socket.h>
72
73		  int getpeername (int, $arg2 *, $t *);
74	       ],[
75		  $t len;
76		  getpeername(0,0,&len);
77	       ],[
78		  curl_cv_socklen_t_equiv="$t"
79		  break
80	       ])
81	    done
82	 done
83
84	 if test "x$curl_cv_socklen_t_equiv" = x; then
85	    AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
86	 fi
87      ])
88      AC_MSG_RESULT($curl_cv_socklen_t_equiv)
89      AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
90			[type to use in place of socklen_t if not defined])],
91      [#include <sys/types.h>
92#include <sys/socket.h>])
93])
94
95