Damien Miller | 0437b33 | 2000-05-02 09:56:41 +1000 | [diff] [blame] | 1 | dnl OpenSSH-specific autoconf macros |
| 2 | dnl |
| 3 | |
Damien Miller | b176362 | 2011-05-20 11:45:25 +1000 | [diff] [blame] | 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 |
| 7 | dnl 'check_flag'. |
| 8 | AC_DEFUN([OSSH_CHECK_CFLAG_COMPILE], [{ |
Darren Tucker | a6d573c | 2014-01-21 12:50:46 +1100 | [diff] [blame] | 9 | AC_MSG_CHECKING([if $CC supports compile flag $1]) |
Damien Miller | b176362 | 2011-05-20 11:45:25 +1000 | [diff] [blame] | 10 | saved_CFLAGS="$CFLAGS" |
Darren Tucker | fd99437 | 2014-01-17 09:53:24 +1100 | [diff] [blame] | 11 | CFLAGS="$CFLAGS $WERROR $1" |
Damien Miller | b176362 | 2011-05-20 11:45:25 +1000 | [diff] [blame] | 12 | _define_flag="$2" |
| 13 | test "x$_define_flag" = "x" && _define_flag="$1" |
Damien Miller | 5c96a15 | 2014-01-21 13:10:26 +1100 | [diff] [blame] | 14 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ |
| 15 | #include <stdlib.h> |
| 16 | #include <stdio.h> |
| 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; |
| 20 | float l = i * 2.1; |
| 21 | double m = l / 0.5; |
Damien Miller | 5c2ff5e | 2014-01-22 21:30:12 +1100 | [diff] [blame] | 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); |
| 24 | exit(0); |
| 25 | } |
| 26 | ]])], |
| 27 | [ |
| 28 | if `grep -i "unrecognized option" conftest.err >/dev/null` |
| 29 | then |
| 30 | AC_MSG_RESULT([no]) |
| 31 | CFLAGS="$saved_CFLAGS" |
| 32 | else |
| 33 | AC_MSG_RESULT([yes]) |
| 34 | CFLAGS="$saved_CFLAGS $_define_flag" |
| 35 | fi], |
| 36 | [ AC_MSG_RESULT([no]) |
| 37 | CFLAGS="$saved_CFLAGS" ] |
| 38 | ) |
| 39 | }]) |
| 40 | |
| 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 |
| 44 | dnl 'check_flag'. |
| 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" |
| 49 | _define_flag="$2" |
| 50 | test "x$_define_flag" = "x" && _define_flag="$1" |
| 51 | AC_LINK_IFELSE([AC_LANG_SOURCE([[ |
| 52 | #include <stdlib.h> |
| 53 | #include <stdio.h> |
| 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; |
| 57 | float l = i * 2.1; |
| 58 | double m = l / 0.5; |
| 59 | long long int n = argc * 12345LL, o = 12345LL * (long long int)argc; |
Darren Tucker | a8fc0f4 | 2016-08-17 13:35:43 +1000 | [diff] [blame] | 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); |
Damien Miller | 5c96a15 | 2014-01-21 13:10:26 +1100 | [diff] [blame] | 62 | exit(0); |
| 63 | } |
| 64 | ]])], |
Tim Rice | 01ec0af | 2013-06-02 14:31:27 -0700 | [diff] [blame] | 65 | [ |
| 66 | if `grep -i "unrecognized option" conftest.err >/dev/null` |
| 67 | then |
| 68 | AC_MSG_RESULT([no]) |
| 69 | CFLAGS="$saved_CFLAGS" |
| 70 | else |
| 71 | AC_MSG_RESULT([yes]) |
| 72 | CFLAGS="$saved_CFLAGS $_define_flag" |
| 73 | fi], |
Damien Miller | b176362 | 2011-05-20 11:45:25 +1000 | [diff] [blame] | 74 | [ AC_MSG_RESULT([no]) |
| 75 | CFLAGS="$saved_CFLAGS" ] |
| 76 | ) |
| 77 | }]) |
| 78 | |
Damien Miller | 5c96a15 | 2014-01-21 13:10:26 +1100 | [diff] [blame] | 79 | dnl OSSH_CHECK_LDFLAG_LINK(check_flag[, define_flag]) |
Darren Tucker | fd99437 | 2014-01-17 09:53:24 +1100 | [diff] [blame] | 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 |
| 82 | dnl 'check_flag'. |
| 83 | AC_DEFUN([OSSH_CHECK_LDFLAG_LINK], [{ |
Darren Tucker | a6d573c | 2014-01-21 12:50:46 +1100 | [diff] [blame] | 84 | AC_MSG_CHECKING([if $LD supports link flag $1]) |
Darren Tucker | fd99437 | 2014-01-17 09:53:24 +1100 | [diff] [blame] | 85 | saved_LDFLAGS="$LDFLAGS" |
| 86 | LDFLAGS="$LDFLAGS $WERROR $1" |
| 87 | _define_flag="$2" |
| 88 | test "x$_define_flag" = "x" && _define_flag="$1" |
Damien Miller | 5c96a15 | 2014-01-21 13:10:26 +1100 | [diff] [blame] | 89 | AC_LINK_IFELSE([AC_LANG_SOURCE([[ |
| 90 | #include <stdlib.h> |
| 91 | #include <stdio.h> |
| 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; |
| 95 | float l = i * 2.1; |
| 96 | double m = l / 0.5; |
Damien Miller | 5c2ff5e | 2014-01-22 21:30:12 +1100 | [diff] [blame] | 97 | long long int n = argc * 12345LL, o = 12345LL * (long long int)argc; |
Darren Tucker | a8fc0f4 | 2016-08-17 13:35:43 +1000 | [diff] [blame] | 98 | long long p = n * o; |
| 99 | printf("%d %d %d %f %f %lld %lld %lld\n", i, j, k, l, m, n, o, p); |
Damien Miller | 5c96a15 | 2014-01-21 13:10:26 +1100 | [diff] [blame] | 100 | exit(0); |
| 101 | } |
| 102 | ]])], |
Darren Tucker | fd99437 | 2014-01-17 09:53:24 +1100 | [diff] [blame] | 103 | [ AC_MSG_RESULT([yes]) |
| 104 | LDFLAGS="$saved_LDFLAGS $_define_flag"], |
| 105 | [ AC_MSG_RESULT([no]) |
| 106 | LDFLAGS="$saved_LDFLAGS" ] |
| 107 | ) |
| 108 | }]) |
Damien Miller | 61e50f1 | 2000-05-08 20:49:37 +1000 | [diff] [blame] | 109 | |
| 110 | dnl OSSH_CHECK_HEADER_FOR_FIELD(field, header, symbol) |
| 111 | dnl Does AC_EGREP_HEADER on 'header' for the string 'field' |
| 112 | dnl If found, set 'symbol' to be defined. Cache the result. |
| 113 | dnl TODO: This is not foolproof, better to compile and read from there |
| 114 | AC_DEFUN(OSSH_CHECK_HEADER_FOR_FIELD, [ |
| 115 | # look for field '$1' in header '$2' |
| 116 | dnl This strips characters illegal to m4 from the header filename |
| 117 | ossh_safe=`echo "$2" | sed 'y%./+-%__p_%'` |
| 118 | dnl |
| 119 | ossh_varname="ossh_cv_$ossh_safe""_has_"$1 |
| 120 | AC_MSG_CHECKING(for $1 field in $2) |
| 121 | AC_CACHE_VAL($ossh_varname, [ |
| 122 | AC_EGREP_HEADER($1, $2, [ dnl |
| 123 | eval "$ossh_varname=yes" dnl |
| 124 | ], [ dnl |
| 125 | eval "$ossh_varname=no" dnl |
| 126 | ]) dnl |
| 127 | ]) |
Damien Miller | 8dd33fd | 2000-06-26 10:20:19 +1000 | [diff] [blame] | 128 | ossh_result=`eval 'echo $'"$ossh_varname"` |
Damien Miller | 61e50f1 | 2000-05-08 20:49:37 +1000 | [diff] [blame] | 129 | if test -n "`echo $ossh_varname`"; then |
| 130 | AC_MSG_RESULT($ossh_result) |
| 131 | if test "x$ossh_result" = "xyes"; then |
Tim Rice | 7df8d39 | 2005-09-19 09:33:39 -0700 | [diff] [blame] | 132 | AC_DEFINE($3, 1, [Define if you have $1 in $2]) |
Damien Miller | 61e50f1 | 2000-05-08 20:49:37 +1000 | [diff] [blame] | 133 | fi |
| 134 | else |
| 135 | AC_MSG_RESULT(no) |
| 136 | fi |
| 137 | ]) |
| 138 | |
Tim Rice | 13aae5e | 2001-10-21 17:53:58 -0700 | [diff] [blame] | 139 | dnl Check for socklen_t: historically on BSD it is an int, and in |
| 140 | dnl POSIX 1g it is a type of its own, but some platforms use different |
| 141 | dnl types for the argument to getsockopt, getpeername, etc. So we |
| 142 | dnl have to test to find something that will work. |
| 143 | AC_DEFUN([TYPE_SOCKLEN_T], |
| 144 | [ |
| 145 | AC_CHECK_TYPE([socklen_t], ,[ |
| 146 | AC_MSG_CHECKING([for socklen_t equivalent]) |
| 147 | AC_CACHE_VAL([curl_cv_socklen_t_equiv], |
| 148 | [ |
| 149 | # Systems have either "struct sockaddr *" or |
| 150 | # "void *" as the second argument to getpeername |
| 151 | curl_cv_socklen_t_equiv= |
| 152 | for arg2 in "struct sockaddr" void; do |
| 153 | for t in int size_t unsigned long "unsigned long"; do |
| 154 | AC_TRY_COMPILE([ |
| 155 | #include <sys/types.h> |
| 156 | #include <sys/socket.h> |
| 157 | |
| 158 | int getpeername (int, $arg2 *, $t *); |
| 159 | ],[ |
| 160 | $t len; |
| 161 | getpeername(0,0,&len); |
| 162 | ],[ |
| 163 | curl_cv_socklen_t_equiv="$t" |
| 164 | break |
| 165 | ]) |
| 166 | done |
| 167 | done |
| 168 | |
| 169 | if test "x$curl_cv_socklen_t_equiv" = x; then |
| 170 | AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) |
| 171 | fi |
| 172 | ]) |
| 173 | AC_MSG_RESULT($curl_cv_socklen_t_equiv) |
| 174 | AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv, |
| 175 | [type to use in place of socklen_t if not defined])], |
| 176 | [#include <sys/types.h> |
| 177 | #include <sys/socket.h>]) |
| 178 | ]) |
| 179 | |