1 dnl OpenSSH-specific autoconf macros
4 dnl OSSH_CHECK_CFLAG_COMPILE(check_flag[, define_flag])
5 dnl Check that $CC accepts a flag 'check_flag'. If it is supported append
6 dnl 'define_flag' to $CFLAGS. If 'define_flag' is not specified, then append
8 AC_DEFUN([OSSH_CHECK_CFLAG_COMPILE], [{
9 AC_MSG_CHECKING([if $CC supports compile flag $1])
10 saved_CFLAGS="$CFLAGS"
11 CFLAGS="$CFLAGS $WERROR $1"
13 test "x$_define_flag" = "x" && _define_flag="$1"
14 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
17 int main(int argc, char **argv) {
18 /* Some math to catch -ftrapv problems in the toolchain */
19 int i = 123 * argc, j = 456 + argc, k = 789 - argc;
22 long long int n = argc * 12345LL, o = 12345LL * (long long int)argc;
23 printf("%d %d %d %f %f %lld %lld\n", i, j, k, l, m, n, o);
28 if $ac_cv_path_EGREP -i "unrecognized option|warning.*ignored" conftest.err >/dev/null
31 CFLAGS="$saved_CFLAGS"
34 CFLAGS="$saved_CFLAGS $_define_flag"
37 CFLAGS="$saved_CFLAGS" ]
41 dnl OSSH_CHECK_CFLAG_LINK(check_flag[, define_flag])
42 dnl Check that $CC accepts a flag 'check_flag'. If it is supported append
43 dnl 'define_flag' to $CFLAGS. If 'define_flag' is not specified, then append
45 AC_DEFUN([OSSH_CHECK_CFLAG_LINK], [{
46 AC_MSG_CHECKING([if $CC supports compile flag $1 and linking succeeds])
47 saved_CFLAGS="$CFLAGS"
48 CFLAGS="$CFLAGS $WERROR $1"
50 test "x$_define_flag" = "x" && _define_flag="$1"
51 AC_LINK_IFELSE([AC_LANG_SOURCE([[
54 int main(int argc, char **argv) {
55 /* Some math to catch -ftrapv problems in the toolchain */
56 int i = 123 * argc, j = 456 + argc, k = 789 - argc;
59 long long int n = argc * 12345LL, o = 12345LL * (long long int)argc;
60 long long int p = n * o;
61 printf("%d %d %d %f %f %lld %lld %lld\n", i, j, k, l, m, n, o, p);
66 if $ac_cv_path_EGREP -i "unrecognized option|warning.*ignored" conftest.err >/dev/null
69 CFLAGS="$saved_CFLAGS"
72 CFLAGS="$saved_CFLAGS $_define_flag"
75 CFLAGS="$saved_CFLAGS" ]
79 dnl OSSH_CHECK_LDFLAG_LINK(check_flag[, define_flag])
80 dnl Check that $LD accepts a flag 'check_flag'. If it is supported append
81 dnl 'define_flag' to $LDFLAGS. If 'define_flag' is not specified, then append
83 AC_DEFUN([OSSH_CHECK_LDFLAG_LINK], [{
84 AC_MSG_CHECKING([if $LD supports link flag $1])
85 saved_LDFLAGS="$LDFLAGS"
86 LDFLAGS="$LDFLAGS $WERROR $1"
88 test "x$_define_flag" = "x" && _define_flag="$1"
89 AC_LINK_IFELSE([AC_LANG_SOURCE([[
92 int main(int argc, char **argv) {
93 /* Some math to catch -ftrapv problems in the toolchain */
94 int i = 123 * argc, j = 456 + argc, k = 789 - argc;
97 long long int n = argc * 12345LL, o = 12345LL * (long long int)argc;
99 printf("%d %d %d %f %f %lld %lld %lld\n", i, j, k, l, m, n, o, p);
104 if $ac_cv_path_EGREP -i "unrecognized option|warning.*ignored" conftest.err >/dev/null
107 LDFLAGS="$saved_LDFLAGS"
110 LDFLAGS="$saved_LDFLAGS $_define_flag"
112 [ AC_MSG_RESULT([no])
113 LDFLAGS="$saved_LDFLAGS" ]
117 dnl OSSH_CHECK_HEADER_FOR_FIELD(field, header, symbol)
118 dnl Does AC_EGREP_HEADER on 'header' for the string 'field'
119 dnl If found, set 'symbol' to be defined. Cache the result.
120 dnl TODO: This is not foolproof, better to compile and read from there
121 AC_DEFUN(OSSH_CHECK_HEADER_FOR_FIELD, [
122 # look for field '$1' in header '$2'
123 dnl This strips characters illegal to m4 from the header filename
124 ossh_safe=`echo "$2" | sed 'y%./+-%__p_%'`
126 ossh_varname="ossh_cv_$ossh_safe""_has_"$1
127 AC_MSG_CHECKING(for $1 field in $2)
128 AC_CACHE_VAL($ossh_varname, [
129 AC_EGREP_HEADER($1, $2, [ dnl
130 eval "$ossh_varname=yes" dnl
132 eval "$ossh_varname=no" dnl
135 ossh_result=`eval 'echo $'"$ossh_varname"`
136 if test -n "`echo $ossh_varname`"; then
137 AC_MSG_RESULT($ossh_result)
138 if test "x$ossh_result" = "xyes"; then
139 AC_DEFINE($3, 1, [Define if you have $1 in $2])
146 dnl Check for socklen_t: historically on BSD it is an int, and in
147 dnl POSIX 1g it is a type of its own, but some platforms use different
148 dnl types for the argument to getsockopt, getpeername, etc. So we
149 dnl have to test to find something that will work.
150 AC_DEFUN([TYPE_SOCKLEN_T],
152 AC_CHECK_TYPE([socklen_t], ,[
153 AC_MSG_CHECKING([for socklen_t equivalent])
154 AC_CACHE_VAL([curl_cv_socklen_t_equiv],
156 # Systems have either "struct sockaddr *" or
157 # "void *" as the second argument to getpeername
158 curl_cv_socklen_t_equiv=
159 for arg2 in "struct sockaddr" void; do
160 for t in int size_t unsigned long "unsigned long"; do
162 #include <sys/types.h>
163 #include <sys/socket.h>
165 int getpeername (int, $arg2 *, $t *);
168 getpeername(0,0,&len);
170 curl_cv_socklen_t_equiv="$t"
176 if test "x$curl_cv_socklen_t_equiv" = x; then
177 AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
180 AC_MSG_RESULT($curl_cv_socklen_t_equiv)
181 AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
182 [type to use in place of socklen_t if not defined])],
183 [#include <sys/types.h>
184 #include <sys/socket.h>])