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.

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