configure.ac 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707
  1. dnl Copyright (c) 2001-2004, Roger Dingledine
  2. dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
  3. dnl Copyright (c) 2007-2015, The Tor Project, Inc.
  4. dnl See LICENSE for licensing information
  5. AC_INIT([tor],[0.2.8.1-alpha])
  6. AC_CONFIG_SRCDIR([src/or/main.c])
  7. AC_CONFIG_MACRO_DIR([m4])
  8. AM_INIT_AUTOMAKE
  9. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
  10. AC_CONFIG_HEADERS([orconfig.h])
  11. AC_CANONICAL_HOST
  12. PKG_PROG_PKG_CONFIG
  13. if test -f /etc/redhat-release ; then
  14. if test -f /usr/kerberos/include ; then
  15. CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
  16. fi
  17. fi
  18. # Not a no-op; we want to make sure that CPPFLAGS is set before we use
  19. # the += operator on it in src/or/Makefile.am
  20. CPPFLAGS="$CPPFLAGS -I\${top_srcdir}/src/common"
  21. #XXXX020 We should make these enabled or not, before 0.2.0.x-final
  22. AC_ARG_ENABLE(openbsd-malloc,
  23. AS_HELP_STRING(--enable-openbsd-malloc, [use malloc code from OpenBSD. Linux only]))
  24. AC_ARG_ENABLE(instrument-downloads,
  25. AS_HELP_STRING(--enable-instrument-downloads, [instrument downloads of directory resources etc.]))
  26. AC_ARG_ENABLE(static-openssl,
  27. AS_HELP_STRING(--enable-static-openssl, [link against a static openssl library. Requires --with-openssl-dir]))
  28. AC_ARG_ENABLE(static-libevent,
  29. AS_HELP_STRING(--enable-static-libevent, [link against a static libevent library. Requires --with-libevent-dir]))
  30. AC_ARG_ENABLE(static-zlib,
  31. AS_HELP_STRING(--enable-static-zlib, [link against a static zlib library. Requires --with-zlib-dir]))
  32. AC_ARG_ENABLE(static-tor,
  33. AS_HELP_STRING(--enable-static-tor, [create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir]))
  34. AC_ARG_ENABLE(unittests,
  35. AS_HELP_STRING(--disable-unittests, [don't build unit tests for Tor. Risky!]))
  36. AC_ARG_ENABLE(coverage,
  37. AS_HELP_STRING(--enable-coverage, [enable coverage support in the unit-test build]))
  38. AC_ARG_ENABLE(asserts-in-tests,
  39. AS_HELP_STRING(--disable-asserts-in-tests, [disable tor_assert() calls in the unit tests, for branch coverage]))
  40. AC_ARG_ENABLE(system-torrc,
  41. AS_HELP_STRING(--disable-system-torrc, [don't look for a system-wide torrc file]))
  42. AM_CONDITIONAL(UNITTESTS_ENABLED, test x$enable_unittests != xno)
  43. AM_CONDITIONAL(COVERAGE_ENABLED, test x$enable_coverage = xyes)
  44. if test "$enable_static_tor" = "yes"; then
  45. enable_static_libevent="yes";
  46. enable_static_openssl="yes";
  47. enable_static_zlib="yes";
  48. CFLAGS="$CFLAGS -static"
  49. fi
  50. if test "$enable_system_torrc" = "no"; then
  51. AC_DEFINE(DISABLE_SYSTEM_TORRC, 1,
  52. [Defined if we're not going to look for a torrc in SYSCONF])
  53. fi
  54. AM_CONDITIONAL(USE_OPENBSD_MALLOC, test x$enable_openbsd_malloc = xyes)
  55. if test x$enable_instrument_downloads = xyes; then
  56. AC_DEFINE(INSTRUMENT_DOWNLOADS, 1,
  57. [Defined if we want to keep track of how much of each kind of resource we download.])
  58. fi
  59. AC_ARG_ENABLE(transparent,
  60. AS_HELP_STRING(--disable-transparent, [disable transparent proxy support]),
  61. [case "${enableval}" in
  62. yes) transparent=true ;;
  63. no) transparent=false ;;
  64. *) AC_MSG_ERROR(bad value for --enable-transparent) ;;
  65. esac], [transparent=true])
  66. AC_ARG_ENABLE(asciidoc,
  67. AS_HELP_STRING(--disable-asciidoc, [don't use asciidoc (disables building of manpages)]),
  68. [case "${enableval}" in
  69. yes) asciidoc=true ;;
  70. no) asciidoc=false ;;
  71. *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
  72. esac], [asciidoc=true])
  73. # systemd notify support
  74. AC_ARG_ENABLE(systemd,
  75. AS_HELP_STRING(--enable-systemd, [enable systemd notification support]),
  76. [case "${enableval}" in
  77. yes) systemd=true ;;
  78. no) systemd=false ;;
  79. * ) AC_MSG_ERROR(bad value for --enable-systemd) ;;
  80. esac], [systemd=auto])
  81. # systemd support
  82. if test x$enable_systemd = xno ; then
  83. have_systemd=no;
  84. else
  85. PKG_CHECK_MODULES(SYSTEMD,
  86. [libsystemd-daemon],
  87. have_systemd=yes,
  88. have_systemd=no)
  89. if test x$have_systemd=xno; then
  90. AC_MSG_NOTICE([Okay, checking for systemd a different way...])
  91. PKG_CHECK_MODULES(SYSTEMD,
  92. [libsystemd],
  93. have_systemd=yes,
  94. have_systemd=no)
  95. fi
  96. fi
  97. if test x$have_systemd = xyes; then
  98. AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
  99. TOR_SYSTEMD_CFLAGS="${SYSTEMD_CFLAGS}"
  100. TOR_SYSTEMD_LIBS="${SYSTEMD_LIBS}"
  101. PKG_CHECK_MODULES(LIBSYSTEMD209, [libsystemd >= 209],
  102. [AC_DEFINE(HAVE_SYSTEMD_209,1,[Have systemd v209 or more])], [])
  103. fi
  104. AC_SUBST(TOR_SYSTEMD_CFLAGS)
  105. AC_SUBST(TOR_SYSTEMD_LIBS)
  106. if test x$enable_systemd = xyes -a x$have_systemd != xyes ; then
  107. AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found])
  108. fi
  109. case $host in
  110. *-*-solaris* )
  111. AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
  112. ;;
  113. esac
  114. AC_ARG_ENABLE(gcc-warnings,
  115. AS_HELP_STRING(--enable-gcc-warnings, [enable verbose warnings]))
  116. AC_ARG_ENABLE(gcc-warnings-advisory,
  117. AS_HELP_STRING(--enable-gcc-warnings-advisory, [enable verbose warnings, excluding -Werror]))
  118. dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
  119. AC_ARG_ENABLE(gcc-hardening,
  120. AS_HELP_STRING(--disable-gcc-hardening, [disable compiler security checks]))
  121. AC_ARG_ENABLE(expensive-hardening,
  122. AS_HELP_STRING(--enable-expensive-hardening, [enable more expensive compiler hardening; makes Tor slower]))
  123. dnl Linker hardening options
  124. dnl Currently these options are ELF specific - you can't use this with MacOSX
  125. AC_ARG_ENABLE(linker-hardening,
  126. AS_HELP_STRING(--disable-linker-hardening, [disable linker security fixups]))
  127. AC_ARG_ENABLE(local-appdata,
  128. AS_HELP_STRING(--enable-local-appdata, [default to host local application data paths on Windows]))
  129. if test "$enable_local_appdata" = "yes"; then
  130. AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
  131. [Defined if we default to host local appdata paths on Windows])
  132. fi
  133. # Tor2web mode flag
  134. AC_ARG_ENABLE(tor2web-mode,
  135. AS_HELP_STRING(--enable-tor2web-mode, [support tor2web non-anonymous mode]),
  136. [if test x$enableval = xyes; then
  137. CFLAGS="$CFLAGS -D ENABLE_TOR2WEB_MODE=1"
  138. fi])
  139. AC_ARG_ENABLE(bufferevents,
  140. AS_HELP_STRING(--enable-bufferevents, [use Libevent's buffered IO]))
  141. AC_ARG_ENABLE(tool-name-check,
  142. AS_HELP_STRING(--disable-tool-name-check, [check for sanely named toolchain when cross-compiling]))
  143. AC_ARG_ENABLE(seccomp,
  144. AS_HELP_STRING(--disable-seccomp, [do not attempt to use libseccomp]))
  145. AC_ARG_ENABLE(libscrypt,
  146. AS_HELP_STRING(--disable-libscrypt, [do not attempt to use libscrypt]))
  147. dnl check for the correct "ar" when cross-compiling
  148. AN_MAKEVAR([AR], [AC_PROG_AR])
  149. AN_PROGRAM([ar], [AC_PROG_AR])
  150. AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [ar])])
  151. AC_PROG_AR
  152. dnl Check whether the above macro has settled for a simply named tool even
  153. dnl though we're cross compiling. We must do this before running AC_PROG_CC,
  154. dnl because that will find any cc on the system, not only the cross-compiler,
  155. dnl and then verify that a binary built with this compiler runs on the
  156. dnl build system. It will then come to the false conclusion that we're not
  157. dnl cross-compiling.
  158. if test x$enable_tool_name_check != xno; then
  159. if test x$ac_tool_warned = xyes; then
  160. AC_MSG_ERROR([We are cross compiling but could not find a properly named toolchain. Do you have your cross-compiling toolchain in PATH? (You can --disable-tool-name-check to ignore this.)])
  161. elif test "x$ac_ct_AR" != x -a x$cross_compiling = xmaybe; then
  162. AC_MSG_ERROR([We think we are cross compiling but could not find a properly named toolchain. Do you have your cross-compiling toolchain in PATH? (You can --disable-tool-name-check to ignore this.)])
  163. fi
  164. fi
  165. AC_PROG_CC
  166. AC_PROG_CPP
  167. AC_PROG_MAKE_SET
  168. AC_PROG_RANLIB
  169. AC_PATH_PROG([PERL], [perl])
  170. dnl autoconf 2.59 appears not to support AC_PROG_SED
  171. AC_CHECK_PROG([SED],[sed],[sed],[/bin/false])
  172. dnl check for asciidoc and a2x
  173. AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
  174. AC_PATH_PROGS([A2X], [a2x a2x.py], none)
  175. AM_CONDITIONAL(USE_ASCIIDOC, test x$asciidoc = xtrue)
  176. AM_CONDITIONAL(USE_FW_HELPER, test x$natpmp = xtrue || test x$upnp = xtrue)
  177. AM_CONDITIONAL(NAT_PMP, test x$natpmp = xtrue)
  178. AM_CONDITIONAL(MINIUPNPC, test x$upnp = xtrue)
  179. AM_PROG_CC_C_O
  180. AC_PROG_CC_C99
  181. AC_ARG_VAR([PYTHON], [path to Python binary])
  182. AC_CHECK_PROGS(PYTHON, [python python2 python2.7 python3 python3.3])
  183. if test "x$PYTHON" = "x"; then
  184. AC_MSG_WARN([Python unavailable; some tests will not be run.])
  185. fi
  186. AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
  187. ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
  188. AC_C_FLEXIBLE_ARRAY_MEMBER
  189. ], [
  190. dnl Maybe we've got an old autoconf...
  191. AC_CACHE_CHECK([for flexible array members],
  192. tor_cv_c_flexarray,
  193. [AC_COMPILE_IFELSE(
  194. AC_LANG_PROGRAM([
  195. struct abc { int a; char b[]; };
  196. ], [
  197. struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
  198. def->b[0] = 33;
  199. ]),
  200. [tor_cv_c_flexarray=yes],
  201. [tor_cv_c_flexarray=no])])
  202. if test $tor_cv_flexarray = yes ; then
  203. AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
  204. else
  205. AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
  206. fi
  207. ])
  208. AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
  209. tor_cv_c_c99_decl,
  210. [AC_COMPILE_IFELSE(
  211. [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
  212. [tor_cv_c_c99_decl=yes],
  213. [tor_cv_c_c99_decl=no] )])
  214. if test "$tor_cv_c_c99_decl" != "yes"; then
  215. AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
  216. fi
  217. AC_CACHE_CHECK([for working C99 designated initializers],
  218. tor_cv_c_c99_designated_init,
  219. [AC_COMPILE_IFELSE(
  220. [AC_LANG_PROGRAM([struct s { int a; int b; };],
  221. [[ struct s ss = { .b = 5, .a = 6 }; ]])],
  222. [tor_cv_c_c99_designated_init=yes],
  223. [tor_cv_c_c99_designated_init=no] )])
  224. if test "$tor_cv_c_c99_designated_init" != "yes"; then
  225. AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
  226. fi
  227. TORUSER=_tor
  228. AC_ARG_WITH(tor-user,
  229. AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
  230. [
  231. TORUSER=$withval
  232. ]
  233. )
  234. AC_SUBST(TORUSER)
  235. TORGROUP=_tor
  236. AC_ARG_WITH(tor-group,
  237. AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
  238. [
  239. TORGROUP=$withval
  240. ]
  241. )
  242. AC_SUBST(TORGROUP)
  243. dnl If _WIN32 is defined and non-zero, we are building for win32
  244. AC_MSG_CHECKING([for win32])
  245. AC_RUN_IFELSE([AC_LANG_SOURCE([
  246. int main(int c, char **v) {
  247. #ifdef _WIN32
  248. #if _WIN32
  249. return 0;
  250. #else
  251. return 1;
  252. #endif
  253. #else
  254. return 2;
  255. #endif
  256. }])],
  257. bwin32=true; AC_MSG_RESULT([yes]),
  258. bwin32=false; AC_MSG_RESULT([no]),
  259. bwin32=cross; AC_MSG_RESULT([cross])
  260. )
  261. if test "$bwin32" = cross; then
  262. AC_MSG_CHECKING([for win32 (cross)])
  263. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  264. #ifdef _WIN32
  265. int main(int c, char **v) {return 0;}
  266. #else
  267. #error
  268. int main(int c, char **v) {return x(y);}
  269. #endif
  270. ])],
  271. bwin32=true; AC_MSG_RESULT([yes]),
  272. bwin32=false; AC_MSG_RESULT([no]))
  273. fi
  274. AH_BOTTOM([
  275. #ifdef _WIN32
  276. /* Defined to access windows functions and definitions for >=WinXP */
  277. # ifndef WINVER
  278. # define WINVER 0x0501
  279. # endif
  280. /* Defined to access _other_ windows functions and definitions for >=WinXP */
  281. # ifndef _WIN32_WINNT
  282. # define _WIN32_WINNT 0x0501
  283. # endif
  284. /* Defined to avoid including some windows headers as part of Windows.h */
  285. # ifndef WIN32_LEAN_AND_MEAN
  286. # define WIN32_LEAN_AND_MEAN 1
  287. # endif
  288. #endif
  289. ])
  290. AM_CONDITIONAL(BUILD_NT_SERVICES, test x$bwin32 = xtrue)
  291. dnl Enable C99 when compiling with MIPSpro
  292. AC_MSG_CHECKING([for MIPSpro compiler])
  293. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
  294. #if (defined(__sgi) && defined(_COMPILER_VERSION))
  295. #error
  296. return x(y);
  297. #endif
  298. ])],
  299. bmipspro=false; AC_MSG_RESULT(no),
  300. bmipspro=true; AC_MSG_RESULT(yes))
  301. if test "$bmipspro" = true; then
  302. CFLAGS="$CFLAGS -c99"
  303. fi
  304. AC_C_BIGENDIAN
  305. AC_SEARCH_LIBS(socket, [socket network])
  306. AC_SEARCH_LIBS(gethostbyname, [nsl])
  307. AC_SEARCH_LIBS(dlopen, [dl])
  308. AC_SEARCH_LIBS(inet_aton, [resolv])
  309. AC_SEARCH_LIBS(backtrace, [execinfo])
  310. saved_LIBS="$LIBS"
  311. AC_SEARCH_LIBS([clock_gettime], [rt])
  312. if test "$LIBS" != "$saved_LIBS"; then
  313. # Looks like we need -lrt for clock_gettime().
  314. have_rt=yes
  315. fi
  316. AC_SEARCH_LIBS(pthread_create, [pthread])
  317. AC_SEARCH_LIBS(pthread_detach, [pthread])
  318. AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
  319. AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
  320. AC_CHECK_FUNCS(
  321. _NSGetEnviron \
  322. RtlSecureZeroMemory \
  323. SecureZeroMemory \
  324. accept4 \
  325. backtrace \
  326. backtrace_symbols_fd \
  327. clock_gettime \
  328. eventfd \
  329. explicit_bzero \
  330. timingsafe_memcmp \
  331. flock \
  332. ftime \
  333. getaddrinfo \
  334. getentropy \
  335. getifaddrs \
  336. getpass \
  337. getrlimit \
  338. gettimeofday \
  339. gmtime_r \
  340. htonll \
  341. inet_aton \
  342. ioctl \
  343. issetugid \
  344. llround \
  345. localtime_r \
  346. lround \
  347. memmem \
  348. memset_s \
  349. pipe \
  350. pipe2 \
  351. prctl \
  352. readpassphrase \
  353. rint \
  354. sigaction \
  355. socketpair \
  356. statvfs \
  357. strlcat \
  358. strlcpy \
  359. strnlen \
  360. strptime \
  361. strtok_r \
  362. strtoull \
  363. sysconf \
  364. sysctl \
  365. uname \
  366. usleep \
  367. vasprintf \
  368. _vscprintf
  369. )
  370. if test "$bwin32" != true; then
  371. AC_CHECK_HEADERS(pthread.h)
  372. AC_CHECK_FUNCS(pthread_create)
  373. AC_CHECK_FUNCS(pthread_condattr_setclock)
  374. fi
  375. if test "$bwin32" = true; then
  376. AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
  377. #include <windows.h>
  378. #include <conio.h>
  379. #include <wchar.h>
  380. ])
  381. fi
  382. AM_CONDITIONAL(BUILD_READPASSPHRASE_C, test x$ac_cv_func_readpassphrase = xno && test $bwin32 = false)
  383. dnl ------------------------------------------------------
  384. dnl Where do you live, libevent? And how do we call you?
  385. if test "$bwin32" = true; then
  386. TOR_LIB_WS32=-lws2_32
  387. TOR_LIB_IPHLPAPI=-liphlpapi
  388. # Some of the cargo-cults recommend -lwsock32 as well, but I don't
  389. # think it's actually necessary.
  390. TOR_LIB_GDI=-lgdi32
  391. else
  392. TOR_LIB_WS32=
  393. TOR_LIB_GDI=
  394. fi
  395. AC_SUBST(TOR_LIB_WS32)
  396. AC_SUBST(TOR_LIB_GDI)
  397. AC_SUBST(TOR_LIB_IPHLPAPI)
  398. tor_libevent_pkg_redhat="libevent"
  399. tor_libevent_pkg_debian="libevent-dev"
  400. tor_libevent_devpkg_redhat="libevent-devel"
  401. tor_libevent_devpkg_debian="libevent-dev"
  402. dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
  403. dnl linking for static builds.
  404. STATIC_LIBEVENT_FLAGS=""
  405. if test "$enable_static_libevent" = "yes"; then
  406. if test "$have_rt" = yes; then
  407. STATIC_LIBEVENT_FLAGS=" -lrt "
  408. fi
  409. fi
  410. TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
  411. #ifdef _WIN32
  412. #include <winsock2.h>
  413. #endif
  414. #include <stdlib.h>
  415. #include <sys/time.h>
  416. #include <sys/types.h>
  417. #include <event.h>], [
  418. #ifdef _WIN32
  419. #include <winsock2.h>
  420. #endif
  421. void exit(int); void *event_init(void);],
  422. [
  423. #ifdef _WIN32
  424. {WSADATA d; WSAStartup(0x101,&d); }
  425. #endif
  426. event_init(); exit(0);
  427. ], [--with-libevent-dir], [/opt/libevent])
  428. dnl Now check for particular libevent functions.
  429. save_LIBS="$LIBS"
  430. save_LDFLAGS="$LDFLAGS"
  431. save_CPPFLAGS="$CPPFLAGS"
  432. LIBS="-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $LIBS"
  433. LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
  434. CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
  435. AC_CHECK_FUNCS([event_get_version_number \
  436. evutil_secure_rng_set_urandom_device_file \
  437. evutil_secure_rng_init \
  438. ])
  439. AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
  440. [#include <event.h>
  441. ])
  442. AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
  443. LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
  444. AM_CONDITIONAL(USE_EXTERNAL_EVDNS, test x$ac_cv_header_event2_dns_h = xyes)
  445. if test "$enable_static_libevent" = "yes"; then
  446. if test "$tor_cv_library_libevent_dir" = "(system)"; then
  447. AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
  448. else
  449. TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
  450. fi
  451. else
  452. if test "x$ac_cv_header_event2_event_h" = "xyes"; then
  453. AC_SEARCH_LIBS(event_new, [event event_core], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for event_new"))
  454. AC_SEARCH_LIBS(evdns_base_new, [event event_extra], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for evdns_base_new"))
  455. if test "$ac_cv_search_event_new" != "none required"; then
  456. TOR_LIBEVENT_LIBS="$ac_cv_search_event_new"
  457. fi
  458. if test "$ac_cv_search_evdns_base_new" != "none required"; then
  459. TOR_LIBEVENT_LIBS="$ac_cv_search_evdns_base_new $TOR_LIBEVENT_LIBS"
  460. fi
  461. else
  462. TOR_LIBEVENT_LIBS="-levent"
  463. fi
  464. fi
  465. LIBS="$save_LIBS"
  466. LDFLAGS="$save_LDFLAGS"
  467. CPPFLAGS="$save_CPPFLAGS"
  468. dnl This isn't the best test for Libevent 2.0.3-alpha. Once it's released,
  469. dnl we can do much better.
  470. if test "$enable_bufferevents" = "yes" ; then
  471. if test "$ac_cv_header_event2_bufferevent_ssl_h" != "yes" ; then
  472. AC_MSG_ERROR([You've asked for bufferevent support, but you're using a version of Libevent without SSL support. This won't work. We need Libevent 2.0.8-rc or later, and you don't seem to even have Libevent 2.0.3-alpha.])
  473. else
  474. CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
  475. # Check for the right version. First see if version detection works.
  476. AC_MSG_CHECKING([whether we can detect the Libevent version])
  477. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  478. #include <event2/event.h>
  479. #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 10
  480. #error
  481. int x = y(zz);
  482. #else
  483. int x = 1;
  484. #endif
  485. ])], [event_version_number_works=yes; AC_MSG_RESULT([yes]) ],
  486. [event_version_number_works=no; AC_MSG_RESULT([no])])
  487. if test "$event_version_number_works" != 'yes'; then
  488. AC_MSG_WARN([Version detection on Libevent seems broken. Your Libevent installation is probably screwed up or very old.])
  489. else
  490. AC_MSG_CHECKING([whether Libevent is new enough for bufferevents])
  491. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  492. #include <event2/event.h>
  493. #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000d00
  494. #error
  495. int x = y(zz);
  496. #else
  497. int x = 1;
  498. #endif
  499. ])], [ AC_MSG_RESULT([yes]) ],
  500. [ AC_MSG_RESULT([no])
  501. AC_MSG_ERROR([Libevent does not seem new enough to support bufferevents. We require 2.0.13-stable or later]) ] )
  502. fi
  503. fi
  504. fi
  505. LIBS="$save_LIBS"
  506. LDFLAGS="$save_LDFLAGS"
  507. CPPFLAGS="$save_CPPFLAGS"
  508. AM_CONDITIONAL(USE_BUFFEREVENTS, test "$enable_bufferevents" = "yes")
  509. if test "$enable_bufferevents" = "yes"; then
  510. AC_DEFINE(USE_BUFFEREVENTS, 1, [Defined if we're going to use Libevent's buffered IO API])
  511. if test "$enable_static_libevent" = "yes"; then
  512. TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent_openssl.a $TOR_LIBEVENT_LIBS"
  513. else
  514. TOR_LIBEVENT_LIBS="-levent_openssl $TOR_LIBEVENT_LIBS"
  515. fi
  516. fi
  517. AC_SUBST(TOR_LIBEVENT_LIBS)
  518. dnl ------------------------------------------------------
  519. dnl Where do you live, libm?
  520. dnl On some platforms (Haiku/BeOS) the math library is
  521. dnl part of libroot. In which case don't link against lm
  522. TOR_LIB_MATH=""
  523. save_LIBS="$LIBS"
  524. AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
  525. if test "$ac_cv_search_pow" != "none required"; then
  526. TOR_LIB_MATH="$ac_cv_search_pow"
  527. fi
  528. LIBS="$save_LIBS"
  529. AC_SUBST(TOR_LIB_MATH)
  530. dnl ------------------------------------------------------
  531. dnl Where do you live, openssl? And how do we call you?
  532. tor_openssl_pkg_redhat="openssl"
  533. tor_openssl_pkg_debian="libssl-dev"
  534. tor_openssl_devpkg_redhat="openssl-devel"
  535. tor_openssl_devpkg_debian="libssl-dev"
  536. ALT_openssl_WITHVAL=""
  537. AC_ARG_WITH(ssl-dir,
  538. AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
  539. [
  540. if test "x$withval" != xno && test "x$withval" != "x" ; then
  541. ALT_openssl_WITHVAL="$withval"
  542. fi
  543. ])
  544. TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
  545. [#include <openssl/rand.h>],
  546. [void RAND_add(const void *buf, int num, double entropy);],
  547. [RAND_add((void*)0,0,0); exit(0);], [],
  548. [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
  549. dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
  550. if test "$enable_static_openssl" = "yes"; then
  551. if test "$tor_cv_library_openssl_dir" = "(system)"; then
  552. AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
  553. else
  554. TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
  555. fi
  556. else
  557. TOR_OPENSSL_LIBS="-lssl -lcrypto"
  558. fi
  559. AC_SUBST(TOR_OPENSSL_LIBS)
  560. dnl Now check for particular openssl functions.
  561. save_LIBS="$LIBS"
  562. save_LDFLAGS="$LDFLAGS"
  563. save_CPPFLAGS="$CPPFLAGS"
  564. LIBS="$TOR_OPENSSL_LIBS $LIBS"
  565. LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
  566. CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
  567. AC_TRY_COMPILE([
  568. #include <openssl/opensslv.h>
  569. #if OPENSSL_VERSION_NUMBER < 0x1000000fL
  570. #error "too old"
  571. #endif
  572. ], [],
  573. [ : ],
  574. [ AC_ERROR([OpenSSL is too old. We require 1.0.0 or later. You can specify a path to a newer one with --with-openssl-dir.]) ])
  575. AC_TRY_COMPILE([
  576. #include <openssl/opensslv.h>
  577. #include <openssl/evp.h>
  578. #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_ECDSA)
  579. #error "no ECC"
  580. #endif
  581. #if !defined(NID_X9_62_prime256v1) || !defined(NID_secp224r1)
  582. #error "curves unavailable"
  583. #endif
  584. ], [],
  585. [ : ],
  586. [ AC_ERROR([OpenSSL is built without full ECC support, including curves P256 and P224. You can specify a path to one with ECC support with --with-openssl-dir.]) ])
  587. AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
  588. [#include <openssl/ssl.h>
  589. ])
  590. AC_CHECK_FUNCS([ \
  591. SSL_SESSION_get_master_key \
  592. SSL_get_server_random \
  593. SSL_get_client_ciphers \
  594. SSL_get_client_random \
  595. SSL_CIPHER_find \
  596. TLS_method
  597. ])
  598. dnl Check if OpenSSL has scrypt implementation.
  599. AC_CHECK_FUNCS([ EVP_PBE_scrypt ])
  600. LIBS="$save_LIBS"
  601. LDFLAGS="$save_LDFLAGS"
  602. CPPFLAGS="$save_CPPFLAGS"
  603. dnl ------------------------------------------------------
  604. dnl Where do you live, zlib? And how do we call you?
  605. tor_zlib_pkg_redhat="zlib"
  606. tor_zlib_pkg_debian="zlib1g"
  607. tor_zlib_devpkg_redhat="zlib-devel"
  608. tor_zlib_devpkg_debian="zlib1g-dev"
  609. TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
  610. [#include <zlib.h>],
  611. [const char * zlibVersion(void);],
  612. [zlibVersion(); exit(0);], [--with-zlib-dir],
  613. [/opt/zlib])
  614. if test "$enable_static_zlib" = "yes"; then
  615. if test "$tor_cv_library_zlib_dir" = "(system)"; then
  616. AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
  617. using --enable-static-zlib")
  618. else
  619. TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
  620. fi
  621. else
  622. TOR_ZLIB_LIBS="-lz"
  623. fi
  624. AC_SUBST(TOR_ZLIB_LIBS)
  625. dnl ----------------------------------------------------------------------
  626. dnl Check if libcap is available for capabilities.
  627. tor_cap_pkg_debian="libcap2"
  628. tor_cap_pkg_redhat="libcap"
  629. tor_cap_devpkg_debian="libcap-dev"
  630. tor_cap_devpkg_redhat="libcap-devel"
  631. AC_CHECK_LIB([cap], [cap_init], [],
  632. AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
  633. )
  634. AC_CHECK_FUNCS(cap_set_proc)
  635. dnl ---------------------------------------------------------------------
  636. dnl Now that we know about our major libraries, we can check for compiler
  637. dnl and linker hardening options. We need to do this with the libraries known,
  638. dnl since sometimes the linker will like an option but not be willing to
  639. dnl use it with a build of a library.
  640. all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
  641. all_libs_for_check="$TOR_ZLIB_LIBS $TOR_LIB_MATH $TOR_LIBEVENT_LIBS $TOR_OPENSSL_LIBS $TOR_SYSTEMD_LIBS $TOR_LIB_WS32 $TOR_LIB_GDI $TOR_CAP_LIBS"
  642. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
  643. #if !defined(__clang__)
  644. #error
  645. #endif])], have_clang=yes, have_clang=no)
  646. if test x$enable_gcc_hardening != xno; then
  647. CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
  648. if test x$have_clang = xyes; then
  649. TOR_CHECK_CFLAGS(-Qunused-arguments)
  650. fi
  651. TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
  652. AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
  653. AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
  654. m4_ifdef([AS_VAR_IF],[
  655. AS_VAR_IF(can_compile, [yes],
  656. AS_VAR_IF(can_link, [yes],
  657. [],
  658. AC_MSG_ERROR([We tried to build with stack protection; it looks like your compiler supports it but your libc does not provide it. Are you missing libssp? (You can --disable-gcc-hardening to ignore this error.)]))
  659. )])
  660. AS_VAR_POPDEF([can_link])
  661. AS_VAR_POPDEF([can_compile])
  662. TOR_CHECK_CFLAGS(-Wstack-protector)
  663. TOR_CHECK_CFLAGS(-fwrapv)
  664. TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
  665. if test "$bwin32" = "false"; then
  666. TOR_CHECK_CFLAGS(-fPIE)
  667. TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
  668. fi
  669. fi
  670. if test x$enable_expensive_hardening = xyes ; then
  671. TOR_CHECK_CFLAGS([-fsanitize=address])
  672. TOR_CHECK_CFLAGS([-fsanitize=undefined])
  673. TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
  674. fi
  675. if test x$enable_linker_hardening != xno; then
  676. TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
  677. fi
  678. # For backtrace support
  679. TOR_CHECK_LDFLAGS(-rdynamic)
  680. dnl ------------------------------------------------------
  681. dnl Now see if we have a -fomit-frame-pointer compiler option.
  682. saved_CFLAGS="$CFLAGS"
  683. TOR_CHECK_CFLAGS(-fomit-frame-pointer)
  684. F_OMIT_FRAME_POINTER=''
  685. if test "$saved_CFLAGS" != "$CFLAGS"; then
  686. if test x$enable_expensive_hardening != xyes ; then
  687. F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
  688. fi
  689. fi
  690. CFLAGS="$saved_CFLAGS"
  691. AC_SUBST(F_OMIT_FRAME_POINTER)
  692. dnl ------------------------------------------------------
  693. dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
  694. dnl for us, as GCC 4.6 and later do at many optimization levels), then
  695. dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
  696. dnl code will work.
  697. TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
  698. dnl ============================================================
  699. dnl Check for libseccomp
  700. if test "x$enable_seccomp" != "xno"; then
  701. AC_CHECK_HEADERS([seccomp.h])
  702. AC_SEARCH_LIBS(seccomp_init, [seccomp])
  703. fi
  704. dnl ============================================================
  705. dnl Check for libscrypt
  706. if test "x$enable_libscrypt" != "xno"; then
  707. AC_CHECK_HEADERS([libscrypt.h])
  708. AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
  709. fi
  710. dnl ============================================================
  711. dnl We need an implementation of curve25519.
  712. dnl set these defaults.
  713. build_curve25519_donna=no
  714. build_curve25519_donna_c64=no
  715. use_curve25519_donna=no
  716. use_curve25519_nacl=no
  717. CURVE25519_LIBS=
  718. dnl The best choice is using curve25519-donna-c64, but that requires
  719. dnl that we
  720. AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
  721. tor_cv_can_use_curve25519_donna_c64,
  722. [AC_RUN_IFELSE(
  723. [AC_LANG_PROGRAM([dnl
  724. #include <stdint.h>
  725. typedef unsigned uint128_t __attribute__((mode(TI)));
  726. int func(uint64_t a, uint64_t b) {
  727. uint128_t c = ((uint128_t)a) * b;
  728. int ok = ((uint64_t)(c>>96)) == 522859 &&
  729. (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
  730. (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
  731. (((uint64_t)(c))&0xffffffffL) == 0;
  732. return ok;
  733. }
  734. ], [dnl
  735. int ok = func( ((uint64_t)2000000000) * 1000000000,
  736. ((uint64_t)1234567890) << 24);
  737. return !ok;
  738. ])],
  739. [tor_cv_can_use_curve25519_donna_c64=yes],
  740. [tor_cv_can_use_curve25519_donna_c64=no],
  741. [AC_LINK_IFELSE(
  742. [AC_LANG_PROGRAM([dnl
  743. #include <stdint.h>
  744. typedef unsigned uint128_t __attribute__((mode(TI)));
  745. int func(uint64_t a, uint64_t b) {
  746. uint128_t c = ((uint128_t)a) * b;
  747. int ok = ((uint64_t)(c>>96)) == 522859 &&
  748. (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
  749. (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
  750. (((uint64_t)(c))&0xffffffffL) == 0;
  751. return ok;
  752. }
  753. ], [dnl
  754. int ok = func( ((uint64_t)2000000000) * 1000000000,
  755. ((uint64_t)1234567890) << 24);
  756. return !ok;
  757. ])],
  758. [tor_cv_can_use_curve25519_donna_c64=cross],
  759. [tor_cv_can_use_curve25519_donna_c64=no])])])
  760. AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
  761. nacl/crypto_scalarmult_curve25519.h])
  762. AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
  763. tor_cv_can_use_curve25519_nacl,
  764. [tor_saved_LIBS="$LIBS"
  765. LIBS="$LIBS -lnacl"
  766. AC_LINK_IFELSE(
  767. [AC_LANG_PROGRAM([dnl
  768. #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
  769. #include <crypto_scalarmult_curve25519.h>
  770. #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
  771. #include <nacl/crypto_scalarmult_curve25519.h>
  772. #endif
  773. #ifdef crypto_scalarmult_curve25519_ref_BYTES
  774. #error Hey, this is the reference implementation! That's not fast.
  775. #endif
  776. ], [
  777. unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
  778. ])], [tor_cv_can_use_curve25519_nacl=yes],
  779. [tor_cv_can_use_curve25519_nacl=no])
  780. LIBS="$tor_saved_LIBS" ])
  781. dnl Okay, now we need to figure out which one to actually use. Fall back
  782. dnl to curve25519-donna.c
  783. if test x$tor_cv_can_use_curve25519_donna_c64 != xno; then
  784. build_curve25519_donna_c64=yes
  785. use_curve25519_donna=yes
  786. elif test x$tor_cv_can_use_curve25519_nacl = xyes; then
  787. use_curve25519_nacl=yes
  788. CURVE25519_LIBS=-lnacl
  789. else
  790. build_curve25519_donna=yes
  791. use_curve25519_donna=yes
  792. fi
  793. if test x$use_curve25519_donna = xyes; then
  794. AC_DEFINE(USE_CURVE25519_DONNA, 1,
  795. [Defined if we should use an internal curve25519_donna{,_c64} implementation])
  796. fi
  797. if test x$use_curve25519_nacl = xyes; then
  798. AC_DEFINE(USE_CURVE25519_NACL, 1,
  799. [Defined if we should use a curve25519 from nacl])
  800. fi
  801. AM_CONDITIONAL(BUILD_CURVE25519_DONNA, test x$build_curve25519_donna = xyes)
  802. AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64, test x$build_curve25519_donna_c64 = xyes)
  803. AC_SUBST(CURVE25519_LIBS)
  804. dnl Make sure to enable support for large off_t if available.
  805. AC_SYS_LARGEFILE
  806. AC_CHECK_HEADERS(
  807. assert.h \
  808. errno.h \
  809. fcntl.h \
  810. signal.h \
  811. string.h \
  812. sys/capability.h \
  813. sys/fcntl.h \
  814. sys/stat.h \
  815. sys/time.h \
  816. sys/types.h \
  817. time.h \
  818. unistd.h
  819. , , AC_MSG_WARN(Some headers were not found, compilation may fail. If compilation succeeds, please send your orconfig.h to the developers so we can fix this warning.))
  820. dnl These headers are not essential
  821. AC_CHECK_HEADERS(
  822. arpa/inet.h \
  823. crt_externs.h \
  824. execinfo.h \
  825. grp.h \
  826. ifaddrs.h \
  827. inttypes.h \
  828. limits.h \
  829. linux/types.h \
  830. machine/limits.h \
  831. malloc.h \
  832. malloc/malloc.h \
  833. malloc_np.h \
  834. netdb.h \
  835. netinet/in.h \
  836. netinet/in6.h \
  837. pwd.h \
  838. readpassphrase.h \
  839. stdint.h \
  840. sys/eventfd.h \
  841. sys/file.h \
  842. sys/ioctl.h \
  843. sys/limits.h \
  844. sys/mman.h \
  845. sys/param.h \
  846. sys/prctl.h \
  847. sys/resource.h \
  848. sys/select.h \
  849. sys/socket.h \
  850. sys/statvfs.h \
  851. sys/syscall.h \
  852. sys/sysctl.h \
  853. sys/syslimits.h \
  854. sys/time.h \
  855. sys/types.h \
  856. sys/un.h \
  857. sys/utime.h \
  858. sys/wait.h \
  859. syslog.h \
  860. utime.h
  861. )
  862. AC_CHECK_HEADERS(sys/param.h)
  863. AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
  864. [#ifdef HAVE_SYS_TYPES_H
  865. #include <sys/types.h>
  866. #endif
  867. #ifdef HAVE_SYS_SOCKET_H
  868. #include <sys/socket.h>
  869. #endif])
  870. AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
  871. [#ifdef HAVE_SYS_TYPES_H
  872. #include <sys/types.h>
  873. #endif
  874. #ifdef HAVE_SYS_SOCKET_H
  875. #include <sys/socket.h>
  876. #endif
  877. #ifdef HAVE_NET_IF_H
  878. #include <net/if.h>
  879. #endif
  880. #ifdef HAVE_NETINET_IN_H
  881. #include <netinet/in.h>
  882. #endif])
  883. AC_CHECK_HEADERS(linux/if.h,[],[],
  884. [
  885. #ifdef HAVE_SYS_SOCKET_H
  886. #include <sys/socket.h>
  887. #endif
  888. ])
  889. AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
  890. linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
  891. [#ifdef HAVE_SYS_TYPES_H
  892. #include <sys/types.h>
  893. #endif
  894. #ifdef HAVE_SYS_SOCKET_H
  895. #include <sys/socket.h>
  896. #endif
  897. #ifdef HAVE_LIMITS_H
  898. #include <limits.h>
  899. #endif
  900. #ifdef HAVE_LINUX_TYPES_H
  901. #include <linux/types.h>
  902. #endif
  903. #ifdef HAVE_NETINET_IN6_H
  904. #include <netinet/in6.h>
  905. #endif
  906. #ifdef HAVE_NETINET_IN_H
  907. #include <netinet/in.h>
  908. #endif])
  909. AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
  910. linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
  911. [#ifdef HAVE_SYS_TYPES_H
  912. #include <sys/types.h>
  913. #endif
  914. #ifdef HAVE_SYS_SOCKET_H
  915. #include <sys/socket.h>
  916. #endif
  917. #ifdef HAVE_LIMITS_H
  918. #include <limits.h>
  919. #endif
  920. #ifdef HAVE_LINUX_TYPES_H
  921. #include <linux/types.h>
  922. #endif
  923. #ifdef HAVE_NETINET_IN6_H
  924. #include <netinet/in6.h>
  925. #endif
  926. #ifdef HAVE_NETINET_IN_H
  927. #include <netinet/in.h>
  928. #endif
  929. #ifdef HAVE_LINUX_IF_H
  930. #include <linux/if.h>
  931. #endif])
  932. if test x$transparent = xtrue ; then
  933. transparent_ok=0
  934. if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
  935. transparent_ok=1
  936. fi
  937. if test x$linux_netfilter_ipv4 = x1 ; then
  938. transparent_ok=1
  939. fi
  940. if test x$linux_netfilter_ipv6_ip6_tables = x1 ; then
  941. transparent_ok=1
  942. fi
  943. if test x$transparent_ok = x1 ; then
  944. AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
  945. case $host in
  946. *-*-openbsd* | *-*-bitrig*)
  947. AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
  948. esac
  949. else
  950. AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
  951. fi
  952. fi
  953. AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
  954. [#ifdef HAVE_SYS_TYPES_H
  955. #include <sys/types.h>
  956. #endif
  957. #ifdef HAVE_SYS_TIME_H
  958. #include <sys/time.h>
  959. #endif])
  960. dnl In case we aren't given a working stdint.h, we'll need to grow our own.
  961. dnl Watch out.
  962. AC_CHECK_SIZEOF(int8_t)
  963. AC_CHECK_SIZEOF(int16_t)
  964. AC_CHECK_SIZEOF(int32_t)
  965. AC_CHECK_SIZEOF(int64_t)
  966. AC_CHECK_SIZEOF(uint8_t)
  967. AC_CHECK_SIZEOF(uint16_t)
  968. AC_CHECK_SIZEOF(uint32_t)
  969. AC_CHECK_SIZEOF(uint64_t)
  970. AC_CHECK_SIZEOF(intptr_t)
  971. AC_CHECK_SIZEOF(uintptr_t)
  972. dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
  973. AC_CHECK_SIZEOF(char)
  974. AC_CHECK_SIZEOF(short)
  975. AC_CHECK_SIZEOF(int)
  976. AC_CHECK_SIZEOF(long)
  977. AC_CHECK_SIZEOF(long long)
  978. AC_CHECK_SIZEOF(__int64)
  979. AC_CHECK_SIZEOF(void *)
  980. AC_CHECK_SIZEOF(time_t)
  981. AC_CHECK_SIZEOF(size_t)
  982. AC_CHECK_SIZEOF(pid_t)
  983. AC_CHECK_TYPES([uint, u_char, ssize_t])
  984. AC_PC_FROM_UCONTEXT([:])
  985. dnl used to include sockaddr_storage, but everybody has that.
  986. AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
  987. [#ifdef HAVE_SYS_TYPES_H
  988. #include <sys/types.h>
  989. #endif
  990. #ifdef HAVE_NETINET_IN_H
  991. #include <netinet/in.h>
  992. #endif
  993. #ifdef HAVE_NETINET_IN6_H
  994. #include <netinet/in6.h>
  995. #endif
  996. #ifdef HAVE_SYS_SOCKET_H
  997. #include <sys/socket.h>
  998. #endif
  999. #ifdef _WIN32
  1000. #define _WIN32_WINNT 0x0501
  1001. #define WIN32_LEAN_AND_MEAN
  1002. #include <winsock2.h>
  1003. #include <ws2tcpip.h>
  1004. #endif
  1005. ])
  1006. AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
  1007. [#ifdef HAVE_SYS_TYPES_H
  1008. #include <sys/types.h>
  1009. #endif
  1010. #ifdef HAVE_NETINET_IN_H
  1011. #include <netinet/in.h>
  1012. #endif
  1013. #ifdef HAVE_NETINET_IN6_H
  1014. #include <netinet/in6.h>
  1015. #endif
  1016. #ifdef HAVE_SYS_SOCKET_H
  1017. #include <sys/socket.h>
  1018. #endif
  1019. #ifdef _WIN32
  1020. #define _WIN32_WINNT 0x0501
  1021. #define WIN32_LEAN_AND_MEAN
  1022. #include <winsock2.h>
  1023. #include <ws2tcpip.h>
  1024. #endif
  1025. ])
  1026. AC_CHECK_TYPES([rlim_t], , ,
  1027. [#ifdef HAVE_SYS_TYPES_H
  1028. #include <sys/types.h>
  1029. #endif
  1030. #ifdef HAVE_SYS_TIME_H
  1031. #include <sys/time.h>
  1032. #endif
  1033. #ifdef HAVE_SYS_RESOURCE_H
  1034. #include <sys/resource.h>
  1035. #endif
  1036. ])
  1037. AX_CHECK_SIGN([time_t],
  1038. [ AC_DEFINE(TIME_T_IS_SIGNED, 1, [Define if time_t is signed]) ],
  1039. [ : ], [
  1040. #ifdef HAVE_SYS_TYPES_H
  1041. #include <sys/types.h>
  1042. #endif
  1043. #ifdef HAVE_SYS_TIME_H
  1044. #include <sys/time.h>
  1045. #endif
  1046. #ifdef HAVE_TIME_H
  1047. #include <time.h>
  1048. #endif
  1049. ])
  1050. if test "$ax_cv_decl_time_t_signed" = no; then
  1051. AC_MSG_WARN([You have an unsigned time_t; some things will probably break. Please tell the Tor developers about your interesting platform.])
  1052. fi
  1053. AX_CHECK_SIGN([size_t],
  1054. [ tor_cv_size_t_signed=yes ],
  1055. [ tor_cv_size_t_signed=no ], [
  1056. #ifdef HAVE_SYS_TYPES_H
  1057. #include <sys/types.h>
  1058. #endif
  1059. ])
  1060. if test "$ax_cv_decl_size_t_signed" = yes; then
  1061. AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
  1062. fi
  1063. AX_CHECK_SIGN([enum always],
  1064. [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
  1065. [ : ], [
  1066. enum always { AAA, BBB, CCC };
  1067. ])
  1068. AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
  1069. #ifdef HAVE_SYS_SOCKET_H
  1070. #include <sys/socket.h>
  1071. #endif
  1072. ])
  1073. # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
  1074. AC_CHECK_SIZEOF(cell_t)
  1075. # Now make sure that NULL can be represented as zero bytes.
  1076. AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
  1077. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1078. [[#include <stdlib.h>
  1079. #include <string.h>
  1080. #include <stdio.h>
  1081. #ifdef HAVE_STDDEF_H
  1082. #include <stddef.h>
  1083. #endif
  1084. int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
  1085. return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
  1086. [tor_cv_null_is_zero=yes],
  1087. [tor_cv_null_is_zero=no],
  1088. [tor_cv_null_is_zero=cross])])
  1089. if test "$tor_cv_null_is_zero" = cross ; then
  1090. # Cross-compiling; let's hope that the target isn't raving mad.
  1091. AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
  1092. fi
  1093. if test "$tor_cv_null_is_zero" != no; then
  1094. AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
  1095. [Define to 1 iff memset(0) sets pointers to NULL])
  1096. fi
  1097. AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
  1098. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1099. [[#include <stdlib.h>
  1100. #include <string.h>
  1101. #include <stdio.h>
  1102. #ifdef HAVE_STDDEF_H
  1103. #include <stddef.h>
  1104. #endif
  1105. int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
  1106. return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
  1107. [tor_cv_dbl0_is_zero=yes],
  1108. [tor_cv_dbl0_is_zero=no],
  1109. [tor_cv_dbl0_is_zero=cross])])
  1110. if test "$tor_cv_dbl0_is_zero" = cross ; then
  1111. # Cross-compiling; let's hope that the target isn't raving mad.
  1112. AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
  1113. fi
  1114. if test "$tor_cv_dbl0_is_zero" != no; then
  1115. AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
  1116. [Define to 1 iff memset(0) sets doubles to 0.0])
  1117. fi
  1118. # And what happens when we malloc zero?
  1119. AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
  1120. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1121. [[#include <stdlib.h>
  1122. #include <string.h>
  1123. #include <stdio.h>
  1124. #ifdef HAVE_STDDEF_H
  1125. #include <stddef.h>
  1126. #endif
  1127. int main () { return malloc(0)?0:1; }]])],
  1128. [tor_cv_malloc_zero_works=yes],
  1129. [tor_cv_malloc_zero_works=no],
  1130. [tor_cv_malloc_zero_works=cross])])
  1131. if test "$tor_cv_malloc_zero_works" = cross; then
  1132. # Cross-compiling; let's hope that the target isn't raving mad.
  1133. AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
  1134. fi
  1135. if test "$tor_cv_malloc_zero_works" = yes; then
  1136. AC_DEFINE([MALLOC_ZERO_WORKS], 1,
  1137. [Define to 1 iff malloc(0) returns a pointer])
  1138. fi
  1139. # whether we seem to be in a 2s-complement world.
  1140. AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
  1141. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1142. [[int main () { int problem = ((-99) != (~99)+1);
  1143. return problem ? 1 : 0; }]])],
  1144. [tor_cv_twos_complement=yes],
  1145. [tor_cv_twos_complement=no],
  1146. [tor_cv_twos_complement=cross])])
  1147. if test "$tor_cv_twos_complement" = cross ; then
  1148. # Cross-compiling; let's hope that the target isn't raving mad.
  1149. AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
  1150. fi
  1151. if test "$tor_cv_twos_complement" != no ; then
  1152. AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
  1153. [Define to 1 iff we represent negative integers with two's complement])
  1154. fi
  1155. # What does shifting a negative value do?
  1156. AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
  1157. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1158. [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
  1159. [tor_cv_sign_extend=yes],
  1160. [tor_cv_sign_extend=no],
  1161. [tor_cv_sign_extend=cross])])
  1162. if test "$tor_cv_sign_extend" = cross ; then
  1163. # Cross-compiling; let's hope that the target isn't raving mad.
  1164. AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
  1165. fi
  1166. if test "$tor_cv_sign_extend" != no ; then
  1167. AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
  1168. [Define to 1 iff right-shifting a negative value performs sign-extension])
  1169. fi
  1170. # Whether we should use the dmalloc memory allocation debugging library.
  1171. AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
  1172. AC_ARG_WITH(dmalloc,
  1173. AS_HELP_STRING(--with-dmalloc, [use debug memory allocation library]),
  1174. [if [[ "$withval" = "yes" ]]; then
  1175. dmalloc=1
  1176. AC_MSG_RESULT(yes)
  1177. else
  1178. dmalloc=1
  1179. AC_MSG_RESULT(no)
  1180. fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
  1181. )
  1182. if [[ $dmalloc -eq 1 ]]; then
  1183. AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
  1184. AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
  1185. AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
  1186. AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
  1187. fi
  1188. AC_ARG_WITH(tcmalloc,
  1189. AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library]),
  1190. [ tcmalloc=yes ], [ tcmalloc=no ])
  1191. if test x$tcmalloc = xyes ; then
  1192. LDFLAGS="-ltcmalloc $LDFLAGS"
  1193. fi
  1194. using_custom_malloc=no
  1195. if test x$enable_openbsd_malloc = xyes ; then
  1196. using_custom_malloc=yes
  1197. fi
  1198. if test x$tcmalloc = xyes ; then
  1199. using_custom_malloc=yes
  1200. fi
  1201. if test $using_custom_malloc = no ; then
  1202. AC_CHECK_FUNCS(mallinfo)
  1203. fi
  1204. # By default, we're going to assume we don't have mlockall()
  1205. # bionic and other platforms have various broken mlockall subsystems.
  1206. # Some systems don't have a working mlockall, some aren't linkable,
  1207. # and some have it but don't declare it.
  1208. AC_CHECK_FUNCS(mlockall)
  1209. AC_CHECK_DECLS([mlockall], , , [
  1210. #ifdef HAVE_SYS_MMAN_H
  1211. #include <sys/mman.h>
  1212. #endif])
  1213. # Allow user to specify an alternate syslog facility
  1214. AC_ARG_WITH(syslog-facility,
  1215. AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
  1216. syslog_facility="$withval", syslog_facility="LOG_DAEMON")
  1217. AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
  1218. AC_SUBST(LOGFACILITY)
  1219. # Check if we have getresuid and getresgid
  1220. AC_CHECK_FUNCS(getresuid getresgid)
  1221. # Check for gethostbyname_r in all its glorious incompatible versions.
  1222. # (This logic is based on that in Python's configure.in)
  1223. AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
  1224. [Define this if you have any gethostbyname_r()])
  1225. AC_CHECK_FUNC(gethostbyname_r, [
  1226. AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
  1227. OLD_CFLAGS=$CFLAGS
  1228. CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
  1229. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
  1230. #include <netdb.h>
  1231. ], [[
  1232. char *cp1, *cp2;
  1233. struct hostent *h1, *h2;
  1234. int i1, i2;
  1235. (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
  1236. ]])],[
  1237. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  1238. AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
  1239. [Define this if gethostbyname_r takes 6 arguments])
  1240. AC_MSG_RESULT(6)
  1241. ], [
  1242. AC_TRY_COMPILE([
  1243. #include <netdb.h>
  1244. ], [
  1245. char *cp1, *cp2;
  1246. struct hostent *h1;
  1247. int i1, i2;
  1248. (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
  1249. ], [
  1250. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  1251. AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
  1252. [Define this if gethostbyname_r takes 5 arguments])
  1253. AC_MSG_RESULT(5)
  1254. ], [
  1255. AC_TRY_COMPILE([
  1256. #include <netdb.h>
  1257. ], [
  1258. char *cp1;
  1259. struct hostent *h1;
  1260. struct hostent_data hd;
  1261. (void) gethostbyname_r(cp1,h1,&hd);
  1262. ], [
  1263. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  1264. AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
  1265. [Define this if gethostbyname_r takes 3 arguments])
  1266. AC_MSG_RESULT(3)
  1267. ], [
  1268. AC_MSG_RESULT(0)
  1269. ])
  1270. ])
  1271. ])
  1272. CFLAGS=$OLD_CFLAGS
  1273. ])
  1274. AC_CACHE_CHECK([whether the C compiler supports __func__],
  1275. tor_cv_have_func_macro,
  1276. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  1277. #include <stdio.h>
  1278. int main(int c, char **v) { puts(__func__); }])],
  1279. tor_cv_have_func_macro=yes,
  1280. tor_cv_have_func_macro=no))
  1281. AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
  1282. tor_cv_have_FUNC_macro,
  1283. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  1284. #include <stdio.h>
  1285. int main(int c, char **v) { puts(__FUNC__); }])],
  1286. tor_cv_have_FUNC_macro=yes,
  1287. tor_cv_have_FUNC_macro=no))
  1288. AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
  1289. tor_cv_have_FUNCTION_macro,
  1290. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  1291. #include <stdio.h>
  1292. int main(int c, char **v) { puts(__FUNCTION__); }])],
  1293. tor_cv_have_FUNCTION_macro=yes,
  1294. tor_cv_have_FUNCTION_macro=no))
  1295. AC_CACHE_CHECK([whether we have extern char **environ already declared],
  1296. tor_cv_have_environ_declared,
  1297. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  1298. /* We define _GNU_SOURCE here because it is also defined in compat.c.
  1299. * Without it environ doesn't get declared. */
  1300. #define _GNU_SOURCE
  1301. #ifdef HAVE_UNISTD_H
  1302. #include <unistd.h>
  1303. #endif
  1304. #include <stdlib.h>
  1305. int main(int c, char **v) { char **t = environ; }])],
  1306. tor_cv_have_environ_declared=yes,
  1307. tor_cv_have_environ_declared=no))
  1308. if test "$tor_cv_have_func_macro" = 'yes'; then
  1309. AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
  1310. fi
  1311. if test "$tor_cv_have_FUNC_macro" = 'yes'; then
  1312. AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
  1313. fi
  1314. if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
  1315. AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
  1316. [Defined if the compiler supports __FUNCTION__])
  1317. fi
  1318. if test "$tor_cv_have_environ_declared" = 'yes'; then
  1319. AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
  1320. [Defined if we have extern char **environ already declared])
  1321. fi
  1322. # $prefix stores the value of the --prefix command line option, or
  1323. # NONE if the option wasn't set. In the case that it wasn't set, make
  1324. # it be the default, so that we can use it to expand directories now.
  1325. if test "x$prefix" = "xNONE"; then
  1326. prefix=$ac_default_prefix
  1327. fi
  1328. # and similarly for $exec_prefix
  1329. if test "x$exec_prefix" = "xNONE"; then
  1330. exec_prefix=$prefix
  1331. fi
  1332. if test "x$BUILDDIR" = "x"; then
  1333. BUILDDIR=`pwd`
  1334. fi
  1335. AC_SUBST(BUILDDIR)
  1336. AH_TEMPLATE([BUILDDIR],[tor's build directory])
  1337. AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
  1338. if test "x$CONFDIR" = "x"; then
  1339. CONFDIR=`eval echo $sysconfdir/tor`
  1340. fi
  1341. AC_SUBST(CONFDIR)
  1342. AH_TEMPLATE([CONFDIR],[tor's configuration directory])
  1343. AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
  1344. BINDIR=`eval echo $bindir`
  1345. AC_SUBST(BINDIR)
  1346. LOCALSTATEDIR=`eval echo $localstatedir`
  1347. AC_SUBST(LOCALSTATEDIR)
  1348. if test "$bwin32" = true; then
  1349. # Test if the linker supports the --nxcompat and --dynamicbase options
  1350. # for Windows
  1351. save_LDFLAGS="$LDFLAGS"
  1352. LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
  1353. AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
  1354. AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
  1355. [AC_MSG_RESULT([yes])]
  1356. [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
  1357. [AC_MSG_RESULT([no])]
  1358. )
  1359. LDFLAGS="$save_LDFLAGS"
  1360. fi
  1361. # Set CFLAGS _after_ all the above checks, since our warnings are stricter
  1362. # than autoconf's macros like.
  1363. if test "$GCC" = yes; then
  1364. # Disable GCC's strict aliasing checks. They are an hours-to-debug
  1365. # accident waiting to happen.
  1366. CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
  1367. else
  1368. # Override optimization level for non-gcc compilers
  1369. CFLAGS="$CFLAGS -O"
  1370. enable_gcc_warnings=no
  1371. enable_gcc_warnings_advisory=no
  1372. fi
  1373. # OS X Lion started deprecating the system openssl. Let's just disable
  1374. # all deprecation warnings on OS X. Also, to potentially make the binary
  1375. # a little smaller, let's enable dead_strip.
  1376. case "$host_os" in
  1377. darwin*)
  1378. CFLAGS="$CFLAGS -Wno-deprecated-declarations"
  1379. LDFLAGS="$LDFLAGS -dead_strip" ;;
  1380. esac
  1381. # Add some more warnings which we use in development but not in the
  1382. # released versions. (Some relevant gcc versions can't handle these.)
  1383. if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xyes; then
  1384. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
  1385. #if !defined(__GNUC__) || (__GNUC__ < 4)
  1386. #error
  1387. #endif])], have_gcc4=yes, have_gcc4=no)
  1388. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
  1389. #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
  1390. #error
  1391. #endif])], have_gcc42=yes, have_gcc42=no)
  1392. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
  1393. #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
  1394. #error
  1395. #endif])], have_gcc43=yes, have_gcc43=no)
  1396. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
  1397. #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
  1398. #error
  1399. #endif])], have_gcc46=yes, have_gcc46=no)
  1400. save_CFLAGS="$CFLAGS"
  1401. CFLAGS="$CFLAGS -Wshorten-64-to-32"
  1402. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes,
  1403. have_shorten64_flag=no)
  1404. CFLAGS="$save_CFLAGS"
  1405. case $host in
  1406. *-*-openbsd* | *-*-bitrig*)
  1407. # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
  1408. # That's fine, except that the headers don't pass -Wredundant-decls.
  1409. # Therefore, let's disable -Wsystem-headers when we're building
  1410. # with maximal warnings on OpenBSD.
  1411. CFLAGS="$CFLAGS -Wno-system-headers" ;;
  1412. esac
  1413. CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
  1414. CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
  1415. CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
  1416. CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations -Wredundant-decls"
  1417. CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
  1418. if test x$enable_gcc_warnings = xyes; then
  1419. CFLAGS="$CFLAGS -Werror"
  1420. fi
  1421. # Disabled, so we can use mallinfo(): -Waggregate-return
  1422. if test x$have_gcc4 = xyes ; then
  1423. # These warnings break gcc 3.3.5 and work on gcc 4.0.2
  1424. CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wold-style-definition"
  1425. fi
  1426. if test x$have_gcc42 = xyes ; then
  1427. # These warnings break gcc 4.0.2 and work on gcc 4.2
  1428. # XXXX020 See if any of these work with earlier versions.
  1429. CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wstrict-overflow=1"
  1430. # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
  1431. fi
  1432. if test x$have_gcc42 = xyes && test x$have_clang = xno; then
  1433. # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
  1434. CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
  1435. fi
  1436. if test x$have_gcc43 = xyes ; then
  1437. # These warnings break gcc 4.2 and work on gcc 4.3
  1438. # XXXX020 See if any of these work with earlier versions.
  1439. CFLAGS="$CFLAGS -Wextra -Warray-bounds"
  1440. fi
  1441. if test x$have_gcc46 = xyes ; then
  1442. # This warning was added in gcc 4.3, but it appears to generate
  1443. # spurious warnings in gcc 4.4. I don't know if it works in 4.5.
  1444. CFLAGS="$CFLAGS -Wlogical-op"
  1445. fi
  1446. if test x$have_shorten64_flag = xyes ; then
  1447. CFLAGS="$CFLAGS -Wshorten-64-to-32"
  1448. fi
  1449. ##This will break the world on some 64-bit architectures
  1450. # CFLAGS="$CFLAGS -Winline"
  1451. fi
  1452. if test "$enable_coverage" = yes && test "$have_clang" = "no"; then
  1453. case "$host_os" in
  1454. darwin*)
  1455. AC_MSG_WARN([Tried to enable coverage on OSX without using the clang compiler. This might not work! If coverage fails, use CC=clang when configuring with --enable-profiling.])
  1456. esac
  1457. fi
  1458. CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
  1459. AC_CONFIG_FILES([
  1460. Doxyfile
  1461. Makefile
  1462. contrib/dist/suse/tor.sh
  1463. contrib/operator-tools/tor.logrotate
  1464. contrib/dist/tor.sh
  1465. contrib/dist/torctl
  1466. contrib/dist/tor.service
  1467. src/config/torrc.sample
  1468. src/config/torrc.minimal
  1469. scripts/maint/checkOptionDocs.pl
  1470. scripts/maint/updateVersions.pl
  1471. ])
  1472. if test x$asciidoc = xtrue && test "$ASCIIDOC" = "none" ; then
  1473. regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
  1474. for file in $regular_mans ; do
  1475. if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
  1476. echo "==================================";
  1477. echo;
  1478. echo "Building Tor has failed since manpages cannot be built.";
  1479. echo;
  1480. echo "You need asciidoc installed to be able to build the manpages.";
  1481. echo "To build without manpages, use the --disable-asciidoc argument";
  1482. echo "when calling configure.";
  1483. echo;
  1484. echo "==================================";
  1485. exit 1;
  1486. fi
  1487. done
  1488. fi
  1489. AC_OUTPUT