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.

151 lines
4.8 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 has __bounded__])
  22. AC_DEFINE([HAVE_ATTRIBUTE__DEAD], [1], [OpenBSD has __dead])
  23. ;;
  24. *solaris*)
  25. HOST_OS=solaris
  26. CFLAGS="$CFLAGS -D__EXTENSIONS__ -D_XOPEN_SOURCE=600 -DBSD_COMP"
  27. AC_SUBST([PLATFORM_LDADD], ['-lnsl -lsocket'])
  28. ;;
  29. *) ;;
  30. esac
  31. AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin])
  32. AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd])
  33. AM_CONDITIONAL([HOST_LINUX], [test x$HOST_OS = xlinux])
  34. AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris])
  35. AC_CHECK_FUNC([clock_gettime],,
  36. [AC_SEARCH_LIBS([clock_gettime],[rt posix4])])
  37. AC_CHECK_FUNC([dl_iterate_phdr],,
  38. [AC_SEARCH_LIBS([dl_iterate_phdr],[dl])])
  39. AC_PROG_CC
  40. AC_PROG_CC_STDC
  41. AM_PROG_CC_C_O
  42. AC_PROG_LIBTOOL
  43. AC_PROG_YACC
  44. save_cflags="$CFLAGS"
  45. CFLAGS=-Wno-pointer-sign
  46. AC_MSG_CHECKING([whether CC supports -Wno-pointer-sign])
  47. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  48. [AC_MSG_RESULT([yes])]
  49. [AM_CFLAGS=-Wno-pointer-sign],
  50. [AC_MSG_RESULT([no])]
  51. )
  52. CFLAGS="$save_cflags $AM_CFLAGS"
  53. AC_MSG_CHECKING([if compiling with clang])
  54. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
  55. #ifndef __clang__
  56. not clang
  57. #endif
  58. ]])],
  59. [AC_MSG_RESULT([yes])]
  60. [CLANG_FLAGS=-Qunused-arguments],
  61. [AC_MSG_RESULT([no])]
  62. )
  63. CFLAGS="$CFLAGS $CLANG_CFLAGS"
  64. LDFLAGS="$LDFLAGS $CLANG_FLAGS"
  65. # check functions that are expected to be in libc
  66. AC_CHECK_FUNCS([adjfreq arc4random_uniform asprintf explicit_bzero])
  67. AC_CHECK_FUNCS([getentropy memmem poll reallocarray])
  68. AC_CHECK_FUNCS([setproctitle setgroups])
  69. AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strtonum])
  70. # check auxiliary libraries that might contain other functions
  71. AC_SEARCH_LIBS([arc4random], [crypto])
  72. AC_SEARCH_LIBS([ibuf_open], [util])
  73. AC_SEARCH_LIBS([MD5Init], [md])
  74. AC_SEARCH_LIBS([SHA512Init], [md])
  75. AC_CHECK_FUNCS([arc4random ibuf_open MD5Init SHA512Init])
  76. # Share test results with automake
  77. AM_CONDITIONAL([HAVE_ADJFREQ], [test "x$ac_cv_func_adjfreq" = xyes])
  78. AM_CONDITIONAL([HAVE_ARC4RANDOM], [test "x$ac_cv_func_arc4random" = xyes])
  79. AM_CONDITIONAL([HAVE_ARC4RANDOM_UNIFORM], [test "x$ac_cv_func_arc4random_uniform" = xyes])
  80. AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes])
  81. AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes])
  82. AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes])
  83. AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes])
  84. AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes])
  85. AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes])
  86. AM_CONDITIONAL([HAVE_SETGROUPS], [test "x$ac_cv_func_setgroups" = xyes])
  87. AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
  88. AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes])
  89. AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
  90. AM_CONDITIONAL([HAVE_STRNDUP], [test "x$ac_cv_func_strndup" = xyes])
  91. AM_CONDITIONAL([HAVE_STRNLEN], [test "x$ac_cv_func_strnlen" = xyes])
  92. AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes])
  93. AM_CONDITIONAL([HAVE_MD5], [test "x$ac_cv_func_MD5Init" = xyes])
  94. AM_CONDITIONAL([HAVE_SHA512], [test "x$ac_cv_func_SHA512Init" = 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 md5.h sha2.h])
  123. AC_CHECK_HEADERS([sys/sensors.h],
  124. AM_CONDITIONAL(HAVE_SENSORS, true),
  125. AM_CONDITIONAL(HAVE_SENSORS, false)
  126. )
  127. AC_CONFIG_FILES([
  128. Makefile
  129. include/Makefile
  130. ])
  131. AC_OUTPUT