configure.ac 53 KB

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