Portable build framework for OpenNTPD
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
4.4 KiB

  1. AC_DEFUN([CHECK_PROGNAME], [
  2. AC_CACHE_CHECK([if libc defines __progname], ac_cv_libc_defines___progname, [
  3. AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
  4. [[ extern char *__progname; printf("%s", __progname); ]])],
  5. [ ac_cv_libc_defines___progname="yes" ],
  6. [ ac_cv_libc_defines___progname="no"
  7. ])
  8. ])
  9. if test "x$ac_cv_libc_defines___progname" = "xyes" ; then
  10. AC_DEFINE([HAVE___PROGNAME], [1], [Define if libc defines __progname])
  11. fi
  12. ])
  13. AC_DEFUN([CHECK_SYSCALL_COMPAT], [
  14. AC_CHECK_FUNCS([accept4 pipe2 pledge poll socketpair])
  15. AM_CONDITIONAL([HAVE_ACCEPT4], [test "x$ac_cv_func_accept4" = xyes])
  16. AM_CONDITIONAL([HAVE_PIPE2], [test "x$ac_cv_func_pipe2" = xyes])
  17. AM_CONDITIONAL([HAVE_PLEDGE], [test "x$ac_cv_func_pledge" = xyes])
  18. AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes])
  19. AM_CONDITIONAL([HAVE_SOCKETPAIR], [test "x$ac_cv_func_socketpair" = xyes])
  20. ])
  21. AC_DEFUN([CHECK_B64_NTOP], [
  22. AC_SEARCH_LIBS([b64_ntop],[resolv])
  23. AC_SEARCH_LIBS([__b64_ntop],[resolv])
  24. AC_CACHE_CHECK([for b64_ntop], ac_cv_have_b64_ntop_arg, [
  25. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  26. #include <sys/types.h>
  27. #include <sys/socket.h>
  28. #include <netinet/in.h>
  29. #include <arpa/inet.h>
  30. #include <resolv.h>
  31. ]], [[ b64_ntop(NULL, 0, NULL, 0); ]])],
  32. [ ac_cv_have_b64_ntop_arg="yes" ],
  33. [ ac_cv_have_b64_ntop_arg="no"
  34. ])
  35. ])
  36. AM_CONDITIONAL([HAVE_B64_NTOP], [test "x$ac_cv_func_b64_ntop_arg" = xyes])
  37. ])
  38. AC_DEFUN([CHECK_CRYPTO_COMPAT], [
  39. # Check crypto-related libc functions and syscalls
  40. AC_CHECK_FUNCS([arc4random arc4random_buf arc4random_uniform])
  41. AC_CHECK_FUNCS([explicit_bzero getauxval])
  42. AC_CACHE_CHECK([for getentropy], ac_cv_func_getentropy, [
  43. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  44. #include <sys/types.h>
  45. #include <unistd.h>
  46. /*
  47. * Explanation:
  48. *
  49. * - iOS <= 10.1 fails because of missing sys/random.h
  50. *
  51. * - in macOS 10.12 getentropy is not tagged as introduced in
  52. * 10.12 so we cannot use it for target < 10.12
  53. */
  54. #ifdef __APPLE__
  55. # include <AvailabilityMacros.h>
  56. # include <TargetConditionals.h>
  57. # if (TARGET_OS_IPHONE || TARGET_OS_SIMULATOR)
  58. # include <sys/random.h> /* Not available as of iOS <= 10.1 */
  59. # else
  60. # include <sys/random.h> /* Pre 10.12 systems should die here */
  61. /* Based on: https://gitweb.torproject.org/tor.git/commit/?id=16fcbd21 */
  62. # ifndef MAC_OS_X_VERSION_10_12
  63. # define MAC_OS_X_VERSION_10_12 101200 /* Robustness */
  64. # endif
  65. # if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
  66. # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
  67. # error "Targeting on Mac OSX 10.11 or earlier"
  68. # endif
  69. # endif
  70. # endif
  71. #endif /* __APPLE__ */
  72. ]], [[
  73. char buffer;
  74. (void)getentropy(&buffer, sizeof (buffer));
  75. ]])],
  76. [ ac_cv_func_getentropy="yes" ],
  77. [ ac_cv_func_getentropy="no"
  78. ])
  79. ])
  80. AC_CHECK_FUNCS([timingsafe_bcmp timingsafe_memcmp])
  81. AM_CONDITIONAL([HAVE_ARC4RANDOM], [test "x$ac_cv_func_arc4random" = xyes])
  82. AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], [test "x$ac_cv_func_arc4random_buf" = xyes])
  83. AM_CONDITIONAL([HAVE_ARC4RANDOM_UNIFORM], [test "x$ac_cv_func_arc4random_uniform" = xyes])
  84. AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes])
  85. AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes])
  86. AM_CONDITIONAL([HAVE_TIMINGSAFE_BCMP], [test "x$ac_cv_func_timingsafe_bcmp" = xyes])
  87. AM_CONDITIONAL([HAVE_TIMINGSAFE_MEMCMP], [test "x$ac_cv_func_timingsafe_memcmp" = xyes])
  88. # Override arc4random_buf implementations with known issues
  89. AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF],
  90. [test "x$USE_BUILTIN_ARC4RANDOM" != xyes \
  91. -a "x$ac_cv_func_arc4random_buf" = xyes])
  92. # Check for getentropy fallback dependencies
  93. AC_CHECK_FUNC([getauxval])
  94. AC_SEARCH_LIBS([clock_gettime],[rt posix4])
  95. AC_CHECK_FUNC([clock_gettime])
  96. AC_SEARCH_LIBS([dl_iterate_phdr],[dl])
  97. AC_CHECK_FUNC([dl_iterate_phdr])
  98. ])
  99. AC_DEFUN([CHECK_VA_COPY], [
  100. AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [
  101. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  102. #include <stdarg.h>
  103. va_list x,y;
  104. ]], [[ va_copy(x,y); ]])],
  105. [ ac_cv_have_va_copy="yes" ],
  106. [ ac_cv_have_va_copy="no"
  107. ])
  108. ])
  109. if test "x$ac_cv_have_va_copy" = "xyes" ; then
  110. AC_DEFINE([HAVE_VA_COPY], [1], [Define if va_copy exists])
  111. fi
  112. AC_CACHE_CHECK([whether __va_copy exists], ac_cv_have___va_copy, [
  113. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  114. #include <stdarg.h>
  115. va_list x,y;
  116. ]], [[ __va_copy(x,y); ]])],
  117. [ ac_cv_have___va_copy="yes" ], [ ac_cv_have___va_copy="no"
  118. ])
  119. ])
  120. if test "x$ac_cv_have___va_copy" = "xyes" ; then
  121. AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists])
  122. fi
  123. ])