Tim Rice | 01ec0af | 2013-06-02 14:31:27 -0700 | [diff] [blame] | 1 | dnl $Id: aclocal.m4,v 1.9 2013/06/02 21:31:27 tim Exp $ |
Damien Miller | 0437b33 | 2000-05-02 09:56:41 +1000 | [diff] [blame] | 2 | dnl |
| 3 | dnl OpenSSH-specific autoconf macros |
| 4 | dnl |
| 5 | |
Damien Miller | b176362 | 2011-05-20 11:45:25 +1000 | [diff] [blame] | 6 | dnl OSSH_CHECK_CFLAG_COMPILE(check_flag[, define_flag]) |
| 7 | dnl Check that $CC accepts a flag 'check_flag'. If it is supported append |
| 8 | dnl 'define_flag' to $CFLAGS. If 'define_flag' is not specified, then append |
| 9 | dnl 'check_flag'. |
| 10 | AC_DEFUN([OSSH_CHECK_CFLAG_COMPILE], [{ |
| 11 | AC_MSG_CHECKING([if $CC supports $1]) |
| 12 | saved_CFLAGS="$CFLAGS" |
| 13 | CFLAGS="$CFLAGS $1" |
| 14 | _define_flag="$2" |
| 15 | test "x$_define_flag" = "x" && _define_flag="$1" |
| 16 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int main(void) { return 0; }]])], |
Tim Rice | 01ec0af | 2013-06-02 14:31:27 -0700 | [diff] [blame] | 17 | [ |
| 18 | if `grep -i "unrecognized option" conftest.err >/dev/null` |
| 19 | then |
| 20 | AC_MSG_RESULT([no]) |
| 21 | CFLAGS="$saved_CFLAGS" |
| 22 | else |
| 23 | AC_MSG_RESULT([yes]) |
| 24 | CFLAGS="$saved_CFLAGS $_define_flag" |
| 25 | fi], |
Damien Miller | b176362 | 2011-05-20 11:45:25 +1000 | [diff] [blame] | 26 | [ AC_MSG_RESULT([no]) |
| 27 | CFLAGS="$saved_CFLAGS" ] |
| 28 | ) |
| 29 | }]) |
| 30 | |
Damien Miller | 61e50f1 | 2000-05-08 20:49:37 +1000 | [diff] [blame] | 31 | |
| 32 | dnl OSSH_CHECK_HEADER_FOR_FIELD(field, header, symbol) |
| 33 | dnl Does AC_EGREP_HEADER on 'header' for the string 'field' |
| 34 | dnl If found, set 'symbol' to be defined. Cache the result. |
| 35 | dnl TODO: This is not foolproof, better to compile and read from there |
| 36 | AC_DEFUN(OSSH_CHECK_HEADER_FOR_FIELD, [ |
| 37 | # look for field '$1' in header '$2' |
| 38 | dnl This strips characters illegal to m4 from the header filename |
| 39 | ossh_safe=`echo "$2" | sed 'y%./+-%__p_%'` |
| 40 | dnl |
| 41 | ossh_varname="ossh_cv_$ossh_safe""_has_"$1 |
| 42 | AC_MSG_CHECKING(for $1 field in $2) |
| 43 | AC_CACHE_VAL($ossh_varname, [ |
| 44 | AC_EGREP_HEADER($1, $2, [ dnl |
| 45 | eval "$ossh_varname=yes" dnl |
| 46 | ], [ dnl |
| 47 | eval "$ossh_varname=no" dnl |
| 48 | ]) dnl |
| 49 | ]) |
Damien Miller | 8dd33fd | 2000-06-26 10:20:19 +1000 | [diff] [blame] | 50 | ossh_result=`eval 'echo $'"$ossh_varname"` |
Damien Miller | 61e50f1 | 2000-05-08 20:49:37 +1000 | [diff] [blame] | 51 | if test -n "`echo $ossh_varname`"; then |
| 52 | AC_MSG_RESULT($ossh_result) |
| 53 | if test "x$ossh_result" = "xyes"; then |
Tim Rice | 7df8d39 | 2005-09-19 09:33:39 -0700 | [diff] [blame] | 54 | AC_DEFINE($3, 1, [Define if you have $1 in $2]) |
Damien Miller | 61e50f1 | 2000-05-08 20:49:37 +1000 | [diff] [blame] | 55 | fi |
| 56 | else |
| 57 | AC_MSG_RESULT(no) |
| 58 | fi |
| 59 | ]) |
| 60 | |
Tim Rice | 13aae5e | 2001-10-21 17:53:58 -0700 | [diff] [blame] | 61 | dnl Check for socklen_t: historically on BSD it is an int, and in |
| 62 | dnl POSIX 1g it is a type of its own, but some platforms use different |
| 63 | dnl types for the argument to getsockopt, getpeername, etc. So we |
| 64 | dnl have to test to find something that will work. |
| 65 | AC_DEFUN([TYPE_SOCKLEN_T], |
| 66 | [ |
| 67 | AC_CHECK_TYPE([socklen_t], ,[ |
| 68 | AC_MSG_CHECKING([for socklen_t equivalent]) |
| 69 | AC_CACHE_VAL([curl_cv_socklen_t_equiv], |
| 70 | [ |
| 71 | # Systems have either "struct sockaddr *" or |
| 72 | # "void *" as the second argument to getpeername |
| 73 | curl_cv_socklen_t_equiv= |
| 74 | for arg2 in "struct sockaddr" void; do |
| 75 | for t in int size_t unsigned long "unsigned long"; do |
| 76 | AC_TRY_COMPILE([ |
| 77 | #include <sys/types.h> |
| 78 | #include <sys/socket.h> |
| 79 | |
| 80 | int getpeername (int, $arg2 *, $t *); |
| 81 | ],[ |
| 82 | $t len; |
| 83 | getpeername(0,0,&len); |
| 84 | ],[ |
| 85 | curl_cv_socklen_t_equiv="$t" |
| 86 | break |
| 87 | ]) |
| 88 | done |
| 89 | done |
| 90 | |
| 91 | if test "x$curl_cv_socklen_t_equiv" = x; then |
| 92 | AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) |
| 93 | fi |
| 94 | ]) |
| 95 | AC_MSG_RESULT($curl_cv_socklen_t_equiv) |
| 96 | AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv, |
| 97 | [type to use in place of socklen_t if not defined])], |
| 98 | [#include <sys/types.h> |
| 99 | #include <sys/socket.h>]) |
| 100 | ]) |
| 101 | |