1*f7167e0eSDag-Erling Smørgravdnl $Id: aclocal.m4,v 1.13 2014/01/22 10:30:12 djm 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], [{ 11*f7167e0eSDag-Erling Smørgrav AC_MSG_CHECKING([if $CC supports compile flag $1]) 12e146993eSDag-Erling Smørgrav saved_CFLAGS="$CFLAGS" 13*f7167e0eSDag-Erling Smørgrav CFLAGS="$CFLAGS $WERROR $1" 14e146993eSDag-Erling Smørgrav _define_flag="$2" 15e146993eSDag-Erling Smørgrav test "x$_define_flag" = "x" && _define_flag="$1" 16*f7167e0eSDag-Erling Smørgrav AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 17*f7167e0eSDag-Erling Smørgrav#include <stdlib.h> 18*f7167e0eSDag-Erling Smørgrav#include <stdio.h> 19*f7167e0eSDag-Erling Smørgravint main(int argc, char **argv) { 20*f7167e0eSDag-Erling Smørgrav /* Some math to catch -ftrapv problems in the toolchain */ 21*f7167e0eSDag-Erling Smørgrav int i = 123 * argc, j = 456 + argc, k = 789 - argc; 22*f7167e0eSDag-Erling Smørgrav float l = i * 2.1; 23*f7167e0eSDag-Erling Smørgrav double m = l / 0.5; 24*f7167e0eSDag-Erling Smørgrav long long int n = argc * 12345LL, o = 12345LL * (long long int)argc; 25*f7167e0eSDag-Erling Smørgrav printf("%d %d %d %f %f %lld %lld\n", i, j, k, l, m, n, o); 26*f7167e0eSDag-Erling Smørgrav exit(0); 27*f7167e0eSDag-Erling Smørgrav} 28*f7167e0eSDag-Erling Smørgrav ]])], 29e4a9863fSDag-Erling Smørgrav [ 30e4a9863fSDag-Erling Smørgravif `grep -i "unrecognized option" conftest.err >/dev/null` 31e4a9863fSDag-Erling Smørgravthen 32e4a9863fSDag-Erling Smørgrav AC_MSG_RESULT([no]) 33e4a9863fSDag-Erling Smørgrav CFLAGS="$saved_CFLAGS" 34e4a9863fSDag-Erling Smørgravelse 35e4a9863fSDag-Erling Smørgrav AC_MSG_RESULT([yes]) 36e4a9863fSDag-Erling Smørgrav CFLAGS="$saved_CFLAGS $_define_flag" 37e4a9863fSDag-Erling Smørgravfi], 38e146993eSDag-Erling Smørgrav [ AC_MSG_RESULT([no]) 39e146993eSDag-Erling Smørgrav CFLAGS="$saved_CFLAGS" ] 40e146993eSDag-Erling Smørgrav ) 41e146993eSDag-Erling Smørgrav}]) 42e146993eSDag-Erling Smørgrav 43*f7167e0eSDag-Erling Smørgravdnl OSSH_CHECK_CFLAG_LINK(check_flag[, define_flag]) 44*f7167e0eSDag-Erling Smørgravdnl Check that $CC accepts a flag 'check_flag'. If it is supported append 45*f7167e0eSDag-Erling Smørgravdnl 'define_flag' to $CFLAGS. If 'define_flag' is not specified, then append 46*f7167e0eSDag-Erling Smørgravdnl 'check_flag'. 47*f7167e0eSDag-Erling SmørgravAC_DEFUN([OSSH_CHECK_CFLAG_LINK], [{ 48*f7167e0eSDag-Erling Smørgrav AC_MSG_CHECKING([if $CC supports compile flag $1 and linking succeeds]) 49*f7167e0eSDag-Erling Smørgrav saved_CFLAGS="$CFLAGS" 50*f7167e0eSDag-Erling Smørgrav CFLAGS="$CFLAGS $WERROR $1" 51*f7167e0eSDag-Erling Smørgrav _define_flag="$2" 52*f7167e0eSDag-Erling Smørgrav test "x$_define_flag" = "x" && _define_flag="$1" 53*f7167e0eSDag-Erling Smørgrav AC_LINK_IFELSE([AC_LANG_SOURCE([[ 54*f7167e0eSDag-Erling Smørgrav#include <stdlib.h> 55*f7167e0eSDag-Erling Smørgrav#include <stdio.h> 56*f7167e0eSDag-Erling Smørgravint main(int argc, char **argv) { 57*f7167e0eSDag-Erling Smørgrav /* Some math to catch -ftrapv problems in the toolchain */ 58*f7167e0eSDag-Erling Smørgrav int i = 123 * argc, j = 456 + argc, k = 789 - argc; 59*f7167e0eSDag-Erling Smørgrav float l = i * 2.1; 60*f7167e0eSDag-Erling Smørgrav double m = l / 0.5; 61*f7167e0eSDag-Erling Smørgrav long long int n = argc * 12345LL, o = 12345LL * (long long int)argc; 62*f7167e0eSDag-Erling Smørgrav printf("%d %d %d %f %f %lld %lld\n", i, j, k, l, m, n, o); 63*f7167e0eSDag-Erling Smørgrav exit(0); 64*f7167e0eSDag-Erling Smørgrav} 65*f7167e0eSDag-Erling Smørgrav ]])], 66*f7167e0eSDag-Erling Smørgrav [ 67*f7167e0eSDag-Erling Smørgravif `grep -i "unrecognized option" conftest.err >/dev/null` 68*f7167e0eSDag-Erling Smørgravthen 69*f7167e0eSDag-Erling Smørgrav AC_MSG_RESULT([no]) 70*f7167e0eSDag-Erling Smørgrav CFLAGS="$saved_CFLAGS" 71*f7167e0eSDag-Erling Smørgravelse 72*f7167e0eSDag-Erling Smørgrav AC_MSG_RESULT([yes]) 73*f7167e0eSDag-Erling Smørgrav CFLAGS="$saved_CFLAGS $_define_flag" 74*f7167e0eSDag-Erling Smørgravfi], 75*f7167e0eSDag-Erling Smørgrav [ AC_MSG_RESULT([no]) 76*f7167e0eSDag-Erling Smørgrav CFLAGS="$saved_CFLAGS" ] 77*f7167e0eSDag-Erling Smørgrav ) 78*f7167e0eSDag-Erling Smørgrav}]) 79*f7167e0eSDag-Erling Smørgrav 80*f7167e0eSDag-Erling Smørgravdnl OSSH_CHECK_LDFLAG_LINK(check_flag[, define_flag]) 81*f7167e0eSDag-Erling Smørgravdnl Check that $LD accepts a flag 'check_flag'. If it is supported append 82*f7167e0eSDag-Erling Smørgravdnl 'define_flag' to $LDFLAGS. If 'define_flag' is not specified, then append 83*f7167e0eSDag-Erling Smørgravdnl 'check_flag'. 84*f7167e0eSDag-Erling SmørgravAC_DEFUN([OSSH_CHECK_LDFLAG_LINK], [{ 85*f7167e0eSDag-Erling Smørgrav AC_MSG_CHECKING([if $LD supports link flag $1]) 86*f7167e0eSDag-Erling Smørgrav saved_LDFLAGS="$LDFLAGS" 87*f7167e0eSDag-Erling Smørgrav LDFLAGS="$LDFLAGS $WERROR $1" 88*f7167e0eSDag-Erling Smørgrav _define_flag="$2" 89*f7167e0eSDag-Erling Smørgrav test "x$_define_flag" = "x" && _define_flag="$1" 90*f7167e0eSDag-Erling Smørgrav AC_LINK_IFELSE([AC_LANG_SOURCE([[ 91*f7167e0eSDag-Erling Smørgrav#include <stdlib.h> 92*f7167e0eSDag-Erling Smørgrav#include <stdio.h> 93*f7167e0eSDag-Erling Smørgravint main(int argc, char **argv) { 94*f7167e0eSDag-Erling Smørgrav /* Some math to catch -ftrapv problems in the toolchain */ 95*f7167e0eSDag-Erling Smørgrav int i = 123 * argc, j = 456 + argc, k = 789 - argc; 96*f7167e0eSDag-Erling Smørgrav float l = i * 2.1; 97*f7167e0eSDag-Erling Smørgrav double m = l / 0.5; 98*f7167e0eSDag-Erling Smørgrav long long int n = argc * 12345LL, o = 12345LL * (long long int)argc; 99*f7167e0eSDag-Erling Smørgrav printf("%d %d %d %f %f %lld %lld\n", i, j, k, l, m, n, o); 100*f7167e0eSDag-Erling Smørgrav exit(0); 101*f7167e0eSDag-Erling Smørgrav} 102*f7167e0eSDag-Erling Smørgrav ]])], 103*f7167e0eSDag-Erling Smørgrav [ AC_MSG_RESULT([yes]) 104*f7167e0eSDag-Erling Smørgrav LDFLAGS="$saved_LDFLAGS $_define_flag"], 105*f7167e0eSDag-Erling Smørgrav [ AC_MSG_RESULT([no]) 106*f7167e0eSDag-Erling Smørgrav LDFLAGS="$saved_LDFLAGS" ] 107*f7167e0eSDag-Erling Smørgrav ) 108*f7167e0eSDag-Erling Smørgrav}]) 10983d2307dSDag-Erling Smørgrav 11083d2307dSDag-Erling Smørgravdnl OSSH_CHECK_HEADER_FOR_FIELD(field, header, symbol) 11183d2307dSDag-Erling Smørgravdnl Does AC_EGREP_HEADER on 'header' for the string 'field' 11283d2307dSDag-Erling Smørgravdnl If found, set 'symbol' to be defined. Cache the result. 11383d2307dSDag-Erling Smørgravdnl TODO: This is not foolproof, better to compile and read from there 11483d2307dSDag-Erling SmørgravAC_DEFUN(OSSH_CHECK_HEADER_FOR_FIELD, [ 11583d2307dSDag-Erling Smørgrav# look for field '$1' in header '$2' 11683d2307dSDag-Erling Smørgrav dnl This strips characters illegal to m4 from the header filename 11783d2307dSDag-Erling Smørgrav ossh_safe=`echo "$2" | sed 'y%./+-%__p_%'` 11883d2307dSDag-Erling Smørgrav dnl 11983d2307dSDag-Erling Smørgrav ossh_varname="ossh_cv_$ossh_safe""_has_"$1 12083d2307dSDag-Erling Smørgrav AC_MSG_CHECKING(for $1 field in $2) 12183d2307dSDag-Erling Smørgrav AC_CACHE_VAL($ossh_varname, [ 12283d2307dSDag-Erling Smørgrav AC_EGREP_HEADER($1, $2, [ dnl 12383d2307dSDag-Erling Smørgrav eval "$ossh_varname=yes" dnl 12483d2307dSDag-Erling Smørgrav ], [ dnl 12583d2307dSDag-Erling Smørgrav eval "$ossh_varname=no" dnl 12683d2307dSDag-Erling Smørgrav ]) dnl 12783d2307dSDag-Erling Smørgrav ]) 12883d2307dSDag-Erling Smørgrav ossh_result=`eval 'echo $'"$ossh_varname"` 12983d2307dSDag-Erling Smørgrav if test -n "`echo $ossh_varname`"; then 13083d2307dSDag-Erling Smørgrav AC_MSG_RESULT($ossh_result) 13183d2307dSDag-Erling Smørgrav if test "x$ossh_result" = "xyes"; then 132021d409fSDag-Erling Smørgrav AC_DEFINE($3, 1, [Define if you have $1 in $2]) 13383d2307dSDag-Erling Smørgrav fi 13483d2307dSDag-Erling Smørgrav else 13583d2307dSDag-Erling Smørgrav AC_MSG_RESULT(no) 13683d2307dSDag-Erling Smørgrav fi 13783d2307dSDag-Erling Smørgrav]) 13883d2307dSDag-Erling Smørgrav 13983d2307dSDag-Erling Smørgravdnl Check for socklen_t: historically on BSD it is an int, and in 14083d2307dSDag-Erling Smørgravdnl POSIX 1g it is a type of its own, but some platforms use different 14183d2307dSDag-Erling Smørgravdnl types for the argument to getsockopt, getpeername, etc. So we 14283d2307dSDag-Erling Smørgravdnl have to test to find something that will work. 14383d2307dSDag-Erling SmørgravAC_DEFUN([TYPE_SOCKLEN_T], 14483d2307dSDag-Erling Smørgrav[ 14583d2307dSDag-Erling Smørgrav AC_CHECK_TYPE([socklen_t], ,[ 14683d2307dSDag-Erling Smørgrav AC_MSG_CHECKING([for socklen_t equivalent]) 14783d2307dSDag-Erling Smørgrav AC_CACHE_VAL([curl_cv_socklen_t_equiv], 14883d2307dSDag-Erling Smørgrav [ 14983d2307dSDag-Erling Smørgrav # Systems have either "struct sockaddr *" or 15083d2307dSDag-Erling Smørgrav # "void *" as the second argument to getpeername 15183d2307dSDag-Erling Smørgrav curl_cv_socklen_t_equiv= 15283d2307dSDag-Erling Smørgrav for arg2 in "struct sockaddr" void; do 15383d2307dSDag-Erling Smørgrav for t in int size_t unsigned long "unsigned long"; do 15483d2307dSDag-Erling Smørgrav AC_TRY_COMPILE([ 15583d2307dSDag-Erling Smørgrav #include <sys/types.h> 15683d2307dSDag-Erling Smørgrav #include <sys/socket.h> 15783d2307dSDag-Erling Smørgrav 15883d2307dSDag-Erling Smørgrav int getpeername (int, $arg2 *, $t *); 15983d2307dSDag-Erling Smørgrav ],[ 16083d2307dSDag-Erling Smørgrav $t len; 16183d2307dSDag-Erling Smørgrav getpeername(0,0,&len); 16283d2307dSDag-Erling Smørgrav ],[ 16383d2307dSDag-Erling Smørgrav curl_cv_socklen_t_equiv="$t" 16483d2307dSDag-Erling Smørgrav break 16583d2307dSDag-Erling Smørgrav ]) 16683d2307dSDag-Erling Smørgrav done 16783d2307dSDag-Erling Smørgrav done 16883d2307dSDag-Erling Smørgrav 16983d2307dSDag-Erling Smørgrav if test "x$curl_cv_socklen_t_equiv" = x; then 17083d2307dSDag-Erling Smørgrav AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) 17183d2307dSDag-Erling Smørgrav fi 17283d2307dSDag-Erling Smørgrav ]) 17383d2307dSDag-Erling Smørgrav AC_MSG_RESULT($curl_cv_socklen_t_equiv) 17483d2307dSDag-Erling Smørgrav AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv, 17583d2307dSDag-Erling Smørgrav [type to use in place of socklen_t if not defined])], 17683d2307dSDag-Erling Smørgrav [#include <sys/types.h> 17783d2307dSDag-Erling Smørgrav#include <sys/socket.h>]) 17883d2307dSDag-Erling Smørgrav]) 17983d2307dSDag-Erling Smørgrav 180