1dnl OpenSSH-specific autoconf macros 2dnl 3 4dnl OSSH_CHECK_CFLAG_COMPILE(check_flag[, define_flag]) 5dnl Check that $CC accepts a flag 'check_flag'. If it is supported append 6dnl 'define_flag' to $CFLAGS. If 'define_flag' is not specified, then append 7dnl 'check_flag'. 8AC_DEFUN([OSSH_CHECK_CFLAG_COMPILE], [{ 9 AC_MSG_CHECKING([if $CC supports compile flag $1]) 10 saved_CFLAGS="$CFLAGS" 11 CFLAGS="$CFLAGS $WERROR $1" 12 _define_flag="$2" 13 test "x$_define_flag" = "x" && _define_flag="$1" 14 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ 15#include <stdlib.h> 16#include <stdio.h> 17int main(int argc, char **argv) { 18 (void)argv; 19 /* Some math to catch -ftrapv problems in the toolchain */ 20 int i = 123 * argc, j = 456 + argc, k = 789 - argc; 21 float l = i * 2.1; 22 double m = l / 0.5; 23 long long int n = argc * 12345LL, o = 12345LL * (long long int)argc; 24 printf("%d %d %d %f %f %lld %lld\n", i, j, k, l, m, n, o); 25 /* 26 * Test fallthrough behaviour. clang 10's -Wimplicit-fallthrough does 27 * not understand comments and we don't use the "fallthrough" attribute 28 * that it's looking for. 29 */ 30 switch(i){ 31 case 0: j += i; 32 /* FALLTHROUGH */ 33 default: j += k; 34 } 35 exit(0); 36} 37 ]])], 38 [ 39if $ac_cv_path_EGREP -i "unrecognized option|warning.*ignored" conftest.err >/dev/null 40then 41 AC_MSG_RESULT([no]) 42 CFLAGS="$saved_CFLAGS" 43else 44 AC_MSG_RESULT([yes]) 45 CFLAGS="$saved_CFLAGS $_define_flag" 46fi], 47 [ AC_MSG_RESULT([no]) 48 CFLAGS="$saved_CFLAGS" ] 49 ) 50}]) 51 52dnl OSSH_CHECK_CFLAG_LINK(check_flag[, define_flag]) 53dnl Check that $CC accepts a flag 'check_flag'. If it is supported append 54dnl 'define_flag' to $CFLAGS. If 'define_flag' is not specified, then append 55dnl 'check_flag'. 56AC_DEFUN([OSSH_CHECK_CFLAG_LINK], [{ 57 AC_MSG_CHECKING([if $CC supports compile flag $1 and linking succeeds]) 58 saved_CFLAGS="$CFLAGS" 59 CFLAGS="$CFLAGS $WERROR $1" 60 _define_flag="$2" 61 test "x$_define_flag" = "x" && _define_flag="$1" 62 AC_LINK_IFELSE([AC_LANG_SOURCE([[ 63#include <stdlib.h> 64#include <stdio.h> 65int main(int argc, char **argv) { 66 (void)argv; 67 /* Some math to catch -ftrapv problems in the toolchain */ 68 int i = 123 * argc, j = 456 + argc, k = 789 - argc; 69 float l = i * 2.1; 70 double m = l / 0.5; 71 long long int n = argc * 12345LL, o = 12345LL * (long long int)argc; 72 long long int p = n * o; 73 printf("%d %d %d %f %f %lld %lld %lld\n", i, j, k, l, m, n, o, p); 74 exit(0); 75} 76 ]])], 77 [ 78if $ac_cv_path_EGREP -i "unrecognized option|warning.*ignored" conftest.err >/dev/null 79then 80 AC_MSG_RESULT([no]) 81 CFLAGS="$saved_CFLAGS" 82else 83 AC_MSG_RESULT([yes]) 84 CFLAGS="$saved_CFLAGS $_define_flag" 85fi], 86 [ AC_MSG_RESULT([no]) 87 CFLAGS="$saved_CFLAGS" ] 88 ) 89}]) 90 91dnl OSSH_CHECK_LDFLAG_LINK(check_flag[, define_flag]) 92dnl Check that $LD accepts a flag 'check_flag'. If it is supported append 93dnl 'define_flag' to $LDFLAGS. If 'define_flag' is not specified, then append 94dnl 'check_flag'. 95AC_DEFUN([OSSH_CHECK_LDFLAG_LINK], [{ 96 AC_MSG_CHECKING([if $LD supports link flag $1]) 97 saved_LDFLAGS="$LDFLAGS" 98 LDFLAGS="$LDFLAGS $WERROR $1" 99 _define_flag="$2" 100 test "x$_define_flag" = "x" && _define_flag="$1" 101 AC_LINK_IFELSE([AC_LANG_SOURCE([[ 102#include <stdlib.h> 103#include <stdio.h> 104int main(int argc, char **argv) { 105 (void)argv; 106 /* Some math to catch -ftrapv problems in the toolchain */ 107 int i = 123 * argc, j = 456 + argc, k = 789 - argc; 108 float l = i * 2.1; 109 double m = l / 0.5; 110 long long int n = argc * 12345LL, o = 12345LL * (long long int)argc; 111 long long p = n * o; 112 printf("%d %d %d %f %f %lld %lld %lld\n", i, j, k, l, m, n, o, p); 113 exit(0); 114} 115 ]])], 116 [ 117if $ac_cv_path_EGREP -i "unrecognized option|warning.*ignored" conftest.err >/dev/null 118then 119 AC_MSG_RESULT([no]) 120 LDFLAGS="$saved_LDFLAGS" 121else 122 AC_MSG_RESULT([yes]) 123 LDFLAGS="$saved_LDFLAGS $_define_flag" 124fi ], 125 [ AC_MSG_RESULT([no]) 126 LDFLAGS="$saved_LDFLAGS" ] 127 ) 128}]) 129 130dnl OSSH_CHECK_HEADER_FOR_FIELD(field, header, symbol) 131dnl Does AC_EGREP_HEADER on 'header' for the string 'field' 132dnl If found, set 'symbol' to be defined. Cache the result. 133dnl TODO: This is not foolproof, better to compile and read from there 134AC_DEFUN([OSSH_CHECK_HEADER_FOR_FIELD], [ 135# look for field '$1' in header '$2' 136 dnl This strips characters illegal to m4 from the header filename 137 ossh_safe=`echo "$2" | sed 'y%./+-%__p_%'` 138 dnl 139 ossh_varname="ossh_cv_$ossh_safe""_has_"$1 140 AC_MSG_CHECKING(for $1 field in $2) 141 AC_CACHE_VAL($ossh_varname, [ 142 AC_EGREP_HEADER($1, $2, [ dnl 143 eval "$ossh_varname=yes" dnl 144 ], [ dnl 145 eval "$ossh_varname=no" dnl 146 ]) dnl 147 ]) 148 ossh_result=`eval 'echo $'"$ossh_varname"` 149 if test -n "`echo $ossh_varname`"; then 150 AC_MSG_RESULT($ossh_result) 151 if test "x$ossh_result" = "xyes"; then 152 AC_DEFINE($3, 1, [Define if you have $1 in $2]) 153 fi 154 else 155 AC_MSG_RESULT(no) 156 fi 157]) 158 159dnl Check for socklen_t: historically on BSD it is an int, and in 160dnl POSIX 1g it is a type of its own, but some platforms use different 161dnl types for the argument to getsockopt, getpeername, etc. So we 162dnl have to test to find something that will work. 163AC_DEFUN([TYPE_SOCKLEN_T], 164[ 165 AC_CHECK_TYPE([socklen_t], ,[ 166 AC_MSG_CHECKING([for socklen_t equivalent]) 167 AC_CACHE_VAL([curl_cv_socklen_t_equiv], 168 [ 169 # Systems have either "struct sockaddr *" or 170 # "void *" as the second argument to getpeername 171 curl_cv_socklen_t_equiv= 172 for arg2 in "struct sockaddr" void; do 173 for t in int size_t unsigned long "unsigned long"; do 174 AC_COMPILE_IFELSE([ 175 AC_LANG_PROGRAM([[ 176 #include <sys/types.h> 177 #include <sys/socket.h> 178 int getpeername (int, $arg2 *, $t *); 179 ]], [[ 180 $t len; 181 getpeername(0,0,&len); 182 ]]) 183 ],[ 184 curl_cv_socklen_t_equiv="$t" 185 break 186 ]) 187 done 188 done 189 190 if test "x$curl_cv_socklen_t_equiv" = x; then 191 AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) 192 fi 193 ]) 194 AC_MSG_RESULT($curl_cv_socklen_t_equiv) 195 AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv, 196 [type to use in place of socklen_t if not defined])], 197 [#include <sys/types.h> 198#include <sys/socket.h>]) 199]) 200 201