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.

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