1263970Sdesdnl $Id: aclocal.m4,v 1.13 2014/01/22 10:30:12 djm Exp $
298937Sdesdnl
398937Sdesdnl OpenSSH-specific autoconf macros
498937Sdesdnl
598937Sdes
6247485Sdesdnl OSSH_CHECK_CFLAG_COMPILE(check_flag[, define_flag])
7247485Sdesdnl Check that $CC accepts a flag 'check_flag'. If it is supported append
8247485Sdesdnl 'define_flag' to $CFLAGS. If 'define_flag' is not specified, then append
9247485Sdesdnl 'check_flag'.
10247485SdesAC_DEFUN([OSSH_CHECK_CFLAG_COMPILE], [{
11263970Sdes	AC_MSG_CHECKING([if $CC supports compile flag $1])
12247485Sdes	saved_CFLAGS="$CFLAGS"
13263970Sdes	CFLAGS="$CFLAGS $WERROR $1"
14247485Sdes	_define_flag="$2"
15247485Sdes	test "x$_define_flag" = "x" && _define_flag="$1"
16263970Sdes	AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
17263970Sdes#include <stdlib.h>
18263970Sdes#include <stdio.h>
19263970Sdesint main(int argc, char **argv) {
20263970Sdes	/* Some math to catch -ftrapv problems in the toolchain */
21263970Sdes	int i = 123 * argc, j = 456 + argc, k = 789 - argc;
22263970Sdes	float l = i * 2.1;
23263970Sdes	double m = l / 0.5;
24263970Sdes	long long int n = argc * 12345LL, o = 12345LL * (long long int)argc;
25263970Sdes	printf("%d %d %d %f %f %lld %lld\n", i, j, k, l, m, n, o);
26263970Sdes	exit(0);
27263970Sdes}
28263970Sdes	]])],
29263970Sdes		[
30263970Sdesif `grep -i "unrecognized option" conftest.err >/dev/null`
31263970Sdesthen
32263970Sdes		AC_MSG_RESULT([no])
33263970Sdes		CFLAGS="$saved_CFLAGS"
34263970Sdeselse
35263970Sdes		AC_MSG_RESULT([yes])
36263970Sdes		 CFLAGS="$saved_CFLAGS $_define_flag"
37263970Sdesfi],
38247485Sdes		[ AC_MSG_RESULT([no])
39247485Sdes		  CFLAGS="$saved_CFLAGS" ]
40247485Sdes	)
41247485Sdes}])
4298937Sdes
43263970Sdesdnl OSSH_CHECK_CFLAG_LINK(check_flag[, define_flag])
44263970Sdesdnl Check that $CC accepts a flag 'check_flag'. If it is supported append
45263970Sdesdnl 'define_flag' to $CFLAGS. If 'define_flag' is not specified, then append
46263970Sdesdnl 'check_flag'.
47263970SdesAC_DEFUN([OSSH_CHECK_CFLAG_LINK], [{
48263970Sdes	AC_MSG_CHECKING([if $CC supports compile flag $1 and linking succeeds])
49263970Sdes	saved_CFLAGS="$CFLAGS"
50263970Sdes	CFLAGS="$CFLAGS $WERROR $1"
51263970Sdes	_define_flag="$2"
52263970Sdes	test "x$_define_flag" = "x" && _define_flag="$1"
53263970Sdes	AC_LINK_IFELSE([AC_LANG_SOURCE([[
54263970Sdes#include <stdlib.h>
55263970Sdes#include <stdio.h>
56263970Sdesint main(int argc, char **argv) {
57263970Sdes	/* Some math to catch -ftrapv problems in the toolchain */
58263970Sdes	int i = 123 * argc, j = 456 + argc, k = 789 - argc;
59263970Sdes	float l = i * 2.1;
60263970Sdes	double m = l / 0.5;
61263970Sdes	long long int n = argc * 12345LL, o = 12345LL * (long long int)argc;
62263970Sdes	printf("%d %d %d %f %f %lld %lld\n", i, j, k, l, m, n, o);
63263970Sdes	exit(0);
64263970Sdes}
65263970Sdes	]])],
66263970Sdes		[
67263970Sdesif `grep -i "unrecognized option" conftest.err >/dev/null`
68263970Sdesthen
69263970Sdes		AC_MSG_RESULT([no])
70263970Sdes		CFLAGS="$saved_CFLAGS"
71263970Sdeselse
72263970Sdes		AC_MSG_RESULT([yes])
73263970Sdes		 CFLAGS="$saved_CFLAGS $_define_flag"
74263970Sdesfi],
75263970Sdes		[ AC_MSG_RESULT([no])
76263970Sdes		  CFLAGS="$saved_CFLAGS" ]
77263970Sdes	)
78263970Sdes}])
79247485Sdes
80263970Sdesdnl OSSH_CHECK_LDFLAG_LINK(check_flag[, define_flag])
81263970Sdesdnl Check that $LD accepts a flag 'check_flag'. If it is supported append
82263970Sdesdnl 'define_flag' to $LDFLAGS. If 'define_flag' is not specified, then append
83263970Sdesdnl 'check_flag'.
84263970SdesAC_DEFUN([OSSH_CHECK_LDFLAG_LINK], [{
85263970Sdes	AC_MSG_CHECKING([if $LD supports link flag $1])
86263970Sdes	saved_LDFLAGS="$LDFLAGS"
87263970Sdes	LDFLAGS="$LDFLAGS $WERROR $1"
88263970Sdes	_define_flag="$2"
89263970Sdes	test "x$_define_flag" = "x" && _define_flag="$1"
90263970Sdes	AC_LINK_IFELSE([AC_LANG_SOURCE([[
91263970Sdes#include <stdlib.h>
92263970Sdes#include <stdio.h>
93263970Sdesint main(int argc, char **argv) {
94263970Sdes	/* Some math to catch -ftrapv problems in the toolchain */
95263970Sdes	int i = 123 * argc, j = 456 + argc, k = 789 - argc;
96263970Sdes	float l = i * 2.1;
97263970Sdes	double m = l / 0.5;
98263970Sdes	long long int n = argc * 12345LL, o = 12345LL * (long long int)argc;
99263970Sdes	printf("%d %d %d %f %f %lld %lld\n", i, j, k, l, m, n, o);
100263970Sdes	exit(0);
101263970Sdes}
102263970Sdes		]])],
103263970Sdes		[ AC_MSG_RESULT([yes])
104263970Sdes		  LDFLAGS="$saved_LDFLAGS $_define_flag"],
105263970Sdes		[ AC_MSG_RESULT([no])
106263970Sdes		  LDFLAGS="$saved_LDFLAGS" ]
107263970Sdes	)
108263970Sdes}])
109263970Sdes
11098937Sdesdnl OSSH_CHECK_HEADER_FOR_FIELD(field, header, symbol)
11198937Sdesdnl Does AC_EGREP_HEADER on 'header' for the string 'field'
11298937Sdesdnl If found, set 'symbol' to be defined. Cache the result.
11398937Sdesdnl TODO: This is not foolproof, better to compile and read from there
11498937SdesAC_DEFUN(OSSH_CHECK_HEADER_FOR_FIELD, [
11598937Sdes# look for field '$1' in header '$2'
11698937Sdes	dnl This strips characters illegal to m4 from the header filename
11798937Sdes	ossh_safe=`echo "$2" | sed 'y%./+-%__p_%'`
11898937Sdes	dnl
11998937Sdes	ossh_varname="ossh_cv_$ossh_safe""_has_"$1
12098937Sdes	AC_MSG_CHECKING(for $1 field in $2)
12198937Sdes	AC_CACHE_VAL($ossh_varname, [
12298937Sdes		AC_EGREP_HEADER($1, $2, [ dnl
12398937Sdes			eval "$ossh_varname=yes" dnl
12498937Sdes		], [ dnl
12598937Sdes			eval "$ossh_varname=no" dnl
12698937Sdes		]) dnl
12798937Sdes	])
12898937Sdes	ossh_result=`eval 'echo $'"$ossh_varname"`
12998937Sdes	if test -n "`echo $ossh_varname`"; then
13098937Sdes		AC_MSG_RESULT($ossh_result)
13198937Sdes		if test "x$ossh_result" = "xyes"; then
132157016Sdes			AC_DEFINE($3, 1, [Define if you have $1 in $2])
13398937Sdes		fi
13498937Sdes	else
13598937Sdes		AC_MSG_RESULT(no)
13698937Sdes	fi
13798937Sdes])
13898937Sdes
13998937Sdesdnl Check for socklen_t: historically on BSD it is an int, and in
14098937Sdesdnl POSIX 1g it is a type of its own, but some platforms use different
14198937Sdesdnl types for the argument to getsockopt, getpeername, etc.  So we
14298937Sdesdnl have to test to find something that will work.
14398937SdesAC_DEFUN([TYPE_SOCKLEN_T],
14498937Sdes[
14598937Sdes   AC_CHECK_TYPE([socklen_t], ,[
14698937Sdes      AC_MSG_CHECKING([for socklen_t equivalent])
14798937Sdes      AC_CACHE_VAL([curl_cv_socklen_t_equiv],
14898937Sdes      [
14998937Sdes	 # Systems have either "struct sockaddr *" or
15098937Sdes	 # "void *" as the second argument to getpeername
15198937Sdes	 curl_cv_socklen_t_equiv=
15298937Sdes	 for arg2 in "struct sockaddr" void; do
15398937Sdes	    for t in int size_t unsigned long "unsigned long"; do
15498937Sdes	       AC_TRY_COMPILE([
15598937Sdes		  #include <sys/types.h>
15698937Sdes		  #include <sys/socket.h>
15798937Sdes
15898937Sdes		  int getpeername (int, $arg2 *, $t *);
15998937Sdes	       ],[
16098937Sdes		  $t len;
16198937Sdes		  getpeername(0,0,&len);
16298937Sdes	       ],[
16398937Sdes		  curl_cv_socklen_t_equiv="$t"
16498937Sdes		  break
16598937Sdes	       ])
16698937Sdes	    done
16798937Sdes	 done
16898937Sdes
16998937Sdes	 if test "x$curl_cv_socklen_t_equiv" = x; then
17098937Sdes	    AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
17198937Sdes	 fi
17298937Sdes      ])
17398937Sdes      AC_MSG_RESULT($curl_cv_socklen_t_equiv)
17498937Sdes      AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
17598937Sdes			[type to use in place of socklen_t if not defined])],
17698937Sdes      [#include <sys/types.h>
17798937Sdes#include <sys/socket.h>])
17898937Sdes])
17998937Sdes
180