xref: /freebsd/crypto/openssh/aclocal.m4 (revision e146993e33182e13df79b5a957f2734f663fd836)
1*e146993eSDag-Erling Smørgravdnl $Id: aclocal.m4,v 1.8 2011/05/20 01:45:25 djm Exp $
283d2307dSDag-Erling Smørgravdnl
383d2307dSDag-Erling Smørgravdnl OpenSSH-specific autoconf macros
483d2307dSDag-Erling Smørgravdnl
583d2307dSDag-Erling Smørgrav
6*e146993eSDag-Erling Smørgravdnl OSSH_CHECK_CFLAG_COMPILE(check_flag[, define_flag])
7*e146993eSDag-Erling Smørgravdnl Check that $CC accepts a flag 'check_flag'. If it is supported append
8*e146993eSDag-Erling Smørgravdnl 'define_flag' to $CFLAGS. If 'define_flag' is not specified, then append
9*e146993eSDag-Erling Smørgravdnl 'check_flag'.
10*e146993eSDag-Erling SmørgravAC_DEFUN([OSSH_CHECK_CFLAG_COMPILE], [{
11*e146993eSDag-Erling Smørgrav	AC_MSG_CHECKING([if $CC supports $1])
12*e146993eSDag-Erling Smørgrav	saved_CFLAGS="$CFLAGS"
13*e146993eSDag-Erling Smørgrav	CFLAGS="$CFLAGS $1"
14*e146993eSDag-Erling Smørgrav	_define_flag="$2"
15*e146993eSDag-Erling Smørgrav	test "x$_define_flag" = "x" && _define_flag="$1"
16*e146993eSDag-Erling Smørgrav	AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int main(void) { return 0; }]])],
17*e146993eSDag-Erling Smørgrav		[ AC_MSG_RESULT([yes])
18*e146993eSDag-Erling Smørgrav		  CFLAGS="$saved_CFLAGS $_define_flag"],
19*e146993eSDag-Erling Smørgrav		[ AC_MSG_RESULT([no])
20*e146993eSDag-Erling Smørgrav		  CFLAGS="$saved_CFLAGS" ]
21*e146993eSDag-Erling Smørgrav	)
22*e146993eSDag-Erling Smørgrav}])
23*e146993eSDag-Erling Smørgrav
2483d2307dSDag-Erling Smørgrav
2583d2307dSDag-Erling Smørgravdnl OSSH_CHECK_HEADER_FOR_FIELD(field, header, symbol)
2683d2307dSDag-Erling Smørgravdnl Does AC_EGREP_HEADER on 'header' for the string 'field'
2783d2307dSDag-Erling Smørgravdnl If found, set 'symbol' to be defined. Cache the result.
2883d2307dSDag-Erling Smørgravdnl TODO: This is not foolproof, better to compile and read from there
2983d2307dSDag-Erling SmørgravAC_DEFUN(OSSH_CHECK_HEADER_FOR_FIELD, [
3083d2307dSDag-Erling Smørgrav# look for field '$1' in header '$2'
3183d2307dSDag-Erling Smørgrav	dnl This strips characters illegal to m4 from the header filename
3283d2307dSDag-Erling Smørgrav	ossh_safe=`echo "$2" | sed 'y%./+-%__p_%'`
3383d2307dSDag-Erling Smørgrav	dnl
3483d2307dSDag-Erling Smørgrav	ossh_varname="ossh_cv_$ossh_safe""_has_"$1
3583d2307dSDag-Erling Smørgrav	AC_MSG_CHECKING(for $1 field in $2)
3683d2307dSDag-Erling Smørgrav	AC_CACHE_VAL($ossh_varname, [
3783d2307dSDag-Erling Smørgrav		AC_EGREP_HEADER($1, $2, [ dnl
3883d2307dSDag-Erling Smørgrav			eval "$ossh_varname=yes" dnl
3983d2307dSDag-Erling Smørgrav		], [ dnl
4083d2307dSDag-Erling Smørgrav			eval "$ossh_varname=no" dnl
4183d2307dSDag-Erling Smørgrav		]) dnl
4283d2307dSDag-Erling Smørgrav	])
4383d2307dSDag-Erling Smørgrav	ossh_result=`eval 'echo $'"$ossh_varname"`
4483d2307dSDag-Erling Smørgrav	if test -n "`echo $ossh_varname`"; then
4583d2307dSDag-Erling Smørgrav		AC_MSG_RESULT($ossh_result)
4683d2307dSDag-Erling Smørgrav		if test "x$ossh_result" = "xyes"; then
47021d409fSDag-Erling Smørgrav			AC_DEFINE($3, 1, [Define if you have $1 in $2])
4883d2307dSDag-Erling Smørgrav		fi
4983d2307dSDag-Erling Smørgrav	else
5083d2307dSDag-Erling Smørgrav		AC_MSG_RESULT(no)
5183d2307dSDag-Erling Smørgrav	fi
5283d2307dSDag-Erling Smørgrav])
5383d2307dSDag-Erling Smørgrav
5483d2307dSDag-Erling Smørgravdnl Check for socklen_t: historically on BSD it is an int, and in
5583d2307dSDag-Erling Smørgravdnl POSIX 1g it is a type of its own, but some platforms use different
5683d2307dSDag-Erling Smørgravdnl types for the argument to getsockopt, getpeername, etc.  So we
5783d2307dSDag-Erling Smørgravdnl have to test to find something that will work.
5883d2307dSDag-Erling SmørgravAC_DEFUN([TYPE_SOCKLEN_T],
5983d2307dSDag-Erling Smørgrav[
6083d2307dSDag-Erling Smørgrav   AC_CHECK_TYPE([socklen_t], ,[
6183d2307dSDag-Erling Smørgrav      AC_MSG_CHECKING([for socklen_t equivalent])
6283d2307dSDag-Erling Smørgrav      AC_CACHE_VAL([curl_cv_socklen_t_equiv],
6383d2307dSDag-Erling Smørgrav      [
6483d2307dSDag-Erling Smørgrav	 # Systems have either "struct sockaddr *" or
6583d2307dSDag-Erling Smørgrav	 # "void *" as the second argument to getpeername
6683d2307dSDag-Erling Smørgrav	 curl_cv_socklen_t_equiv=
6783d2307dSDag-Erling Smørgrav	 for arg2 in "struct sockaddr" void; do
6883d2307dSDag-Erling Smørgrav	    for t in int size_t unsigned long "unsigned long"; do
6983d2307dSDag-Erling Smørgrav	       AC_TRY_COMPILE([
7083d2307dSDag-Erling Smørgrav		  #include <sys/types.h>
7183d2307dSDag-Erling Smørgrav		  #include <sys/socket.h>
7283d2307dSDag-Erling Smørgrav
7383d2307dSDag-Erling Smørgrav		  int getpeername (int, $arg2 *, $t *);
7483d2307dSDag-Erling Smørgrav	       ],[
7583d2307dSDag-Erling Smørgrav		  $t len;
7683d2307dSDag-Erling Smørgrav		  getpeername(0,0,&len);
7783d2307dSDag-Erling Smørgrav	       ],[
7883d2307dSDag-Erling Smørgrav		  curl_cv_socklen_t_equiv="$t"
7983d2307dSDag-Erling Smørgrav		  break
8083d2307dSDag-Erling Smørgrav	       ])
8183d2307dSDag-Erling Smørgrav	    done
8283d2307dSDag-Erling Smørgrav	 done
8383d2307dSDag-Erling Smørgrav
8483d2307dSDag-Erling Smørgrav	 if test "x$curl_cv_socklen_t_equiv" = x; then
8583d2307dSDag-Erling Smørgrav	    AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
8683d2307dSDag-Erling Smørgrav	 fi
8783d2307dSDag-Erling Smørgrav      ])
8883d2307dSDag-Erling Smørgrav      AC_MSG_RESULT($curl_cv_socklen_t_equiv)
8983d2307dSDag-Erling Smørgrav      AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
9083d2307dSDag-Erling Smørgrav			[type to use in place of socklen_t if not defined])],
9183d2307dSDag-Erling Smørgrav      [#include <sys/types.h>
9283d2307dSDag-Erling Smørgrav#include <sys/socket.h>])
9383d2307dSDag-Erling Smørgrav])
9483d2307dSDag-Erling Smørgrav
95