blob: 1640683e1d1d7c447e163183cbadb666019401ae [file] [log] [blame]
Damien Miller5c2ff5e2014-01-22 21:30:12 +11001dnl $Id: aclocal.m4,v 1.13 2014/01/22 10:30:12 djm Exp $
Damien Miller0437b332000-05-02 09:56:41 +10002dnl
3dnl OpenSSH-specific autoconf macros
4dnl
5
Damien Millerb1763622011-05-20 11:45:25 +10006dnl OSSH_CHECK_CFLAG_COMPILE(check_flag[, define_flag])
7dnl Check that $CC accepts a flag 'check_flag'. If it is supported append
8dnl 'define_flag' to $CFLAGS. If 'define_flag' is not specified, then append
9dnl 'check_flag'.
10AC_DEFUN([OSSH_CHECK_CFLAG_COMPILE], [{
Darren Tuckera6d573c2014-01-21 12:50:46 +110011 AC_MSG_CHECKING([if $CC supports compile flag $1])
Damien Millerb1763622011-05-20 11:45:25 +100012 saved_CFLAGS="$CFLAGS"
Darren Tuckerfd994372014-01-17 09:53:24 +110013 CFLAGS="$CFLAGS $WERROR $1"
Damien Millerb1763622011-05-20 11:45:25 +100014 _define_flag="$2"
15 test "x$_define_flag" = "x" && _define_flag="$1"
Damien Miller5c96a152014-01-21 13:10:26 +110016 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
17#include <stdlib.h>
18#include <stdio.h>
19int main(int argc, char **argv) {
20 /* Some math to catch -ftrapv problems in the toolchain */
21 int i = 123 * argc, j = 456 + argc, k = 789 - argc;
22 float l = i * 2.1;
23 double m = l / 0.5;
Damien Miller5c2ff5e2014-01-22 21:30:12 +110024 long long int n = argc * 12345LL, o = 12345LL * (long long int)argc;
25 printf("%d %d %d %f %f %lld %lld\n", i, j, k, l, m, n, o);
26 exit(0);
27}
28 ]])],
29 [
30if `grep -i "unrecognized option" conftest.err >/dev/null`
31then
32 AC_MSG_RESULT([no])
33 CFLAGS="$saved_CFLAGS"
34else
35 AC_MSG_RESULT([yes])
36 CFLAGS="$saved_CFLAGS $_define_flag"
37fi],
38 [ AC_MSG_RESULT([no])
39 CFLAGS="$saved_CFLAGS" ]
40 )
41}])
42
43dnl OSSH_CHECK_CFLAG_LINK(check_flag[, define_flag])
44dnl Check that $CC accepts a flag 'check_flag'. If it is supported append
45dnl 'define_flag' to $CFLAGS. If 'define_flag' is not specified, then append
46dnl 'check_flag'.
47AC_DEFUN([OSSH_CHECK_CFLAG_LINK], [{
48 AC_MSG_CHECKING([if $CC supports compile flag $1 and linking succeeds])
49 saved_CFLAGS="$CFLAGS"
50 CFLAGS="$CFLAGS $WERROR $1"
51 _define_flag="$2"
52 test "x$_define_flag" = "x" && _define_flag="$1"
53 AC_LINK_IFELSE([AC_LANG_SOURCE([[
54#include <stdlib.h>
55#include <stdio.h>
56int main(int argc, char **argv) {
57 /* Some math to catch -ftrapv problems in the toolchain */
58 int i = 123 * argc, j = 456 + argc, k = 789 - argc;
59 float l = i * 2.1;
60 double m = l / 0.5;
61 long long int n = argc * 12345LL, o = 12345LL * (long long int)argc;
62 printf("%d %d %d %f %f %lld %lld\n", i, j, k, l, m, n, o);
Damien Miller5c96a152014-01-21 13:10:26 +110063 exit(0);
64}
65 ]])],
Tim Rice01ec0af2013-06-02 14:31:27 -070066 [
67if `grep -i "unrecognized option" conftest.err >/dev/null`
68then
69 AC_MSG_RESULT([no])
70 CFLAGS="$saved_CFLAGS"
71else
72 AC_MSG_RESULT([yes])
73 CFLAGS="$saved_CFLAGS $_define_flag"
74fi],
Damien Millerb1763622011-05-20 11:45:25 +100075 [ AC_MSG_RESULT([no])
76 CFLAGS="$saved_CFLAGS" ]
77 )
78}])
79
Damien Miller5c96a152014-01-21 13:10:26 +110080dnl OSSH_CHECK_LDFLAG_LINK(check_flag[, define_flag])
Darren Tuckerfd994372014-01-17 09:53:24 +110081dnl Check that $LD accepts a flag 'check_flag'. If it is supported append
82dnl 'define_flag' to $LDFLAGS. If 'define_flag' is not specified, then append
83dnl 'check_flag'.
84AC_DEFUN([OSSH_CHECK_LDFLAG_LINK], [{
Darren Tuckera6d573c2014-01-21 12:50:46 +110085 AC_MSG_CHECKING([if $LD supports link flag $1])
Darren Tuckerfd994372014-01-17 09:53:24 +110086 saved_LDFLAGS="$LDFLAGS"
87 LDFLAGS="$LDFLAGS $WERROR $1"
88 _define_flag="$2"
89 test "x$_define_flag" = "x" && _define_flag="$1"
Damien Miller5c96a152014-01-21 13:10:26 +110090 AC_LINK_IFELSE([AC_LANG_SOURCE([[
91#include <stdlib.h>
92#include <stdio.h>
93int main(int argc, char **argv) {
94 /* Some math to catch -ftrapv problems in the toolchain */
95 int i = 123 * argc, j = 456 + argc, k = 789 - argc;
96 float l = i * 2.1;
97 double m = l / 0.5;
Damien Miller5c2ff5e2014-01-22 21:30:12 +110098 long long int n = argc * 12345LL, o = 12345LL * (long long int)argc;
99 printf("%d %d %d %f %f %lld %lld\n", i, j, k, l, m, n, o);
Damien Miller5c96a152014-01-21 13:10:26 +1100100 exit(0);
101}
102 ]])],
Darren Tuckerfd994372014-01-17 09:53:24 +1100103 [ AC_MSG_RESULT([yes])
104 LDFLAGS="$saved_LDFLAGS $_define_flag"],
105 [ AC_MSG_RESULT([no])
106 LDFLAGS="$saved_LDFLAGS" ]
107 )
108}])
Damien Miller61e50f12000-05-08 20:49:37 +1000109
110dnl OSSH_CHECK_HEADER_FOR_FIELD(field, header, symbol)
111dnl Does AC_EGREP_HEADER on 'header' for the string 'field'
112dnl If found, set 'symbol' to be defined. Cache the result.
113dnl TODO: This is not foolproof, better to compile and read from there
114AC_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 Miller8dd33fd2000-06-26 10:20:19 +1000128 ossh_result=`eval 'echo $'"$ossh_varname"`
Damien Miller61e50f12000-05-08 20:49:37 +1000129 if test -n "`echo $ossh_varname`"; then
130 AC_MSG_RESULT($ossh_result)
131 if test "x$ossh_result" = "xyes"; then
Tim Rice7df8d392005-09-19 09:33:39 -0700132 AC_DEFINE($3, 1, [Define if you have $1 in $2])
Damien Miller61e50f12000-05-08 20:49:37 +1000133 fi
134 else
135 AC_MSG_RESULT(no)
136 fi
137])
138
Tim Rice13aae5e2001-10-21 17:53:58 -0700139dnl Check for socklen_t: historically on BSD it is an int, and in
140dnl POSIX 1g it is a type of its own, but some platforms use different
141dnl types for the argument to getsockopt, getpeername, etc. So we
142dnl have to test to find something that will work.
143AC_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