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 has __bounded__])
  22. AC_DEFINE([HAVE_ATTRIBUTE__DEAD], [1], [OpenBSD 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. # check functions that are expected to be in libc
  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. # check auxiliary libraries that might contain other functions
  73. AC_SEARCH_LIBS([arc4random], [crypto])
  74. AC_SEARCH_LIBS([ibuf_open], [util])
  75. AC_SEARCH_LIBS([MD5Init], [md])
  76. AC_SEARCH_LIBS([SHA512Init], [md])
  77. AC_CHECK_FUNCS([arc4random ibuf_open MD5Init SHA512Init])
  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