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