1262566Sdesdnl $Id: aclocal.m4,v 1.13 2014/01/22 10:30:12 djm Exp $ 298937Sdesdnl 398937Sdesdnl OpenSSH-specific autoconf macros 498937Sdesdnl 598937Sdes 6226046Sdesdnl OSSH_CHECK_CFLAG_COMPILE(check_flag[, define_flag]) 7226046Sdesdnl Check that $CC accepts a flag 'check_flag'. If it is supported append 8226046Sdesdnl 'define_flag' to $CFLAGS. If 'define_flag' is not specified, then append 9226046Sdesdnl 'check_flag'. 10226046SdesAC_DEFUN([OSSH_CHECK_CFLAG_COMPILE], [{ 11262566Sdes AC_MSG_CHECKING([if $CC supports compile flag $1]) 12226046Sdes saved_CFLAGS="$CFLAGS" 13262566Sdes CFLAGS="$CFLAGS $WERROR $1" 14226046Sdes _define_flag="$2" 15226046Sdes test "x$_define_flag" = "x" && _define_flag="$1" 16262566Sdes AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 17262566Sdes#include <stdlib.h> 18262566Sdes#include <stdio.h> 19262566Sdesint main(int argc, char **argv) { 20262566Sdes /* Some math to catch -ftrapv problems in the toolchain */ 21262566Sdes int i = 123 * argc, j = 456 + argc, k = 789 - argc; 22262566Sdes float l = i * 2.1; 23262566Sdes double m = l / 0.5; 24262566Sdes long long int n = argc * 12345LL, o = 12345LL * (long long int)argc; 25262566Sdes printf("%d %d %d %f %f %lld %lld\n", i, j, k, l, m, n, o); 26262566Sdes exit(0); 27262566Sdes} 28262566Sdes ]])], 29255767Sdes [ 30255767Sdesif `grep -i "unrecognized option" conftest.err >/dev/null` 31255767Sdesthen 32255767Sdes AC_MSG_RESULT([no]) 33255767Sdes CFLAGS="$saved_CFLAGS" 34255767Sdeselse 35255767Sdes AC_MSG_RESULT([yes]) 36255767Sdes CFLAGS="$saved_CFLAGS $_define_flag" 37255767Sdesfi], 38226046Sdes [ AC_MSG_RESULT([no]) 39226046Sdes CFLAGS="$saved_CFLAGS" ] 40226046Sdes ) 41226046Sdes}]) 4298937Sdes 43262566Sdesdnl OSSH_CHECK_CFLAG_LINK(check_flag[, define_flag]) 44262566Sdesdnl Check that $CC accepts a flag 'check_flag'. If it is supported append 45262566Sdesdnl 'define_flag' to $CFLAGS. If 'define_flag' is not specified, then append 46262566Sdesdnl 'check_flag'. 47262566SdesAC_DEFUN([OSSH_CHECK_CFLAG_LINK], [{ 48262566Sdes AC_MSG_CHECKING([if $CC supports compile flag $1 and linking succeeds]) 49262566Sdes saved_CFLAGS="$CFLAGS" 50262566Sdes CFLAGS="$CFLAGS $WERROR $1" 51262566Sdes _define_flag="$2" 52262566Sdes test "x$_define_flag" = "x" && _define_flag="$1" 53262566Sdes AC_LINK_IFELSE([AC_LANG_SOURCE([[ 54262566Sdes#include <stdlib.h> 55262566Sdes#include <stdio.h> 56262566Sdesint main(int argc, char **argv) { 57262566Sdes /* Some math to catch -ftrapv problems in the toolchain */ 58262566Sdes int i = 123 * argc, j = 456 + argc, k = 789 - argc; 59262566Sdes float l = i * 2.1; 60262566Sdes double m = l / 0.5; 61262566Sdes long long int n = argc * 12345LL, o = 12345LL * (long long int)argc; 62262566Sdes printf("%d %d %d %f %f %lld %lld\n", i, j, k, l, m, n, o); 63262566Sdes exit(0); 64262566Sdes} 65262566Sdes ]])], 66262566Sdes [ 67262566Sdesif `grep -i "unrecognized option" conftest.err >/dev/null` 68262566Sdesthen 69262566Sdes AC_MSG_RESULT([no]) 70262566Sdes CFLAGS="$saved_CFLAGS" 71262566Sdeselse 72262566Sdes AC_MSG_RESULT([yes]) 73262566Sdes CFLAGS="$saved_CFLAGS $_define_flag" 74262566Sdesfi], 75262566Sdes [ AC_MSG_RESULT([no]) 76262566Sdes CFLAGS="$saved_CFLAGS" ] 77262566Sdes ) 78262566Sdes}]) 79226046Sdes 80262566Sdesdnl OSSH_CHECK_LDFLAG_LINK(check_flag[, define_flag]) 81262566Sdesdnl Check that $LD accepts a flag 'check_flag'. If it is supported append 82262566Sdesdnl 'define_flag' to $LDFLAGS. If 'define_flag' is not specified, then append 83262566Sdesdnl 'check_flag'. 84262566SdesAC_DEFUN([OSSH_CHECK_LDFLAG_LINK], [{ 85262566Sdes AC_MSG_CHECKING([if $LD supports link flag $1]) 86262566Sdes saved_LDFLAGS="$LDFLAGS" 87262566Sdes LDFLAGS="$LDFLAGS $WERROR $1" 88262566Sdes _define_flag="$2" 89262566Sdes test "x$_define_flag" = "x" && _define_flag="$1" 90262566Sdes AC_LINK_IFELSE([AC_LANG_SOURCE([[ 91262566Sdes#include <stdlib.h> 92262566Sdes#include <stdio.h> 93262566Sdesint main(int argc, char **argv) { 94262566Sdes /* Some math to catch -ftrapv problems in the toolchain */ 95262566Sdes int i = 123 * argc, j = 456 + argc, k = 789 - argc; 96262566Sdes float l = i * 2.1; 97262566Sdes double m = l / 0.5; 98262566Sdes long long int n = argc * 12345LL, o = 12345LL * (long long int)argc; 99262566Sdes printf("%d %d %d %f %f %lld %lld\n", i, j, k, l, m, n, o); 100262566Sdes exit(0); 101262566Sdes} 102262566Sdes ]])], 103262566Sdes [ AC_MSG_RESULT([yes]) 104262566Sdes LDFLAGS="$saved_LDFLAGS $_define_flag"], 105262566Sdes [ AC_MSG_RESULT([no]) 106262566Sdes LDFLAGS="$saved_LDFLAGS" ] 107262566Sdes ) 108262566Sdes}]) 109262566Sdes 11098937Sdesdnl OSSH_CHECK_HEADER_FOR_FIELD(field, header, symbol) 11198937Sdesdnl Does AC_EGREP_HEADER on 'header' for the string 'field' 11298937Sdesdnl If found, set 'symbol' to be defined. Cache the result. 11398937Sdesdnl TODO: This is not foolproof, better to compile and read from there 11498937SdesAC_DEFUN(OSSH_CHECK_HEADER_FOR_FIELD, [ 11598937Sdes# look for field '$1' in header '$2' 11698937Sdes dnl This strips characters illegal to m4 from the header filename 11798937Sdes ossh_safe=`echo "$2" | sed 'y%./+-%__p_%'` 11898937Sdes dnl 11998937Sdes ossh_varname="ossh_cv_$ossh_safe""_has_"$1 12098937Sdes AC_MSG_CHECKING(for $1 field in $2) 12198937Sdes AC_CACHE_VAL($ossh_varname, [ 12298937Sdes AC_EGREP_HEADER($1, $2, [ dnl 12398937Sdes eval "$ossh_varname=yes" dnl 12498937Sdes ], [ dnl 12598937Sdes eval "$ossh_varname=no" dnl 12698937Sdes ]) dnl 12798937Sdes ]) 12898937Sdes ossh_result=`eval 'echo $'"$ossh_varname"` 12998937Sdes if test -n "`echo $ossh_varname`"; then 13098937Sdes AC_MSG_RESULT($ossh_result) 13198937Sdes if test "x$ossh_result" = "xyes"; then 132157016Sdes AC_DEFINE($3, 1, [Define if you have $1 in $2]) 13398937Sdes fi 13498937Sdes else 13598937Sdes AC_MSG_RESULT(no) 13698937Sdes fi 13798937Sdes]) 13898937Sdes 13998937Sdesdnl Check for socklen_t: historically on BSD it is an int, and in 14098937Sdesdnl POSIX 1g it is a type of its own, but some platforms use different 14198937Sdesdnl types for the argument to getsockopt, getpeername, etc. So we 14298937Sdesdnl have to test to find something that will work. 14398937SdesAC_DEFUN([TYPE_SOCKLEN_T], 14498937Sdes[ 14598937Sdes AC_CHECK_TYPE([socklen_t], ,[ 14698937Sdes AC_MSG_CHECKING([for socklen_t equivalent]) 14798937Sdes AC_CACHE_VAL([curl_cv_socklen_t_equiv], 14898937Sdes [ 14998937Sdes # Systems have either "struct sockaddr *" or 15098937Sdes # "void *" as the second argument to getpeername 15198937Sdes curl_cv_socklen_t_equiv= 15298937Sdes for arg2 in "struct sockaddr" void; do 15398937Sdes for t in int size_t unsigned long "unsigned long"; do 15498937Sdes AC_TRY_COMPILE([ 15598937Sdes #include <sys/types.h> 15698937Sdes #include <sys/socket.h> 15798937Sdes 15898937Sdes int getpeername (int, $arg2 *, $t *); 15998937Sdes ],[ 16098937Sdes $t len; 16198937Sdes getpeername(0,0,&len); 16298937Sdes ],[ 16398937Sdes curl_cv_socklen_t_equiv="$t" 16498937Sdes break 16598937Sdes ]) 16698937Sdes done 16798937Sdes done 16898937Sdes 16998937Sdes if test "x$curl_cv_socklen_t_equiv" = x; then 17098937Sdes AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) 17198937Sdes fi 17298937Sdes ]) 17398937Sdes AC_MSG_RESULT($curl_cv_socklen_t_equiv) 17498937Sdes AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv, 17598937Sdes [type to use in place of socklen_t if not defined])], 17698937Sdes [#include <sys/types.h> 17798937Sdes#include <sys/socket.h>]) 17898937Sdes]) 17998937Sdes 180