configure.in 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. #
  2. # configure.in -- autoconf source to configure newsd
  3. #
  4. # Copyright 2003-2013 Michael Sweet
  5. # Copyright 2002 Greg Ercolano
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public Licensse as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. #
  21. AC_INIT(newsd.C)
  22. AC_CONFIG_HEADER(config.h)
  23. dnl Version number...
  24. VERSION=2.0
  25. AC_SUBST(VERSION)
  26. AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
  27. dnl Get the operating system...
  28. uname=`uname`
  29. uversion=`uname -r | sed -e '1,$s/[[^0-9]]//g'`
  30. if test "$uname" = "IRIX64"; then
  31. uname="IRIX"
  32. fi
  33. dnl Clear default debugging options and set normal optimization by
  34. dnl default unless the user asks for debugging specifically.
  35. CFLAGS="${CFLAGS:=}"
  36. CXXFLAGS="${CXXFLAGS:=}"
  37. LDFLAGS="${LDFLAGS:=}"
  38. OPTIM=""
  39. PIEFLAGS=""
  40. RELROFLAGS=""
  41. AC_SUBST(LDFLAGS)
  42. AC_SUBST(OPTIM)
  43. AC_SUBST(PIEFLAGS)
  44. AC_SUBST(RELROFLAGS)
  45. AC_ARG_ENABLE(debug, [ --enable-debug turn on debugging, default=no])
  46. AC_ARG_ENABLE(relro, [ --enable-relro use GCC relro option, default=no])
  47. AC_ARG_WITH(archflags, [ --with-archflags="flags"
  48. set default architecture flags ])
  49. AC_ARG_WITH(docdir, [ --with-docdir set directory for documentation],
  50. docdir="$withval",
  51. docdir="NONE")
  52. AC_SUBST(docdir)
  53. AC_ARG_WITH(optim, [ --with-optim="flags" set optimization flags ])
  54. AC_ARG_WITH(sendmail, [ --with-sendmail set default sendmail program],
  55. sendmail="$withval",
  56. sendmail="NONE")
  57. AC_SUBST(sendmail)
  58. AC_ARG_WITH(spooldir, [ --with-spooldir set default directory for article files],
  59. spooldir="$withval",
  60. spooldir="NONE")
  61. AC_SUBST(spooldir)
  62. dnl For debugging, use "-g" for optimizer settings...
  63. if test x$enable_debug = xyes; then
  64. OPTIM="-g"
  65. fi
  66. dnl Setup general architecture flags...
  67. if test -z "$with_archflags"; then
  68. ARCHFLAGS=""
  69. else
  70. ARCHFLAGS="$with_archflags"
  71. fi
  72. AC_SUBST(ARCHFLAGS)
  73. dnl Check for libraries with socket stuff...
  74. AC_SEARCH_LIBS(socket, socket)
  75. AC_SEARCH_LIBS(getaddrinfo, nsl)
  76. AC_SEARCH_LIBS(getnameinfo, nsl)
  77. dnl Check for largefile support...
  78. AC_SYS_LARGEFILE
  79. dnl Check for POSIX threading support...
  80. have_pthread=no
  81. AC_CHECK_HEADER(pthread.h)
  82. if test x$ac_cv_header_pthread_h = xyes; then
  83. for flag in -lpthreads -lpthread -pthread; do
  84. AC_MSG_CHECKING([for pthread_create using $flag])
  85. SAVELIBS="$LIBS"
  86. LIBS="$flag $LIBS"
  87. AC_TRY_LINK([#include <pthread.h>],
  88. [pthread_create(0, 0, 0, 0);],
  89. have_pthread=yes,
  90. LIBS="$SAVELIBS")
  91. AC_MSG_RESULT([$have_pthread])
  92. done
  93. fi
  94. if test $have_pthread = no; then
  95. AC_MSG_ERROR(Sorry, newsd requires POSIX threads.)
  96. fi
  97. dnl Define largefile options as needed...
  98. LARGEFILE=""
  99. if test x$enable_largefile != xno; then
  100. LARGEFILE="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE"
  101. if test x$ac_cv_sys_large_files = x1; then
  102. LARGEFILE="$LARGEFILE -D_LARGE_FILES"
  103. fi
  104. if test x$ac_cv_sys_file_offset_bits = x64; then
  105. LARGEFILE="$LARGEFILE -D_FILE_OFFSET_BITS=64"
  106. fi
  107. fi
  108. AC_SUBST(LARGEFILE)
  109. if test -n "$GCC"; then
  110. # Add GCC-specific compiler options...
  111. if test -z "$OPTIM"; then
  112. if test -z "$with_optim"; then
  113. # Default to optimize-for-size and debug
  114. OPTIM="-Os -g"
  115. else
  116. OPTIM="$with_optim $OPTIM"
  117. fi
  118. fi
  119. # The -fstack-protector option is available with some versions of
  120. # GCC and adds "stack canaries" which detect when the return address
  121. # has been overwritten, preventing many types of exploit attacks.
  122. AC_MSG_CHECKING(if GCC supports -fstack-protector)
  123. OLDCFLAGS="$CFLAGS"
  124. CFLAGS="$CFLAGS -fstack-protector"
  125. AC_TRY_COMPILE(,,
  126. OPTIM="$OPTIM -fstack-protector"
  127. AC_MSG_RESULT(yes),
  128. AC_MSG_RESULT(no))
  129. CFLAGS="$OLDCFLAGS"
  130. # The -pie option is available with some versions of GCC and adds
  131. # randomization of addresses, which avoids another class of exploits
  132. # that depend on a fixed address for common functions.
  133. AC_MSG_CHECKING(if GCC supports -fPIE)
  134. OLDCFLAGS="$CFLAGS"
  135. case "$uname" in
  136. Darwin*)
  137. CFLAGS="$CFLAGS -fPIE -Wl,-pie"
  138. AC_TRY_COMPILE(,,[
  139. OPTIM="-fPIC $OPTIM"
  140. PIEFLAGS="-fPIE -Wl,-pie"
  141. AC_MSG_RESULT(yes)],
  142. AC_MSG_RESULT(no))
  143. ;;
  144. *)
  145. CFLAGS="$CFLAGS -fPIE -pie"
  146. AC_TRY_COMPILE(,,[
  147. OPTIM="-fPIC $OPTIM"
  148. PIEFLAGS="-fPIE -pie"
  149. AC_MSG_RESULT(yes)],
  150. AC_MSG_RESULT(no))
  151. ;;
  152. esac
  153. CFLAGS="$OLDCFLAGS"
  154. if test -z "$with_optim"; then
  155. # Add useful warning options for tracking down problems...
  156. OPTIM="-Wall -Wno-format-y2k $OPTIM"
  157. # Additional warning options for development testing...
  158. if test -d .svn; then
  159. OPTIM="-Wshadow -Wunused $OPTIM"
  160. fi
  161. fi
  162. case "$uname" in
  163. Darwin*)
  164. # -D_FORTIFY_SOURCE=2 adds additional object size
  165. # checking, basically wrapping all string functions
  166. # with buffer-limited ones. Not strictly needed for
  167. # newsd since we already use buffer-limited calls, but
  168. # this will catch any additions that are broken.
  169. CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
  170. CXXFLAGS="$CXXFLAGS -D_FORTIFY_SOURCE=2"
  171. if test x$enable_pie = xyes; then
  172. # GCC 4 on Mac OS X needs -Wl,-pie as well
  173. LDFLAGS="$LDFLAGS -Wl,-pie"
  174. fi
  175. ;;
  176. Linux*)
  177. # The -z relro option is provided by the Linux linker
  178. # command to make relocatable data read-only.
  179. if test x$enable_relro = xyes; then
  180. RELROFLAGS="-Wl,-z,relro"
  181. fi
  182. ;;
  183. esac
  184. elif test ! -z "$OPTIM"; then
  185. OPTIM="$with_optim $OPTIM"
  186. fi
  187. dnl Checks for programs...
  188. AC_PROG_CC
  189. AC_PROG_CXX
  190. AC_PROG_INSTALL
  191. if test "$INSTALL" = "$ac_install_sh"; then
  192. # Use full path to install-sh script...
  193. INSTALL="`pwd`/install-sh"
  194. fi
  195. AC_PATH_PROG(HTMLDOC,htmldoc)
  196. AC_PATH_PROG(MKDIR,mkdir)
  197. AC_PATH_PROG(MV,mv)
  198. AC_PATH_PROG(POD2MAN,pod2man)
  199. AC_PATH_PROG(POD2HTML,pod2html)
  200. AC_PATH_PROG(NROFF,nroff)
  201. if test x$NROFF = x; then
  202. AC_PATH_PROG(GROFF,groff)
  203. if test x$GROFF = x; then
  204. NROFF="echo"
  205. else
  206. NROFF="$GROFF -T ascii"
  207. fi
  208. fi
  209. AC_PATH_PROG(RM,rm)
  210. dnl Architecture checks...
  211. AC_C_CONST
  212. AC_C_CHAR_UNSIGNED
  213. dnl Checks for header files.
  214. AC_HEADER_STDC
  215. dnl Fix "prefix" variable if it hasn't been specified...
  216. if test "x$prefix" = xNONE; then
  217. prefix="/usr"
  218. fi
  219. dnl Fix "exec_prefix" variable if it hasn't been specified...
  220. if test "x$exec_prefix" = NONE; then
  221. exec_prefix="$prefix"
  222. fi
  223. dnl Fix "localstatedir" variable if it hasn't been specified...
  224. if test "$localstatedir" = "\${prefix}/var"; then
  225. if test "$prefix" = "/usr"; then
  226. if test $uname = Darwin; then
  227. localstatedir="/private/var"
  228. else
  229. localstatedir="/var"
  230. fi
  231. else
  232. localstatedir="$prefix/var"
  233. fi
  234. fi
  235. dnl Fix "sysconfdir" variable if it hasn't been specified...
  236. if test "$sysconfdir" = "\${prefix}/etc"; then
  237. if test "$prefix" = "/"; then
  238. if test "$uname" = Darwin; then
  239. sysconfdir="/private/etc"
  240. else
  241. sysconfdir="/etc"
  242. fi
  243. else
  244. sysconfdir="$prefix/etc"
  245. fi
  246. fi
  247. AC_DEFINE_UNQUOTED(CONFIG_FILE, "$sysconfdir/newsd.conf")
  248. dnl Fix "datarootdir" variable if it hasn't been specified...
  249. if test "$datarootdir" = "\${prefix}/share"; then
  250. if test "$prefix" = "/"; then
  251. datarootdir="/usr/share"
  252. else
  253. datarootdir="$prefix/share"
  254. fi
  255. fi
  256. dnl Fix "datadir" variable if it hasn't been specified...
  257. if test "x$datadir" = "x\${prefix}/share"; then
  258. datadir="$prefix/share"
  259. fi
  260. dnl Fix "docdir" variable if it hasn't been specified...
  261. if test "x$docdir" = xNONE; then
  262. docdir="$datadir/doc/newsd"
  263. fi
  264. dnl Domain socket is in $(localstatedir)...
  265. DOMAIN_SOCKET="$localstatedir/run/newsd"
  266. AC_DEFINE_UNQUOTED(DOMAIN_SOCKET, "$DOMAIN_SOCKET")
  267. dnl Fix "sendmail" variable if it hasn't been specified...
  268. if test "x$sendmail" = xNONE; then
  269. for dir in /usr/sbin /usr/lib /usr/bin /usr/local/sbin; do
  270. if test -x $dir/sendmail; then
  271. sendmail="$dir/sendmail"
  272. fi
  273. done
  274. fi
  275. AC_DEFINE_UNQUOTED(SENDMAIL, "$sendmail")
  276. dnl Fix "spooldir" variable if it hasn't been specified...
  277. if test "x$spooldir" = xNONE; then
  278. spooldir="$localstatedir/spool/newsd"
  279. fi
  280. AC_DEFINE_UNQUOTED(SPOOL_DIR, "$spooldir")
  281. dnl Fix "mandir" variable if it hasn't been specified...
  282. if test "$mandir" = "\${prefix}/man" -a "$prefix" = "/usr"; then
  283. mandir="/usr/share/man"
  284. fi
  285. dnl More manpage stuff...
  286. MAN5EXT="5.gz"
  287. MAN8EXT="8.gz"
  288. AC_SUBST(MAN5EXT)
  289. AC_SUBST(MAN8EXT)
  290. dnl Setup init.d locations...
  291. init_target="init"
  292. init_dir=""
  293. if test x$rcdir = x; then
  294. case "$uname" in
  295. NetBSD*)
  296. # NetBSD
  297. init_dir="/etc/rc.d"
  298. ;;
  299. Darwin*)
  300. # Darwin and Mac OS X...
  301. init_target="launchd"
  302. ;;
  303. Linux*)
  304. init_dir="/etc/init.d"
  305. ;;
  306. esac
  307. fi
  308. AC_SUBST(init_dir)
  309. AC_SUBST(init_target)
  310. dnl Output the makefile, list file, and config header...
  311. AC_OUTPUT(Makefile newsd.sh newsd.conf newsd.list newsd.pod newsd.conf.pod)