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.

204 lines
6.9 KiB

  1. #
  2. # Copyright (c) 2014 Brent Cook
  3. # Parts based on configure.ac from Portable OpenNTPD:
  4. # Copyright (c) 2004-2008 Darren Tucker
  5. # which itself was based on configure.ac from OpenSSH:
  6. # Copyright (c) 1999-2004 Damien Miller
  7. #
  8. # Permission to use, copy, modify, and distribute this software for any
  9. # purpose with or without fee is hereby granted, provided that the above
  10. # copyright notice and this permission notice appear in all copies.
  11. #
  12. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  13. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  14. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  15. # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  16. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  17. # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  18. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19. AC_INIT([OpenNTPD], m4_esyscmd([tr -d '\n' < VERSION]))
  20. AC_CANONICAL_HOST
  21. AM_INIT_AUTOMAKE([subdir-objects])
  22. AC_CONFIG_MACRO_DIR([m4])
  23. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
  24. AC_SUBST([USER_CFLAGS], "$CFLAGS")
  25. CFLAGS="$CFLAGS -Wall -std=gnu99 -g"
  26. case $host_os in
  27. *darwin*)
  28. HOST_OS=darwin
  29. AC_DEFINE(SETEUID_BREAKS_SETUID,[],[setuid after seteuid does not work])
  30. AC_DEFINE(BROKEN_SETREUID,[], [Broken setreuid])
  31. AC_DEFINE(BROKEN_SETREGID,[], [Broken setregid])
  32. AC_DEFINE(YYSTYPE_IS_DECLARED,[], [Broken bison])
  33. AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV])
  34. ;;
  35. *freebsd*)
  36. HOST_OS=freebsd
  37. AC_SUBST([PROG_LDADD], ['-lthr'])
  38. ;;
  39. *linux*)
  40. HOST_OS=linux
  41. CFLAGS="$CFLAGS -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE"
  42. AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV])
  43. ;;
  44. *openbsd*)
  45. AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD has __bounded__])
  46. AC_DEFINE([HAVE_ATTRIBUTE__DEAD], [1], [OpenBSD has __dead])
  47. ;;
  48. *solaris*)
  49. HOST_OS=solaris
  50. CFLAGS="$CFLAGS -D__EXTENSIONS__ -D_XOPEN_SOURCE=600 -DBSD_COMP"
  51. AC_SUBST([PLATFORM_LDADD], ['-lnsl -lsocket'])
  52. ;;
  53. *) ;;
  54. esac
  55. AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin])
  56. AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd])
  57. AM_CONDITIONAL([HOST_LINUX], [test x$HOST_OS = xlinux])
  58. AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris])
  59. AC_CHECK_FUNC([dl_iterate_phdr],,
  60. [AC_SEARCH_LIBS([dl_iterate_phdr],[dl])])
  61. AC_PROG_CC
  62. AC_PROG_CC_STDC
  63. AM_PROG_CC_C_O
  64. AC_PROG_LIBTOOL
  65. AC_PROG_YACC
  66. save_cflags="$CFLAGS"
  67. CFLAGS=-Wno-pointer-sign
  68. AC_MSG_CHECKING([whether CC supports -Wno-pointer-sign])
  69. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  70. [AC_MSG_RESULT([yes])]
  71. [AM_CFLAGS=-Wno-pointer-sign],
  72. [AC_MSG_RESULT([no])]
  73. )
  74. CFLAGS="$save_cflags $AM_CFLAGS"
  75. AC_MSG_CHECKING([if compiling with clang])
  76. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
  77. #ifndef __clang__
  78. not clang
  79. #endif
  80. ]])],
  81. [AC_MSG_RESULT([yes])]
  82. [CLANG_FLAGS=-Qunused-arguments],
  83. [AC_MSG_RESULT([no])]
  84. )
  85. CFLAGS="$CFLAGS $CLANG_CFLAGS"
  86. LDFLAGS="$LDFLAGS $CLANG_FLAGS"
  87. # check functions that are expected to be in libc
  88. AC_CHECK_FUNCS([adjfreq ntp_adjtime adjtimex])
  89. AC_CHECK_FUNCS([arc4random_uniform asprintf explicit_bzero])
  90. AC_CHECK_FUNCS([getentropy memmem poll reallocarray])
  91. AC_CHECK_FUNCS([setproctitle setgroups])
  92. AC_CHECK_FUNCS([setregid setresgid setreuid setresuid])
  93. AC_CHECK_FUNCS([strlcat strlcpy strtonum])
  94. # check auxiliary libraries that might contain other functions
  95. AC_SEARCH_LIBS([arc4random], [crypto])
  96. AC_SEARCH_LIBS([clock_getres],[rt posix4])
  97. AC_SEARCH_LIBS([clock_gettime],[rt posix4])
  98. AC_SEARCH_LIBS([ibuf_open], [util])
  99. AC_SEARCH_LIBS([MD5Init], [md md5])
  100. AC_SEARCH_LIBS([SHA512Init], [md])
  101. AC_CHECK_FUNCS([arc4random ibuf_open MD5Init SHA512Init])
  102. AC_CHECK_FUNCS([clock_gettime clock_getres])
  103. # Share test results with automake
  104. AM_CONDITIONAL([HAVE_ADJFREQ], [test "x$ac_cv_func_adjfreq" = xyes])
  105. AM_CONDITIONAL([HAVE_ARC4RANDOM], [test "x$ac_cv_func_arc4random" = xyes])
  106. AM_CONDITIONAL([HAVE_ARC4RANDOM_UNIFORM], [test "x$ac_cv_func_arc4random_uniform" = xyes])
  107. AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes])
  108. AM_CONDITIONAL([HAVE_CLOCK_GETRES], [test "x$ac_cv_func_clock_getres" = xyes])
  109. AM_CONDITIONAL([HAVE_CLOCK_GETTIME], [test "x$ac_cv_func_clock_gettime" = xyes])
  110. AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes])
  111. AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes])
  112. AM_CONDITIONAL([HAVE_IMSG], [test "x$ac_cv_func_ibuf_open" = xyes])
  113. AM_CONDITIONAL([HAVE_MD5], [test "x$ac_cv_func_MD5Init" = xyes])
  114. AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes])
  115. AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes])
  116. AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes])
  117. AM_CONDITIONAL([HAVE_SETGROUPS], [test "x$ac_cv_func_setgroups" = xyes])
  118. AM_CONDITIONAL([HAVE_SETRESGID], [test "x$ac_cv_func_setresgid" = xyes])
  119. AM_CONDITIONAL([HAVE_SETRESUID], [test "x$ac_cv_func_setresuid" = xyes])
  120. AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
  121. AM_CONDITIONAL([HAVE_SHA512], [test "x$ac_cv_func_SHA512Init" = xyes])
  122. AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes])
  123. AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
  124. AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes])
  125. # overrides for arc4random_buf implementations with known issues
  126. AM_CONDITIONAL([HAVE_ARC4RANDOM],
  127. [test "x$HOST_OS" != xdarwin -a "x$HOST_OS" != xfreebsd -a "x$ac_cv_func_arc4random" = xyes])
  128. AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [
  129. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  130. #include <stdarg.h>
  131. va_list x,y;
  132. ]], [[ va_copy(x,y); ]])],
  133. [ ac_cv_have_va_copy="yes" ],
  134. [ ac_cv_have_va_copy="no"
  135. ])
  136. ])
  137. if test "x$ac_cv_have_va_copy" = "xyes" ; then
  138. AC_DEFINE([HAVE_VA_COPY], [1], [Define if va_copy exists])
  139. fi
  140. AC_CACHE_CHECK([whether __va_copy exists], ac_cv_have___va_copy, [
  141. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  142. #include <stdarg.h>
  143. va_list x,y;
  144. ]], [[ __va_copy(x,y); ]])],
  145. [ ac_cv_have___va_copy="yes" ], [ ac_cv_have___va_copy="no"
  146. ])
  147. ])
  148. if test "x$ac_cv_have___va_copy" = "xyes" ; then
  149. AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists])
  150. fi
  151. AC_CHECK_HEADERS([err.h md5.h sha2.h])
  152. AC_CHECK_HEADERS([sys/sensors.h],
  153. AM_CONDITIONAL(HAVE_SENSORS, true),
  154. AM_CONDITIONAL(HAVE_SENSORS, false)
  155. )
  156. AC_CHECK_MEMBERS([struct sockaddr_in.sin_len], , ,
  157. [ #include <netdb.h>
  158. #include <netinet/in.h>
  159. #include <sys/socket.h> ]
  160. )
  161. AC_ARG_WITH(privsep-user,
  162. [ --with-privsep-user=user Specify privilege separation user],
  163. [ AC_DEFINE_UNQUOTED(NTPD_USER, "$withval",
  164. [Unprivileged userid])
  165. PRIVSEP_USER=$withval ],
  166. [ PRIVSEP_USER=_ntp ]
  167. )
  168. AC_SUBST(PRIVSEP_USER)
  169. AC_ARG_WITH(privsep-path,
  170. [ --with-privsep-path=path Specify privilege separation chroot path],
  171. [ AC_DEFINE_UNQUOTED(NTPD_CHROOT_DIR, "$withval",
  172. [Privilege separation chroot path])
  173. PRIVSEP_PATH=$withval ],
  174. [ PRIVSEP_PATH=/var/empty/ntp ]
  175. )
  176. AC_SUBST(PRIVSEP_PATH)
  177. AC_CONFIG_FILES([
  178. Makefile
  179. include/Makefile
  180. ])
  181. AC_OUTPUT