openssh.m4 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. dnl OpenSSH-specific autoconf macros
  2. dnl
  3. dnl OSSH_CHECK_CFLAG_COMPILE(check_flag[, define_flag])
  4. dnl Check that $CC accepts a flag 'check_flag'. If it is supported append
  5. dnl 'define_flag' to $CFLAGS. If 'define_flag' is not specified, then append
  6. dnl 'check_flag'.
  7. AC_DEFUN([OSSH_CHECK_CFLAG_COMPILE], [{
  8. AC_MSG_CHECKING([if $CC supports compile flag $1])
  9. saved_CFLAGS="$CFLAGS"
  10. CFLAGS="$CFLAGS $WERROR $1"
  11. _define_flag="$2"
  12. test "x$_define_flag" = "x" && _define_flag="$1"
  13. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. int main(int argc, char **argv) {
  17. (void)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;
  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. /*
  25. * Test fallthrough behaviour. clang 10's -Wimplicit-fallthrough does
  26. * not understand comments and we don't use the "fallthrough" attribute
  27. * that it's looking for.
  28. */
  29. switch(i){
  30. case 0: j += i;
  31. /* FALLTHROUGH */
  32. default: j += k;
  33. }
  34. exit(0);
  35. }
  36. ]])],
  37. [
  38. if $ac_cv_path_EGREP -i "unrecognized option|warning.*ignored" conftest.err >/dev/null
  39. then
  40. AC_MSG_RESULT([no])
  41. CFLAGS="$saved_CFLAGS"
  42. else
  43. AC_MSG_RESULT([yes])
  44. CFLAGS="$saved_CFLAGS $_define_flag"
  45. fi],
  46. [ AC_MSG_RESULT([no])
  47. CFLAGS="$saved_CFLAGS" ]
  48. )
  49. }])
  50. dnl OSSH_CHECK_CFLAG_LINK(check_flag[, define_flag])
  51. dnl Check that $CC accepts a flag 'check_flag'. If it is supported append
  52. dnl 'define_flag' to $CFLAGS. If 'define_flag' is not specified, then append
  53. dnl 'check_flag'.
  54. AC_DEFUN([OSSH_CHECK_CFLAG_LINK], [{
  55. AC_MSG_CHECKING([if $CC supports compile flag $1 and linking succeeds])
  56. saved_CFLAGS="$CFLAGS"
  57. CFLAGS="$CFLAGS $WERROR $1"
  58. _define_flag="$2"
  59. test "x$_define_flag" = "x" && _define_flag="$1"
  60. AC_LINK_IFELSE([AC_LANG_SOURCE([[
  61. #include <stdlib.h>
  62. #include <stdio.h>
  63. int main(int argc, char **argv) {
  64. (void)argv;
  65. /* Some math to catch -ftrapv problems in the toolchain */
  66. int i = 123 * argc, j = 456 + argc, k = 789 - argc;
  67. float l = i * 2.1;
  68. double m = l / 0.5;
  69. long long int n = argc * 12345LL, o = 12345LL * (long long int)argc;
  70. long long int p = n * o;
  71. printf("%d %d %d %f %f %lld %lld %lld\n", i, j, k, l, m, n, o, p);
  72. exit(0);
  73. }
  74. ]])],
  75. [
  76. if $ac_cv_path_EGREP -i "unrecognized option|warning.*ignored" conftest.err >/dev/null
  77. then
  78. AC_MSG_RESULT([no])
  79. CFLAGS="$saved_CFLAGS"
  80. else
  81. AC_MSG_RESULT([yes])
  82. CFLAGS="$saved_CFLAGS $_define_flag"
  83. fi],
  84. [ AC_MSG_RESULT([no])
  85. CFLAGS="$saved_CFLAGS" ]
  86. )
  87. }])
  88. dnl OSSH_CHECK_LDFLAG_LINK(check_flag[, define_flag])
  89. dnl Check that $LD accepts a flag 'check_flag'. If it is supported append
  90. dnl 'define_flag' to $LDFLAGS. If 'define_flag' is not specified, then append
  91. dnl 'check_flag'.
  92. AC_DEFUN([OSSH_CHECK_LDFLAG_LINK], [{
  93. AC_MSG_CHECKING([if $LD supports link flag $1])
  94. saved_LDFLAGS="$LDFLAGS"
  95. LDFLAGS="$LDFLAGS $WERROR $1"
  96. _define_flag="$2"
  97. test "x$_define_flag" = "x" && _define_flag="$1"
  98. AC_LINK_IFELSE([AC_LANG_SOURCE([[
  99. #include <stdlib.h>
  100. #include <stdio.h>
  101. int main(int argc, char **argv) {
  102. (void)argv;
  103. /* Some math to catch -ftrapv problems in the toolchain */
  104. int i = 123 * argc, j = 456 + argc, k = 789 - argc;
  105. float l = i * 2.1;
  106. double m = l / 0.5;
  107. long long int n = argc * 12345LL, o = 12345LL * (long long int)argc;
  108. long long p = n * o;
  109. printf("%d %d %d %f %f %lld %lld %lld\n", i, j, k, l, m, n, o, p);
  110. exit(0);
  111. }
  112. ]])],
  113. [
  114. if $ac_cv_path_EGREP -i "unrecognized option|warning.*ignored" conftest.err >/dev/null
  115. then
  116. AC_MSG_RESULT([no])
  117. LDFLAGS="$saved_LDFLAGS"
  118. else
  119. AC_MSG_RESULT([yes])
  120. LDFLAGS="$saved_LDFLAGS $_define_flag"
  121. fi ],
  122. [ AC_MSG_RESULT([no])
  123. LDFLAGS="$saved_LDFLAGS" ]
  124. )
  125. }])
  126. dnl OSSH_CHECK_HEADER_FOR_FIELD(field, header, symbol)
  127. dnl Does AC_EGREP_HEADER on 'header' for the string 'field'
  128. dnl If found, set 'symbol' to be defined. Cache the result.
  129. dnl TODO: This is not foolproof, better to compile and read from there
  130. AC_DEFUN([OSSH_CHECK_HEADER_FOR_FIELD], [
  131. # look for field '$1' in header '$2'
  132. dnl This strips characters illegal to m4 from the header filename
  133. ossh_safe=`echo "$2" | sed 'y%./+-%__p_%'`
  134. dnl
  135. ossh_varname="ossh_cv_$ossh_safe""_has_"$1
  136. AC_MSG_CHECKING(for $1 field in $2)
  137. AC_CACHE_VAL($ossh_varname, [
  138. AC_EGREP_HEADER($1, $2, [ dnl
  139. eval "$ossh_varname=yes" dnl
  140. ], [ dnl
  141. eval "$ossh_varname=no" dnl
  142. ]) dnl
  143. ])
  144. ossh_result=`eval 'echo $'"$ossh_varname"`
  145. if test -n "`echo $ossh_varname`"; then
  146. AC_MSG_RESULT($ossh_result)
  147. if test "x$ossh_result" = "xyes"; then
  148. AC_DEFINE($3, 1, [Define if you have $1 in $2])
  149. fi
  150. else
  151. AC_MSG_RESULT(no)
  152. fi
  153. ])
  154. dnl Check for socklen_t: historically on BSD it is an int, and in
  155. dnl POSIX 1g it is a type of its own, but some platforms use different
  156. dnl types for the argument to getsockopt, getpeername, etc. So we
  157. dnl have to test to find something that will work.
  158. AC_DEFUN([TYPE_SOCKLEN_T],
  159. [
  160. AC_CHECK_TYPE([socklen_t], ,[
  161. AC_MSG_CHECKING([for socklen_t equivalent])
  162. AC_CACHE_VAL([curl_cv_socklen_t_equiv],
  163. [
  164. # Systems have either "struct sockaddr *" or
  165. # "void *" as the second argument to getpeername
  166. curl_cv_socklen_t_equiv=
  167. for arg2 in "struct sockaddr" void; do
  168. for t in int size_t unsigned long "unsigned long"; do
  169. AC_COMPILE_IFELSE([
  170. AC_LANG_PROGRAM([[
  171. #include <sys/types.h>
  172. #include <sys/socket.h>
  173. int getpeername (int, $arg2 *, $t *);
  174. ]], [[
  175. $t len;
  176. getpeername(0,0,&len);
  177. ]])
  178. ],[
  179. curl_cv_socklen_t_equiv="$t"
  180. break
  181. ])
  182. done
  183. done
  184. if test "x$curl_cv_socklen_t_equiv" = x; then
  185. AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
  186. fi
  187. ])
  188. AC_MSG_RESULT($curl_cv_socklen_t_equiv)
  189. AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
  190. [type to use in place of socklen_t if not defined])],
  191. [#include <sys/types.h>
  192. #include <sys/socket.h>])
  193. ])