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.

259 lines
8.8 KiB

  1. #
  2. # Copyright (c) 2014-2015 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 foreign])
  22. AC_CONFIG_MACRO_DIR([m4])
  23. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
  24. AC_PROG_CC
  25. AC_PROG_CC_STDC
  26. AM_PROG_CC_C_O
  27. AC_PROG_LIBTOOL
  28. AC_PROG_YACC
  29. CFLAGS="$CFLAGS -Wall -std=gnu99 -fno-strict-aliasing"
  30. case $host_os in
  31. *darwin*)
  32. HOST_OS=darwin
  33. AC_DEFINE(SETEUID_BREAKS_SETUID,[],[setuid after seteuid does not work])
  34. AC_DEFINE(BROKEN_SETREUID,[], [Broken setreuid])
  35. AC_DEFINE(BROKEN_SETREGID,[], [Broken setregid])
  36. AC_DEFINE(YYSTYPE_IS_DECLARED,[], [Broken bison])
  37. AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV])
  38. ;;
  39. *freebsd*)
  40. HOST_OS=freebsd
  41. AC_SUBST([PROG_LDADD], ['-lthr'])
  42. ;;
  43. *linux*)
  44. HOST_OS=linux
  45. CFLAGS="$CFLAGS -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_GNU_SOURCE"
  46. AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV])
  47. ;;
  48. *netbsd*)
  49. HOST_OS=netbsd
  50. ;;
  51. *openbsd*)
  52. HOST_OS=openbsd
  53. AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD has __bounded__])
  54. AC_DEFINE([HAVE_ATTRIBUTE__DEAD], [1], [OpenBSD has __dead])
  55. ;;
  56. *solaris*)
  57. HOST_OS=solaris
  58. CFLAGS="$CFLAGS -D__EXTENSIONS__ -D_XOPEN_SOURCE=600 -DBSD_COMP"
  59. AC_SUBST([PLATFORM_LDADD], ['-lnsl -lsocket'])
  60. ;;
  61. *) ;;
  62. esac
  63. AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin])
  64. AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd])
  65. AM_CONDITIONAL([HOST_LINUX], [test x$HOST_OS = xlinux])
  66. AM_CONDITIONAL([HOST_NETBSD], [test x$HOST_OS = xnetbsd])
  67. AM_CONDITIONAL([HOST_OPENBSD], [test x$HOST_OS = xopenbsd])
  68. AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris])
  69. AC_CHECK_FUNC([dl_iterate_phdr],,
  70. [AC_SEARCH_LIBS([dl_iterate_phdr],[dl])])
  71. save_cflags="$CFLAGS"
  72. CFLAGS=-Wno-pointer-sign
  73. AC_MSG_CHECKING([whether CC supports -Wno-pointer-sign])
  74. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  75. [AC_MSG_RESULT([yes])]
  76. [AM_CFLAGS=-Wno-pointer-sign],
  77. [AC_MSG_RESULT([no])]
  78. )
  79. CFLAGS="$save_cflags $AM_CFLAGS"
  80. AC_MSG_CHECKING([if compiling with clang])
  81. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
  82. #ifndef __clang__
  83. not clang
  84. #endif
  85. ]])],
  86. [AC_MSG_RESULT([yes])]
  87. [CLANG_FLAGS=-Qunused-arguments],
  88. [AC_MSG_RESULT([no])]
  89. )
  90. CFLAGS="$CFLAGS $CLANG_CFLAGS"
  91. LDFLAGS="$LDFLAGS $CLANG_FLAGS"
  92. # check functions that are expected to be in libc
  93. AC_CHECK_FUNCS([adjfreq ntp_adjtime adjtimex])
  94. AC_CHECK_FUNCS([arc4random arc4random_uniform asprintf explicit_bzero])
  95. AC_CHECK_FUNCS([closefrom daemon getentropy memmem poll reallocarray])
  96. AC_CHECK_FUNCS([setproctitle setgroups])
  97. AC_CHECK_FUNCS([setregid setresgid setreuid setresuid])
  98. AC_CHECK_FUNCS([strlcat strlcpy strtonum sysconf])
  99. # check auxiliary libraries that might contain other functions
  100. AC_SEARCH_LIBS([arc4random], [crypto])
  101. AC_SEARCH_LIBS([clock_getres],[rt posix4])
  102. AC_SEARCH_LIBS([clock_gettime],[rt posix4])
  103. AC_SEARCH_LIBS([ibuf_open], [util])
  104. AC_CHECK_FUNCS([arc4random ibuf_open])
  105. AC_CHECK_FUNCS([clock_gettime clock_getres])
  106. # check for libtls
  107. AC_SEARCH_LIBS([tls_config_set_ca_mem],[tls],
  108. [LIBS="$LIBS -ltls -lssl -lcrypto"],,[-lssl -lcrypto])
  109. AC_CHECK_FUNCS([tls_config_set_ca_mem])
  110. # check if libtls uses 3-argument tls_write
  111. AC_CACHE_CHECK([if tls_write takes 3 arguments], ac_cv_have_tls_write_3_arg, [
  112. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  113. #include <tls.h>
  114. size_t outlen;
  115. ]], [[ tls_write(NULL, NULL, 0); ]])],
  116. [ ac_cv_have_tls_write_3_arg="yes" ],
  117. [ ac_cv_have_tls_write_3_arg="no"
  118. ])
  119. ])
  120. AM_CONDITIONAL([HAVE_LIBTLS], [test "x$ac_cv_func_tls_config_set_ca_mem" = xyes \
  121. -a "x$ac_cv_have_tls_write_3_arg" = xyes])
  122. if test "x$ac_cv_func_tls_config_set_ca_mem" = xyes -a "x$ac_cv_have_tls_write_3_arg" = xyes; then
  123. AC_DEFINE([HAVE_LIBTLS], [1])
  124. fi
  125. # Share test results with automake
  126. AM_CONDITIONAL([HAVE_ADJFREQ], [test "x$ac_cv_func_adjfreq" = xyes])
  127. AM_CONDITIONAL([HAVE_ARC4RANDOM], [test "x$ac_cv_func_arc4random" = xyes])
  128. AM_CONDITIONAL([HAVE_ARC4RANDOM_UNIFORM], [test "x$ac_cv_func_arc4random_uniform" = xyes])
  129. AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes])
  130. AM_CONDITIONAL([HAVE_CLOSEFROM], [test "x$ac_cv_func_closefrom" = xyes])
  131. AM_CONDITIONAL([HAVE_CLOCK_GETRES], [test "x$ac_cv_func_clock_getres" = xyes])
  132. AM_CONDITIONAL([HAVE_CLOCK_GETTIME], [test "x$ac_cv_func_clock_gettime" = xyes])
  133. AM_CONDITIONAL([HAVE_DAEMON], [test "x$ac_cv_func_daemon" = xyes])
  134. AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes])
  135. AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes])
  136. AM_CONDITIONAL([HAVE_IFADDRS_H], [test "x$ac_cv_header_ifaddrs_h" = xyes])
  137. AM_CONDITIONAL([HAVE_IMSG], [test "x$ac_cv_func_ibuf_open" = xyes])
  138. AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes])
  139. AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes])
  140. AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes])
  141. AM_CONDITIONAL([HAVE_SETGROUPS], [test "x$ac_cv_func_setgroups" = xyes])
  142. AM_CONDITIONAL([HAVE_SETRESGID], [test "x$ac_cv_func_setresgid" = xyes])
  143. AM_CONDITIONAL([HAVE_SETRESUID], [test "x$ac_cv_func_setresuid" = xyes])
  144. AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
  145. AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes])
  146. AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
  147. AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes])
  148. AM_CONDITIONAL([HAVE_SYSCONF], [test "x$ac_cv_func_sysconf" = xyes])
  149. # overrides for arc4random implementations with known issues
  150. AM_CONDITIONAL([HAVE_ARC4RANDOM],
  151. [test "x$HOST_OS" != xdarwin \
  152. -a "x$HOST_OS" != xfreebsd \
  153. -a "x$HOST_OS" != xnetbsd \
  154. -a "x$ac_cv_func_arc4random" = xyes])
  155. AM_CONDITIONAL([HAVE_ARC4RANDOM_UNIFORM],
  156. [test "x$HOST_OS" != xdarwin \
  157. -a "x$HOST_OS" != xfreebsd \
  158. -a "x$HOST_OS" != xnetbsd \
  159. -a "x$ac_cv_func_arc4random_uniform" = xyes])
  160. AC_CACHE_CHECK([if libc defines __progname], ac_cv_libc_defines___progname, [
  161. AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
  162. [[ extern char *__progname; printf("%s", __progname); ]])],
  163. [ ac_cv_libc_defines___progname="yes" ],
  164. [ ac_cv_libc_defines___progname="no"
  165. ])
  166. ])
  167. if test "x$ac_cv_libc_defines___progname" = "xyes" ; then
  168. AC_DEFINE([HAVE___PROGNAME], [1], [Define if libc defines __progname])
  169. fi
  170. AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [
  171. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  172. #include <stdarg.h>
  173. va_list x,y;
  174. ]], [[ va_copy(x,y); ]])],
  175. [ ac_cv_have_va_copy="yes" ],
  176. [ ac_cv_have_va_copy="no"
  177. ])
  178. ])
  179. if test "x$ac_cv_have_va_copy" = "xyes" ; then
  180. AC_DEFINE([HAVE_VA_COPY], [1], [Define if va_copy exists])
  181. fi
  182. AC_CACHE_CHECK([whether __va_copy exists], ac_cv_have___va_copy, [
  183. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  184. #include <stdarg.h>
  185. va_list x,y;
  186. ]], [[ __va_copy(x,y); ]])],
  187. [ ac_cv_have___va_copy="yes" ], [ ac_cv_have___va_copy="no"
  188. ])
  189. ])
  190. if test "x$ac_cv_have___va_copy" = "xyes" ; then
  191. AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists])
  192. fi
  193. AC_CHECK_HEADERS([sys/sysctl.h err.h ifaddrs.h paths.h])
  194. AC_CHECK_HEADERS([sys/sensors.h],
  195. AM_CONDITIONAL(HAVE_SENSORS, true),
  196. AM_CONDITIONAL(HAVE_SENSORS, false)
  197. )
  198. AC_CHECK_MEMBERS([struct sockaddr_in.sin_len], , ,
  199. [ #include <netdb.h>
  200. #include <netinet/in.h>
  201. #include <sys/socket.h> ]
  202. )
  203. AC_ARG_WITH([privsep-user],
  204. AS_HELP_STRING([--with-privsep-user=user],
  205. [Privilege separation user for ntpd to use]),
  206. PRIVSEP_USER="$withval",
  207. PRIVSEP_USER="_ntp"
  208. )
  209. AC_DEFINE_UNQUOTED(NTPD_USER, "$PRIVSEP_USER", [Unprivileged user])
  210. AC_SUBST(PRIVSEP_USER)
  211. AC_ARG_WITH([privsep-path],
  212. AS_HELP_STRING([--with-privsep-path=path],
  213. [Privilege separation chroot path to check on install]),
  214. PRIVSEP_PATH="$withval",
  215. PRIVSEP_PATH="/var/empty"
  216. )
  217. AC_SUBST(PRIVSEP_PATH)
  218. AC_ARG_WITH([cacert],
  219. AS_HELP_STRING([--with-cacert=path],
  220. [CA certificate location for HTTPS constraint validation]),
  221. CONSTRAINT_CA="$withval",
  222. CONSTRAINT_CA="/etc/ssl/cert.pem"
  223. )
  224. AC_DEFINE_UNQUOTED(CONSTRAINT_CA, "$CONSTRAINT_CA", [CA certificate path])
  225. AC_CONFIG_FILES([
  226. Makefile
  227. include/Makefile
  228. compat/Makefile
  229. src/Makefile
  230. ])
  231. AC_OUTPUT