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.

216 lines
7.2 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. *netbsd*)
  45. HOST_OS=netbsd
  46. ;;
  47. *openbsd*)
  48. AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD has __bounded__])
  49. AC_DEFINE([HAVE_ATTRIBUTE__DEAD], [1], [OpenBSD has __dead])
  50. ;;
  51. *solaris*)
  52. HOST_OS=solaris
  53. CFLAGS="$CFLAGS -D__EXTENSIONS__ -D_XOPEN_SOURCE=600 -DBSD_COMP"
  54. AC_SUBST([PLATFORM_LDADD], ['-lnsl -lsocket'])
  55. ;;
  56. *) ;;
  57. esac
  58. AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin])
  59. AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd])
  60. AM_CONDITIONAL([HOST_LINUX], [test x$HOST_OS = xlinux])
  61. AM_CONDITIONAL([HOST_NETBSD], [test x$HOST_OS = xnetbsd])
  62. AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris])
  63. AC_CHECK_FUNC([dl_iterate_phdr],,
  64. [AC_SEARCH_LIBS([dl_iterate_phdr],[dl])])
  65. AC_PROG_CC
  66. AC_PROG_CC_STDC
  67. AM_PROG_CC_C_O
  68. AC_PROG_LIBTOOL
  69. AC_PROG_YACC
  70. save_cflags="$CFLAGS"
  71. CFLAGS=-Wno-pointer-sign
  72. AC_MSG_CHECKING([whether CC supports -Wno-pointer-sign])
  73. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  74. [AC_MSG_RESULT([yes])]
  75. [AM_CFLAGS=-Wno-pointer-sign],
  76. [AC_MSG_RESULT([no])]
  77. )
  78. CFLAGS="$save_cflags $AM_CFLAGS"
  79. AC_MSG_CHECKING([if compiling with clang])
  80. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
  81. #ifndef __clang__
  82. not clang
  83. #endif
  84. ]])],
  85. [AC_MSG_RESULT([yes])]
  86. [CLANG_FLAGS=-Qunused-arguments],
  87. [AC_MSG_RESULT([no])]
  88. )
  89. CFLAGS="$CFLAGS $CLANG_CFLAGS"
  90. LDFLAGS="$LDFLAGS $CLANG_FLAGS"
  91. # check functions that are expected to be in libc
  92. AC_CHECK_FUNCS([adjfreq ntp_adjtime adjtimex])
  93. AC_CHECK_FUNCS([arc4random arc4random_uniform asprintf explicit_bzero])
  94. AC_CHECK_FUNCS([getentropy memmem poll reallocarray])
  95. AC_CHECK_FUNCS([setproctitle setgroups])
  96. AC_CHECK_FUNCS([setregid setresgid setreuid setresuid])
  97. AC_CHECK_FUNCS([strlcat strlcpy strtonum])
  98. # check auxiliary libraries that might contain other functions
  99. AC_SEARCH_LIBS([arc4random], [crypto])
  100. AC_SEARCH_LIBS([clock_getres],[rt posix4])
  101. AC_SEARCH_LIBS([clock_gettime],[rt posix4])
  102. AC_SEARCH_LIBS([ibuf_open], [util])
  103. AC_SEARCH_LIBS([MD5Init], [md md5])
  104. AC_SEARCH_LIBS([SHA512Init], [md])
  105. AC_CHECK_FUNCS([arc4random ibuf_open MD5Init SHA512Init])
  106. AC_CHECK_FUNCS([clock_gettime clock_getres])
  107. # Share test results with automake
  108. AM_CONDITIONAL([HAVE_ADJFREQ], [test "x$ac_cv_func_adjfreq" = xyes])
  109. AM_CONDITIONAL([HAVE_ARC4RANDOM], [test "x$ac_cv_func_arc4random" = xyes])
  110. AM_CONDITIONAL([HAVE_ARC4RANDOM_UNIFORM], [test "x$ac_cv_func_arc4random_uniform" = xyes])
  111. AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes])
  112. AM_CONDITIONAL([HAVE_CLOCK_GETRES], [test "x$ac_cv_func_clock_getres" = xyes])
  113. AM_CONDITIONAL([HAVE_CLOCK_GETTIME], [test "x$ac_cv_func_clock_gettime" = xyes])
  114. AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes])
  115. AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes])
  116. AM_CONDITIONAL([HAVE_IMSG], [test "x$ac_cv_func_ibuf_open" = xyes])
  117. AM_CONDITIONAL([HAVE_MD5], [test "x$ac_cv_func_MD5Init" = xyes])
  118. AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes])
  119. AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes])
  120. AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes])
  121. AM_CONDITIONAL([HAVE_SETGROUPS], [test "x$ac_cv_func_setgroups" = xyes])
  122. AM_CONDITIONAL([HAVE_SETRESGID], [test "x$ac_cv_func_setresgid" = xyes])
  123. AM_CONDITIONAL([HAVE_SETRESUID], [test "x$ac_cv_func_setresuid" = xyes])
  124. AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes])
  125. AM_CONDITIONAL([HAVE_SHA512], [test "x$ac_cv_func_SHA512Init" = xyes])
  126. AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes])
  127. AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
  128. AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes])
  129. # overrides for arc4random implementations with known issues
  130. AM_CONDITIONAL([HAVE_ARC4RANDOM],
  131. [test "x$HOST_OS" != xdarwin \
  132. -a "x$HOST_OS" != xfreebsd \
  133. -a "x$HOST_OS" != xnetbsd \
  134. -a "x$ac_cv_func_arc4random" = xyes])
  135. AM_CONDITIONAL([HAVE_ARC4RANDOM_UNIFORM],
  136. [test "x$HOST_OS" != xdarwin \
  137. -a "x$HOST_OS" != xfreebsd \
  138. -a "x$HOST_OS" != xnetbsd \
  139. -a "x$ac_cv_func_arc4random_uniform" = xyes])
  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" ],
  146. [ ac_cv_have_va_copy="no"
  147. ])
  148. ])
  149. if test "x$ac_cv_have_va_copy" = "xyes" ; then
  150. AC_DEFINE([HAVE_VA_COPY], [1], [Define if va_copy exists])
  151. fi
  152. AC_CACHE_CHECK([whether __va_copy exists], ac_cv_have___va_copy, [
  153. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  154. #include <stdarg.h>
  155. va_list x,y;
  156. ]], [[ __va_copy(x,y); ]])],
  157. [ ac_cv_have___va_copy="yes" ], [ ac_cv_have___va_copy="no"
  158. ])
  159. ])
  160. if test "x$ac_cv_have___va_copy" = "xyes" ; then
  161. AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists])
  162. fi
  163. AC_CHECK_HEADERS([err.h md5.h sha2.h])
  164. AC_CHECK_HEADERS([sys/sensors.h],
  165. AM_CONDITIONAL(HAVE_SENSORS, true),
  166. AM_CONDITIONAL(HAVE_SENSORS, false)
  167. )
  168. AC_CHECK_MEMBERS([struct sockaddr_in.sin_len], , ,
  169. [ #include <netdb.h>
  170. #include <netinet/in.h>
  171. #include <sys/socket.h> ]
  172. )
  173. AC_ARG_WITH(privsep-user,
  174. [ --with-privsep-user=user Specify privilege separation user],
  175. [ AC_DEFINE_UNQUOTED(NTPD_USER, "$withval",
  176. [Unprivileged userid])
  177. PRIVSEP_USER=$withval ],
  178. [ PRIVSEP_USER=_ntp ]
  179. )
  180. AC_SUBST(PRIVSEP_USER)
  181. AC_ARG_WITH(privsep-path,
  182. [ --with-privsep-path=path Specify privilege separation chroot path],
  183. [ AC_DEFINE_UNQUOTED(NTPD_CHROOT_DIR, "$withval",
  184. [Privilege separation chroot path])
  185. PRIVSEP_PATH=$withval ],
  186. [ PRIVSEP_PATH=/var/empty/ntp ]
  187. )
  188. AC_SUBST(PRIVSEP_PATH)
  189. AC_CONFIG_FILES([
  190. Makefile
  191. include/Makefile
  192. ])
  193. AC_OUTPUT