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