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.

149 lines
4.7 KiB

  1. AC_INIT([OpenNTPD], m4_esyscmd([tr -d '\n' < VERSION]))
  2. AC_CANONICAL_HOST
  3. AM_INIT_AUTOMAKE([subdir-objects])
  4. AC_CONFIG_MACRO_DIR([m4])
  5. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
  6. AC_SUBST([USER_CFLAGS], "$CFLAGS")
  7. CFLAGS="$CFLAGS -Wall -std=gnu99 -g"
  8. case $host_os in
  9. *darwin*)
  10. HOST_OS=darwin
  11. ;;
  12. *freebsd*)
  13. HOST_OS=freebsd
  14. AC_SUBST([PROG_LDADD], ['-lthr'])
  15. ;;
  16. *linux*)
  17. HOST_OS=linux
  18. CFLAGS="$CFLAGS -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE"
  19. ;;
  20. *openbsd*)
  21. AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD gcc has __bounded__])
  22. AC_DEFINE([HAVE_ATTRIBUTE__WEAK_ALIAS], [1], [OpenBSD gcc has __weak_alias])
  23. AC_DEFINE([HAVE_ATTRIBUTE__DEAD], [1], [OpenBSD gcc has __dead])
  24. HAVE_SENSORS=true
  25. ;;
  26. *solaris*)
  27. HOST_OS=solaris
  28. CFLAGS="$CFLAGS -D__EXTENSIONS__ -D_XOPEN_SOURCE=600 -DBSD_COMP"
  29. AC_SUBST([PLATFORM_LDADD], ['-lnsl -lsocket'])
  30. ;;
  31. *) ;;
  32. esac
  33. AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin])
  34. AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd])
  35. AM_CONDITIONAL([HOST_LINUX], [test x$HOST_OS = xlinux])
  36. AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris])
  37. AM_CONDITIONAL([HAVE_SENSORS], [test x$HAVE_SENSORS = xtrue ])
  38. AC_CHECK_FUNC([clock_gettime],,
  39. [AC_SEARCH_LIBS([clock_gettime],[rt posix4])])
  40. AC_CHECK_FUNC([dl_iterate_phdr],,
  41. [AC_SEARCH_LIBS([dl_iterate_phdr],[dl])])
  42. AC_PROG_CC
  43. AC_PROG_CC_STDC
  44. AM_PROG_CC_C_O
  45. AC_PROG_LIBTOOL
  46. AC_PROG_YACC
  47. save_cflags="$CFLAGS"
  48. CFLAGS=-Wno-pointer-sign
  49. AC_MSG_CHECKING([whether CC supports -Wno-pointer-sign])
  50. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  51. [AC_MSG_RESULT([yes])]
  52. [AM_CFLAGS=-Wno-pointer-sign],
  53. [AC_MSG_RESULT([no])]
  54. )
  55. CFLAGS="$save_cflags $AM_CFLAGS"
  56. AC_MSG_CHECKING([if compiling with clang])
  57. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
  58. #ifndef __clang__
  59. not clang
  60. #endif
  61. ]])],
  62. [AC_MSG_RESULT([yes])]
  63. [CLANG_FLAGS=-Qunused-arguments],
  64. [AC_MSG_RESULT([no])]
  65. )
  66. CFLAGS="$CFLAGS $CLANG_CFLAGS"
  67. LDFLAGS="$LDFLAGS $CLANG_FLAGS"
  68. AC_CHECK_FUNCS([adjfreq arc4random_uniform asprintf explicit_bzero])
  69. AC_CHECK_FUNCS([getentropy memmem poll reallocarray])
  70. AC_CHECK_FUNCS([setproctitle setgroups])
  71. AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strtonum])
  72. AC_CHECK_FUNCS([MD5Init SHA512Init])
  73. # check if arc4random is in the system or in libcrypto
  74. AC_CHECK_FUNC([arc4random],,
  75. [AC_SEARCH_LIBS([arc4random],[crypto])])
  76. AC_CHECK_FUNC([ibuf_open],,
  77. [AC_SEARCH_LIBS([ibuf_open],[util])])
  78. # Share test results with automake
  79. AM_CONDITIONAL([HAVE_ADJFREQ], [test "x$ac_cv_func_adjfreq" = xyes])
  80. AM_CONDITIONAL([HAVE_ARC4RANDOM], [test "x$ac_cv_func_arc4random" = xyes])
  81. AM_CONDITIONAL([HAVE_ARC4RANDOM_UNIFORM], [test "x$ac_cv_func_arc4random_uniform" = xyes])
  82. AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes])
  83. AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes])
  84. AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes])
  85. AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes])
  86. AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes])
  87. AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes])
  88. AM_CONDITIONAL([HAVE_SETGROUPS], [test "x$ac_cv_func_setgroups" = xyes])
  89. AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
  90. AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes])
  91. AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
  92. AM_CONDITIONAL([HAVE_STRNDUP], [test "x$ac_cv_func_strndup" = xyes])
  93. AM_CONDITIONAL([HAVE_STRNLEN], [test "x$ac_cv_func_strnlen" = xyes])
  94. AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes])
  95. AM_CONDITIONAL([HAVE_MD5], [test "x$ac_cv_func_MD5Init" = xyes])
  96. AM_CONDITIONAL([HAVE_SHA512], [test "x$ac_cv_func_SHA512Init" = xyes])
  97. AM_CONDITIONAL([HAVE_IMSG], [test "x$ac_cv_func_ibuf_open" = xyes])
  98. # overrides for arc4random_buf implementations with known issues
  99. AM_CONDITIONAL([HAVE_ARC4RANDOM],
  100. [test "x$HOST_OS" != xdarwin -a "x$HOST_OS" != xfreebsd -a "x$ac_cv_func_arc4random" = xyes])
  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. AC_CHECK_HEADERS([sys/timex.h md5.h sha2.h])
  125. AC_CONFIG_FILES([
  126. Makefile
  127. include/Makefile
  128. ])
  129. AC_OUTPUT