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.

147 lines
4.6 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__DEAD], [1], [OpenBSD gcc has __dead])
  23. HAVE_SENSORS=true
  24. ;;
  25. *solaris*)
  26. HOST_OS=solaris
  27. CFLAGS="$CFLAGS -D__EXTENSIONS__ -D_XOPEN_SOURCE=600 -DBSD_COMP"
  28. AC_SUBST([PLATFORM_LDADD], ['-lnsl -lsocket'])
  29. ;;
  30. *) ;;
  31. esac
  32. AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin])
  33. AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd])
  34. AM_CONDITIONAL([HOST_LINUX], [test x$HOST_OS = xlinux])
  35. AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris])
  36. AM_CONDITIONAL([HAVE_SENSORS], [test x$HAVE_SENSORS = xtrue ])
  37. AC_CHECK_FUNC([clock_gettime],,
  38. [AC_SEARCH_LIBS([clock_gettime],[rt posix4])])
  39. AC_CHECK_FUNC([dl_iterate_phdr],,
  40. [AC_SEARCH_LIBS([dl_iterate_phdr],[dl])])
  41. AC_PROG_CC
  42. AC_PROG_CC_STDC
  43. AM_PROG_CC_C_O
  44. AC_PROG_LIBTOOL
  45. AC_PROG_YACC
  46. save_cflags="$CFLAGS"
  47. CFLAGS=-Wno-pointer-sign
  48. AC_MSG_CHECKING([whether CC supports -Wno-pointer-sign])
  49. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  50. [AC_MSG_RESULT([yes])]
  51. [AM_CFLAGS=-Wno-pointer-sign],
  52. [AC_MSG_RESULT([no])]
  53. )
  54. CFLAGS="$save_cflags $AM_CFLAGS"
  55. AC_MSG_CHECKING([if compiling with clang])
  56. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
  57. #ifndef __clang__
  58. not clang
  59. #endif
  60. ]])],
  61. [AC_MSG_RESULT([yes])]
  62. [CLANG_FLAGS=-Qunused-arguments],
  63. [AC_MSG_RESULT([no])]
  64. )
  65. CFLAGS="$CFLAGS $CLANG_CFLAGS"
  66. LDFLAGS="$LDFLAGS $CLANG_FLAGS"
  67. AC_CHECK_FUNCS([adjfreq arc4random_uniform asprintf explicit_bzero])
  68. AC_CHECK_FUNCS([getentropy memmem poll reallocarray])
  69. AC_CHECK_FUNCS([setproctitle setgroups])
  70. AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strtonum])
  71. AC_CHECK_FUNCS([MD5Init])
  72. # check if arc4random is in the system or in libcrypto
  73. AC_CHECK_FUNC([arc4random],,
  74. [AC_SEARCH_LIBS([arc4random],[crypto])])
  75. AC_CHECK_FUNC([ibuf_open],,
  76. [AC_SEARCH_LIBS([ibuf_open],[util])])
  77. # Share test results with automake
  78. AM_CONDITIONAL([HAVE_ADJFREQ], [test "x$ac_cv_func_adjfreq" = xyes])
  79. AM_CONDITIONAL([HAVE_ARC4RANDOM], [test "x$ac_cv_func_arc4random" = xyes])
  80. AM_CONDITIONAL([HAVE_ARC4RANDOM_UNIFORM], [test "x$ac_cv_func_arc4random_uniform" = xyes])
  81. AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = 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_MEMMEM], [test "x$ac_cv_func_memmem" = xyes])
  85. AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes])
  86. AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes])
  87. AM_CONDITIONAL([HAVE_SETGROUPS], [test "x$ac_cv_func_setgroups" = xyes])
  88. AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
  89. AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes])
  90. AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
  91. AM_CONDITIONAL([HAVE_STRNDUP], [test "x$ac_cv_func_strndup" = xyes])
  92. AM_CONDITIONAL([HAVE_STRNLEN], [test "x$ac_cv_func_strnlen" = xyes])
  93. AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes])
  94. AM_CONDITIONAL([HAVE_MD5], [test "x$ac_cv_func_MD5Init" = xyes])
  95. AM_CONDITIONAL([HAVE_IMSG], [test "x$ac_cv_func_ibuf_open" = xyes])
  96. # overrides for arc4random_buf implementations with known issues
  97. AM_CONDITIONAL([HAVE_ARC4RANDOM],
  98. [test "x$HOST_OS" != xdarwin -a "x$HOST_OS" != xfreebsd -a "x$ac_cv_func_arc4random" = xyes])
  99. AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [
  100. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  101. #include <stdarg.h>
  102. va_list x,y;
  103. ]], [[ va_copy(x,y); ]])],
  104. [ ac_cv_have_va_copy="yes" ],
  105. [ ac_cv_have_va_copy="no"
  106. ])
  107. ])
  108. if test "x$ac_cv_have_va_copy" = "xyes" ; then
  109. AC_DEFINE([HAVE_VA_COPY], [1], [Define if va_copy exists])
  110. fi
  111. AC_CACHE_CHECK([whether __va_copy exists], ac_cv_have___va_copy, [
  112. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  113. #include <stdarg.h>
  114. va_list x,y;
  115. ]], [[ __va_copy(x,y); ]])],
  116. [ ac_cv_have___va_copy="yes" ], [ ac_cv_have___va_copy="no"
  117. ])
  118. ])
  119. if test "x$ac_cv_have___va_copy" = "xyes" ; then
  120. AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists])
  121. fi
  122. AC_CHECK_HEADERS([sys/timex.h])
  123. AC_CONFIG_FILES([
  124. Makefile
  125. include/Makefile
  126. ])
  127. AC_OUTPUT