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.

161 lines
5.4 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. AC_DEFINE(SETEUID_BREAKS_SETUID,[],[setuid after seteuid does not work])
  12. AC_DEFINE(BROKEN_SETREUID,[], [Broken setreuid])
  13. AC_DEFINE(BROKEN_SETREGID,[], [Broken setregid])
  14. AC_DEFINE(YYSTYPE_IS_DECLARED,[], [Broken bison])
  15. ;;
  16. *freebsd*)
  17. HOST_OS=freebsd
  18. AC_SUBST([PROG_LDADD], ['-lthr'])
  19. ;;
  20. *linux*)
  21. HOST_OS=linux
  22. CFLAGS="$CFLAGS -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE"
  23. ;;
  24. *openbsd*)
  25. AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD has __bounded__])
  26. AC_DEFINE([HAVE_ATTRIBUTE__DEAD], [1], [OpenBSD has __dead])
  27. ;;
  28. *solaris*)
  29. HOST_OS=solaris
  30. CFLAGS="$CFLAGS -D__EXTENSIONS__ -D_XOPEN_SOURCE=600 -DBSD_COMP"
  31. AC_SUBST([PLATFORM_LDADD], ['-lnsl -lsocket'])
  32. ;;
  33. *) ;;
  34. esac
  35. AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin])
  36. AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd])
  37. AM_CONDITIONAL([HOST_LINUX], [test x$HOST_OS = xlinux])
  38. AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris])
  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 ntp_adjtime adjtimex])
  69. AC_CHECK_FUNCS([arc4random_uniform asprintf explicit_bzero])
  70. AC_CHECK_FUNCS([getentropy memmem poll reallocarray])
  71. AC_CHECK_FUNCS([setproctitle setgroups])
  72. AC_CHECK_FUNCS([setregid setresgid setreuid setresuid])
  73. AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strtonum])
  74. # check auxiliary libraries that might contain other functions
  75. AC_SEARCH_LIBS([arc4random], [crypto])
  76. AC_SEARCH_LIBS([clock_getres],[rt posix4])
  77. AC_SEARCH_LIBS([clock_gettime],[rt posix4])
  78. AC_SEARCH_LIBS([ibuf_open], [util])
  79. AC_SEARCH_LIBS([MD5Init], [md])
  80. AC_SEARCH_LIBS([SHA512Init], [md])
  81. AC_CHECK_FUNCS([arc4random ibuf_open MD5Init SHA512Init])
  82. AC_CHECK_FUNCS([clock_gettime clock_getres])
  83. # Share test results with automake
  84. AM_CONDITIONAL([HAVE_ADJFREQ], [test "x$ac_cv_func_adjfreq" = xyes])
  85. AM_CONDITIONAL([HAVE_ARC4RANDOM], [test "x$ac_cv_func_arc4random" = xyes])
  86. AM_CONDITIONAL([HAVE_ARC4RANDOM_UNIFORM], [test "x$ac_cv_func_arc4random_uniform" = xyes])
  87. AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes])
  88. AM_CONDITIONAL([HAVE_CLOCK_GETRES], [test "x$ac_cv_func_clock_getres" = xyes])
  89. AM_CONDITIONAL([HAVE_CLOCK_GETTIME], [test "x$ac_cv_func_clock_gettime" = xyes])
  90. AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes])
  91. AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes])
  92. AM_CONDITIONAL([HAVE_IMSG], [test "x$ac_cv_func_ibuf_open" = xyes])
  93. AM_CONDITIONAL([HAVE_MD5], [test "x$ac_cv_func_MD5Init" = xyes])
  94. AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes])
  95. AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes])
  96. AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes])
  97. AM_CONDITIONAL([HAVE_SETGROUPS], [test "x$ac_cv_func_setgroups" = xyes])
  98. AM_CONDITIONAL([HAVE_SETRESGID], [test "x$ac_cv_func_setresgid" = xyes])
  99. AM_CONDITIONAL([HAVE_SETRESUID], [test "x$ac_cv_func_setresuid" = xyes])
  100. AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
  101. AM_CONDITIONAL([HAVE_SHA512], [test "x$ac_cv_func_SHA512Init" = xyes])
  102. AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes])
  103. AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
  104. AM_CONDITIONAL([HAVE_STRNDUP], [test "x$ac_cv_func_strndup" = xyes])
  105. AM_CONDITIONAL([HAVE_STRNLEN], [test "x$ac_cv_func_strnlen" = xyes])
  106. AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes])
  107. # overrides for arc4random_buf implementations with known issues
  108. AM_CONDITIONAL([HAVE_ARC4RANDOM],
  109. [test "x$HOST_OS" != xdarwin -a "x$HOST_OS" != xfreebsd -a "x$ac_cv_func_arc4random" = xyes])
  110. AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [
  111. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  112. #include <stdarg.h>
  113. va_list x,y;
  114. ]], [[ va_copy(x,y); ]])],
  115. [ ac_cv_have_va_copy="yes" ],
  116. [ 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_CACHE_CHECK([whether __va_copy exists], ac_cv_have___va_copy, [
  123. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  124. #include <stdarg.h>
  125. va_list x,y;
  126. ]], [[ __va_copy(x,y); ]])],
  127. [ ac_cv_have___va_copy="yes" ], [ ac_cv_have___va_copy="no"
  128. ])
  129. ])
  130. if test "x$ac_cv_have___va_copy" = "xyes" ; then
  131. AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists])
  132. fi
  133. AC_CHECK_HEADERS([sys/timex.h md5.h sha2.h])
  134. AC_CHECK_HEADERS([sys/sensors.h],
  135. AM_CONDITIONAL(HAVE_SENSORS, true),
  136. AM_CONDITIONAL(HAVE_SENSORS, false)
  137. )
  138. AC_CONFIG_FILES([
  139. Makefile
  140. include/Makefile
  141. ])
  142. AC_OUTPUT