configure.in 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  1. dnl Copyright (c) 2001-2004, Roger Dingledine
  2. dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
  3. dnl Copyright (c) 2007-2012, The Tor Project, Inc.
  4. dnl See LICENSE for licensing information
  5. AC_INIT([tor],[0.2.4.0-alpha-dev])
  6. AC_CONFIG_SRCDIR([src/or/main.c])
  7. AM_INIT_AUTOMAKE
  8. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
  9. AC_CONFIG_HEADERS([orconfig.h])
  10. AC_CANONICAL_HOST
  11. if test -f /etc/redhat-release ; then
  12. if test -f /usr/kerberos/include ; then
  13. CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
  14. fi
  15. fi
  16. # Not a no-op; we want to make sure that CPPFLAGS is set before we use
  17. # the += operator on it in src/or/Makefile.am
  18. CPPFLAGS="$CPPFLAGS -I\${top_srcdir}/src/common"
  19. #XXXX020 We should make these enabled or not, before 0.2.0.x-final
  20. AC_ARG_ENABLE(buf-freelists,
  21. AS_HELP_STRING(--disable-buf-freelists, disable freelists for buffer RAM))
  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. if test "$enable_static_tor" = "yes"; then
  35. enable_static_libevent="yes";
  36. enable_static_openssl="yes";
  37. enable_static_zlib="yes";
  38. CFLAGS="$CFLAGS -static"
  39. fi
  40. if test x$enable_buf_freelists != xno; then
  41. AC_DEFINE(ENABLE_BUF_FREELISTS, 1,
  42. [Defined if we try to use freelists for buffer RAM chunks])
  43. fi
  44. AM_CONDITIONAL(USE_OPENBSD_MALLOC, test x$enable_openbsd_malloc = xyes)
  45. if test x$enable_instrument_downloads = xyes; then
  46. AC_DEFINE(INSTRUMENT_DOWNLOADS, 1,
  47. [Defined if we want to keep track of how much of each kind of resource we download.])
  48. fi
  49. AC_ARG_ENABLE(transparent,
  50. AS_HELP_STRING(--disable-transparent, disable transparent proxy support),
  51. [case "${enableval}" in
  52. yes) transparent=true ;;
  53. no) transparent=false ;;
  54. *) AC_MSG_ERROR(bad value for --enable-transparent) ;;
  55. esac], [transparent=true])
  56. AC_ARG_ENABLE(asciidoc,
  57. AS_HELP_STRING(--disable-asciidoc, don't use asciidoc (disables building of manpages)),
  58. [case "${enableval}" in
  59. yes) asciidoc=true ;;
  60. no) asciidoc=false ;;
  61. *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
  62. esac], [asciidoc=true])
  63. # By default, we're not ready to ship a NAT-PMP aware Tor
  64. AC_ARG_ENABLE(nat-pmp,
  65. AS_HELP_STRING(--enable-nat-pmp, enable NAT-PMP support),
  66. [case "${enableval}" in
  67. yes) natpmp=true ;;
  68. no) natpmp=false ;;
  69. * ) AC_MSG_ERROR(bad value for --enable-nat-pmp) ;;
  70. esac], [natpmp=false])
  71. # By default, we're not ready to ship a UPnP aware Tor
  72. AC_ARG_ENABLE(upnp,
  73. AS_HELP_STRING(--enable-upnp, enable UPnP support),
  74. [case "${enableval}" in
  75. yes) upnp=true ;;
  76. no) upnp=false ;;
  77. * ) AC_MSG_ERROR(bad value for --enable-upnp) ;;
  78. esac], [upnp=false])
  79. AC_ARG_ENABLE(threads,
  80. AS_HELP_STRING(--disable-threads, disable multi-threading support))
  81. if test x$enable_threads = x; then
  82. case $host in
  83. *-*-solaris* )
  84. # Don't try multithreading on solaris -- cpuworkers seem to lock.
  85. AC_MSG_NOTICE([You are running Solaris; Sometimes threading makes
  86. cpu workers lock up here, so I will disable threads.])
  87. enable_threads="no";;
  88. *)
  89. enable_threads="yes";;
  90. esac
  91. fi
  92. if test "$enable_threads" = "yes"; then
  93. AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
  94. fi
  95. case $host in
  96. *-*-solaris* )
  97. AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
  98. ;;
  99. esac
  100. AC_ARG_ENABLE(gcc-warnings,
  101. AS_HELP_STRING(--enable-gcc-warnings, enable verbose warnings))
  102. AC_ARG_ENABLE(gcc-warnings-advisory,
  103. AS_HELP_STRING(--enable-gcc-warnings-advisory, [enable verbose warnings, excluding -Werror]))
  104. dnl Adam shostack suggests the following for Windows:
  105. dnl -D_FORTIFY_SOURCE=2 -fstack-protector-all
  106. dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
  107. dnl This requires that we use gcc and that we add -O2 to the CFLAGS.
  108. AC_ARG_ENABLE(gcc-hardening,
  109. AS_HELP_STRING(--disable-gcc-hardening, disable compiler security checks))
  110. dnl Linker hardening options
  111. dnl Currently these options are ELF specific - you can't use this with MacOSX
  112. AC_ARG_ENABLE(linker-hardening,
  113. AS_HELP_STRING(--disable-linker-hardening, disable linker security fixups))
  114. AC_ARG_ENABLE(local-appdata,
  115. AS_HELP_STRING(--enable-local-appdata, default to host local application data paths on Windows))
  116. if test "$enable_local_appdata" = "yes"; then
  117. AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
  118. [Defined if we default to host local appdata paths on Windows])
  119. fi
  120. # Tor2web mode flag
  121. AC_ARG_ENABLE(tor2web-mode,
  122. AS_HELP_STRING(--enable-tor2web-mode, support tor2web non-anonymous mode),
  123. [if test x$enableval = xyes; then
  124. CFLAGS="$CFLAGS -D ENABLE_TOR2WEB_MODE=1"
  125. fi])
  126. AC_ARG_ENABLE(bufferevents,
  127. AS_HELP_STRING(--enable-bufferevents, use Libevent's buffered IO.))
  128. dnl check for the correct "ar" when cross-compiling
  129. AN_MAKEVAR([AR], [AC_PROG_AR])
  130. AN_PROGRAM([ar], [AC_PROG_AR])
  131. AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [ar])])
  132. AC_PROG_AR
  133. AC_PROG_CC
  134. AC_PROG_CPP
  135. AC_PROG_MAKE_SET
  136. AC_PROG_RANLIB
  137. dnl autoconf 2.59 appears not to support AC_PROG_SED
  138. AC_CHECK_PROG([SED],[sed],[sed],[/bin/false])
  139. dnl check for asciidoc and a2x
  140. AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
  141. AC_PATH_PROG([A2X], [a2x], none)
  142. AM_CONDITIONAL(USE_ASCIIDOC, test x$asciidoc = xtrue)
  143. AM_CONDITIONAL(USE_FW_HELPER, test x$natpmp = xtrue || test x$upnp = xtrue)
  144. AM_CONDITIONAL(NAT_PMP, test x$natpmp = xtrue)
  145. AM_CONDITIONAL(MINIUPNPC, test x$upnp = xtrue)
  146. AM_PROG_CC_C_O
  147. ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
  148. AC_C_FLEXIBLE_ARRAY_MEMBER
  149. ], [
  150. dnl Maybe we've got an old autoconf...
  151. AC_CACHE_CHECK([for flexible array members],
  152. tor_cv_c_flexarray,
  153. [AC_COMPILE_IFELSE(
  154. AC_LANG_PROGRAM([
  155. struct abc { int a; char b[]; };
  156. ], [
  157. struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
  158. def->b[0] = 33;
  159. ]),
  160. [tor_cv_c_flexarray=yes],
  161. [tor_cv_c_flexarray=no])])
  162. if test $tor_cv_flexarray = yes ; then
  163. AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
  164. else
  165. AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
  166. fi
  167. ])
  168. AC_PATH_PROG([SHA1SUM], [sha1sum], none)
  169. AC_PATH_PROG([OPENSSL], [openssl], none)
  170. TORUSER=_tor
  171. AC_ARG_WITH(tor-user,
  172. [ --with-tor-user=NAME Specify username for tor daemon ],
  173. [
  174. TORUSER=$withval
  175. ]
  176. )
  177. AC_SUBST(TORUSER)
  178. TORGROUP=_tor
  179. AC_ARG_WITH(tor-group,
  180. [ --with-tor-group=NAME Specify group name for tor daemon ],
  181. [
  182. TORGROUP=$withval
  183. ]
  184. )
  185. AC_SUBST(TORGROUP)
  186. dnl If _WIN32 is defined and non-zero, we are building for win32
  187. AC_MSG_CHECKING([for win32])
  188. AC_RUN_IFELSE([AC_LANG_SOURCE([
  189. int main(int c, char **v) {
  190. #ifdef _WIN32
  191. #if _WIN32
  192. return 0;
  193. #else
  194. return 1;
  195. #endif
  196. #else
  197. return 2;
  198. #endif
  199. }])],
  200. bwin32=true; AC_MSG_RESULT([yes]),
  201. bwin32=false; AC_MSG_RESULT([no]),
  202. bwin32=cross; AC_MSG_RESULT([cross])
  203. )
  204. if test "$bwin32" = cross; then
  205. AC_MSG_CHECKING([for win32 (cross)])
  206. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  207. #ifdef _WIN32
  208. int main(int c, char **v) {return 0;}
  209. #else
  210. #error
  211. int main(int c, char **v) {return x(y);}
  212. #endif
  213. ])],
  214. bwin32=true; AC_MSG_RESULT([yes]),
  215. bwin32=false; AC_MSG_RESULT([no]))
  216. fi
  217. AM_CONDITIONAL(BUILD_NT_SERVICES, test x$bwin32 = xtrue)
  218. dnl Enable C99 when compiling with MIPSpro
  219. AC_MSG_CHECKING([for MIPSpro compiler])
  220. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
  221. #if (defined(__sgi) && defined(_COMPILER_VERSION))
  222. #error
  223. return x(y);
  224. #endif
  225. ])],
  226. bmipspro=false; AC_MSG_RESULT(no),
  227. bmipspro=true; AC_MSG_RESULT(yes))
  228. if test "$bmipspro" = true; then
  229. CFLAGS="$CFLAGS -c99"
  230. fi
  231. AC_C_BIGENDIAN
  232. AC_SEARCH_LIBS(socket, [socket network])
  233. AC_SEARCH_LIBS(gethostbyname, [nsl])
  234. AC_SEARCH_LIBS(dlopen, [dl])
  235. AC_SEARCH_LIBS(inet_aton, [resolv])
  236. saved_LIBS="$LIBS"
  237. AC_SEARCH_LIBS([clock_gettime], [rt])
  238. if test "$LIBS" != "$saved_LIBS"; then
  239. # Looks like we need -lrt for clock_gettime().
  240. have_rt=yes
  241. fi
  242. if test "$enable_threads" = "yes"; then
  243. AC_SEARCH_LIBS(pthread_create, [pthread])
  244. AC_SEARCH_LIBS(pthread_detach, [pthread])
  245. fi
  246. dnl -------------------------------------------------------------------
  247. dnl Check for functions before libevent, since libevent-1.2 apparently
  248. dnl exports strlcpy without defining it in a header.
  249. AC_CHECK_FUNCS(
  250. _NSGetEnviron \
  251. accept4 \
  252. clock_gettime \
  253. flock \
  254. ftime \
  255. getaddrinfo \
  256. getifaddrs \
  257. getrlimit \
  258. gettimeofday \
  259. gmtime_r \
  260. inet_aton \
  261. ioctl \
  262. issetugid \
  263. localtime_r \
  264. lround \
  265. memmem \
  266. prctl \
  267. rint \
  268. socketpair \
  269. strlcat \
  270. strlcpy \
  271. strptime \
  272. strtok_r \
  273. strtoull \
  274. sysconf \
  275. uname \
  276. vasprintf \
  277. )
  278. if test "$enable_threads" = "yes"; then
  279. AC_CHECK_HEADERS(pthread.h)
  280. AC_CHECK_FUNCS(pthread_create)
  281. fi
  282. dnl ------------------------------------------------------
  283. dnl Where do you live, libevent? And how do we call you?
  284. if test "$bwin32" = true; then
  285. TOR_LIB_WS32=-lws2_32
  286. TOR_LIB_IPHLPAPI=-liphlpapi
  287. # Some of the cargo-cults recommend -lwsock32 as well, but I don't
  288. # think it's actually necessary.
  289. TOR_LIB_GDI=-lgdi32
  290. else
  291. TOR_LIB_WS32=
  292. TOR_LIB_GDI=
  293. fi
  294. AC_SUBST(TOR_LIB_WS32)
  295. AC_SUBST(TOR_LIB_GDI)
  296. AC_SUBST(TOR_LIB_IPHLPAPI)
  297. dnl We need to do this before we try our disgusting hack below.
  298. AC_CHECK_HEADERS([sys/types.h])
  299. dnl This is a disgusting hack so we safely include older libevent headers.
  300. AC_CHECK_TYPE(u_int64_t, unsigned long long)
  301. AC_CHECK_TYPE(u_int32_t, unsigned long)
  302. AC_CHECK_TYPE(u_int16_t, unsigned short)
  303. AC_CHECK_TYPE(u_int8_t, unsigned char)
  304. tor_libevent_pkg_redhat="libevent"
  305. tor_libevent_pkg_debian="libevent-dev"
  306. tor_libevent_devpkg_redhat="libevent-devel"
  307. tor_libevent_devpkg_debian="libevent-dev"
  308. dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
  309. dnl linking for static builds.
  310. STATIC_LIBEVENT_FLAGS=""
  311. if test "$enable_static_libevent" = "yes"; then
  312. if test "$have_rt" = yes; then
  313. STATIC_LIBEVENT_FLAGS=" -lrt "
  314. fi
  315. fi
  316. TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
  317. #ifdef _WIN32
  318. #include <winsock2.h>
  319. #endif
  320. #include <stdlib.h>
  321. #include <sys/time.h>
  322. #include <sys/types.h>
  323. #include <event.h>], [
  324. #ifdef _WIN32
  325. #include <winsock2.h>
  326. #endif
  327. void exit(int); void *event_init(void);],
  328. [
  329. #ifdef _WIN32
  330. {WSADATA d; WSAStartup(0x101,&d); }
  331. #endif
  332. event_init(); exit(0);
  333. ], [--with-libevent-dir], [/opt/libevent])
  334. dnl Now check for particular libevent functions.
  335. save_LIBS="$LIBS"
  336. save_LDFLAGS="$LDFLAGS"
  337. save_CPPFLAGS="$CPPFLAGS"
  338. LIBS="-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $LIBS"
  339. LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
  340. CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
  341. AC_CHECK_FUNCS(event_get_version event_get_version_number event_get_method event_set_log_callback evdns_set_outgoing_bind_address event_base_loopexit)
  342. AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
  343. [#include <event.h>
  344. ])
  345. AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
  346. LIBS="$save_LIBS"
  347. LDFLAGS="$save_LDFLAGS"
  348. CPPFLAGS="$save_CPPFLAGS"
  349. AM_CONDITIONAL(USE_EXTERNAL_EVDNS, test x$ac_cv_header_event2_dns_h = xyes)
  350. if test "$enable_static_libevent" = "yes"; then
  351. if test "$tor_cv_library_libevent_dir" = "(system)"; then
  352. AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
  353. else
  354. TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
  355. fi
  356. else
  357. TOR_LIBEVENT_LIBS="-levent"
  358. fi
  359. dnl This isn't the best test for Libevent 2.0.3-alpha. Once it's released,
  360. dnl we can do much better.
  361. if test "$enable_bufferevents" = "yes" ; then
  362. if test "$ac_cv_header_event2_bufferevent_ssl_h" != "yes" ; then
  363. 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.])
  364. else
  365. CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
  366. # Check for the right version. First see if version detection works.
  367. AC_MSG_CHECKING([whether we can detect the Libevent version])
  368. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  369. #include <event2/event.h>
  370. #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 10
  371. #error
  372. int x = y(zz);
  373. #else
  374. int x = 1;
  375. #endif
  376. ])], [event_version_number_works=yes; AC_MSG_RESULT([yes]) ],
  377. [event_version_number_works=no; AC_MSG_RESULT([no])])
  378. if test "$event_version_number_works" != 'yes'; then
  379. AC_MSG_WARN([Version detection on Libevent seems broken. Your Libevent installation is probably screwed up or very old.])
  380. else
  381. AC_MSG_CHECKING([whether Libevent is new enough for bufferevents])
  382. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  383. #include <event2/event.h>
  384. #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000d00
  385. #error
  386. int x = y(zz);
  387. #else
  388. int x = 1;
  389. #endif
  390. ])], [ AC_MSG_RESULT([yes]) ],
  391. [ AC_MSG_RESULT([no])
  392. AC_MSG_ERROR([Libevent does not seem new enough to support bufferevents. We require 2.0.13-stable or later]) ] )
  393. fi
  394. fi
  395. fi
  396. LIBS="$save_LIBS"
  397. LDFLAGS="$save_LDFLAGS"
  398. CPPFLAGS="$save_CPPFLAGS"
  399. AM_CONDITIONAL(USE_BUFFEREVENTS, test "$enable_bufferevents" = "yes")
  400. if test "$enable_bufferevents" = "yes"; then
  401. AC_DEFINE(USE_BUFFEREVENTS, 1, [Defined if we're going to use Libevent's buffered IO API])
  402. if test "$enable_static_libevent" = "yes"; then
  403. TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent_openssl.a $TOR_LIBEVENT_LIBS"
  404. else
  405. TOR_LIBEVENT_LIBS="-levent_openssl $TOR_LIBEVENT_LIBS"
  406. fi
  407. fi
  408. AC_SUBST(TOR_LIBEVENT_LIBS)
  409. dnl ------------------------------------------------------
  410. dnl Where do you live, libm?
  411. dnl On some platforms (Haiku/BeOS) the math library is
  412. dnl part of libroot. In which case don't link against lm
  413. TOR_LIB_MATH=""
  414. save_LIBS="$LIBS"
  415. AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
  416. if test "$ac_cv_search_pow" != "none required"; then
  417. TOR_LIB_MATH="$ac_cv_search_pow"
  418. fi
  419. LIBS="$save_LIBS"
  420. AC_SUBST(TOR_LIB_MATH)
  421. dnl ------------------------------------------------------
  422. dnl Where do you live, openssl? And how do we call you?
  423. tor_openssl_pkg_redhat="openssl"
  424. tor_openssl_pkg_debian="libssl"
  425. tor_openssl_devpkg_redhat="openssl-devel"
  426. tor_openssl_devpkg_debian="libssl-dev"
  427. ALT_openssl_WITHVAL=""
  428. AC_ARG_WITH(ssl-dir,
  429. [ --with-ssl-dir=PATH Obsolete alias for --with-openssl-dir ],
  430. [
  431. if test "x$withval" != xno && test "x$withval" != "x" ; then
  432. ALT_openssl_WITHVAL="$withval"
  433. fi
  434. ])
  435. TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
  436. [#include <openssl/rand.h>],
  437. [void RAND_add(const void *buf, int num, double entropy);],
  438. [RAND_add((void*)0,0,0); exit(0);], [],
  439. [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
  440. dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
  441. if test "$enable_static_openssl" = "yes"; then
  442. if test "$tor_cv_library_openssl_dir" = "(system)"; then
  443. AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
  444. else
  445. TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
  446. fi
  447. else
  448. TOR_OPENSSL_LIBS="-lssl -lcrypto"
  449. fi
  450. AC_SUBST(TOR_OPENSSL_LIBS)
  451. dnl ------------------------------------------------------
  452. dnl Where do you live, zlib? And how do we call you?
  453. tor_zlib_pkg_redhat="zlib"
  454. tor_zlib_pkg_debian="zlib1g"
  455. tor_zlib_devpkg_redhat="zlib-devel"
  456. tor_zlib_devpkg_debian="zlib1g-dev"
  457. TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
  458. [#include <zlib.h>],
  459. [const char * zlibVersion(void);],
  460. [zlibVersion(); exit(0);], [--with-zlib-dir],
  461. [/opt/zlib])
  462. if test "$enable_static_zlib" = "yes"; then
  463. if test "$tor_cv_library_zlib_dir" = "(system)"; then
  464. AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
  465. using --enable-static-zlib")
  466. else
  467. TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
  468. fi
  469. else
  470. TOR_ZLIB_LIBS="-lz"
  471. fi
  472. AC_SUBST(TOR_ZLIB_LIBS)
  473. dnl ---------------------------------------------------------------------
  474. dnl Now that we know about our major libraries, we can check for compiler
  475. dnl and linker hardening options. We need to do this with the libraries known,
  476. dnl since sometimes the linker will like an option but not be willing to
  477. dnl use it with a build of a library.
  478. all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
  479. all_libs_for_check="$TOR_ZLIB_LIBS $TOR_LIB_MATH $TOR_LIBEVENT_LIBS $TOR_OPENSSL_LIBS $TOR_LIB_WS32 $TOR_LIB_GDI"
  480. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
  481. #if !defined(__clang__)
  482. #error
  483. #endif])], have_clang=yes, have_clang=no)
  484. if test x$enable_gcc_hardening != xno; then
  485. CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2"
  486. if test x$have_clang = xyes; then
  487. TOR_CHECK_CFLAGS(-Qunused-arguments)
  488. fi
  489. TOR_CHECK_CFLAGS(-fstack-protector-all)
  490. TOR_CHECK_CFLAGS(-Wstack-protector)
  491. TOR_CHECK_CFLAGS(-fwrapv)
  492. TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
  493. if test "$bwin32" = "false"; then
  494. TOR_CHECK_CFLAGS(-fPIE)
  495. TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
  496. fi
  497. fi
  498. if test x$enable_linker_hardening != xno; then
  499. TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
  500. fi
  501. dnl ------------------------------------------------------
  502. dnl Where do you live, libnatpmp? And how do we call you?
  503. dnl There are no packages for Debian or Redhat as of this patch
  504. if test "$natpmp" = "true"; then
  505. AC_DEFINE(NAT_PMP, 1, [Define to 1 if we are building with nat-pmp.])
  506. TOR_SEARCH_LIBRARY(libnatpmp, $trylibnatpmpdir, [-lnatpmp $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
  507. [#include <natpmp.h>],
  508. [#ifdef _WIN32
  509. #define STATICLIB
  510. #endif
  511. #include <natpmp.h>],
  512. [ int r;
  513. natpmp_t natpmp;
  514. natpmpresp_t response;
  515. r = initnatpmp(&natpmp, 0, 0);],
  516. [printf("initnatpmp() returned %d (%s)\n", r, r?"FAILED":"SUCCESS");
  517. exit(0);],
  518. [--with-libnatpmp-dir],
  519. [/usr/lib/])
  520. fi
  521. dnl ------------------------------------------------------
  522. dnl Where do you live, libminiupnpc? And how do we call you?
  523. dnl There are no packages for Debian or Redhat as of this patch
  524. if test "$upnp" = "true"; then
  525. AC_DEFINE(MINIUPNPC, 1, [Define to 1 if we are building with UPnP.])
  526. dnl Before we call TOR_SEARCH_LIBRARY we'll do a quick compile test
  527. dnl to see if we have miniupnpc-1.5 or -1.6
  528. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <miniupnpc/miniupnpc.h>],
  529. [upnpDiscover(1, 0, 0, 0);exit(0);])],[miniupnpc15="true"],[miniupnpc15="false"])
  530. if test "$miniupnpc15" = "true" ; then
  531. AC_DEFINE([MINIUPNPC15],[1],[libminiupnpc version 1.5 found])
  532. TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
  533. [#include <miniupnpc/miniwget.h>
  534. #include <miniupnpc/miniupnpc.h>
  535. #include <miniupnpc/upnpcommands.h>],
  536. [void upnpDiscover(int delay, const char * multicastif,
  537. const char * minissdpdsock, int sameport);],
  538. [upnpDiscover(1, 0, 0, 0); exit(0);],
  539. [--with-libminiupnpc-dir],
  540. [/usr/lib/])
  541. else
  542. TOR_SEARCH_LIBRARY(libminiupnpc, $trylibminiupnpcdir, [-lminiupnpc $TOR_LIB_WS32 $TOR_LIB_IPHLPAPI],
  543. [#include <miniupnpc/miniwget.h>
  544. #include <miniupnpc/miniupnpc.h>
  545. #include <miniupnpc/upnpcommands.h>],
  546. [void upnpDiscover(int delay, const char * multicastif,
  547. const char * minissdpdsock, int sameport, int ipv6, int * error);],
  548. [upnpDiscover(1, 0, 0, 0, 0, 0); exit(0);],
  549. [--with-libminiupnpc-dir],
  550. [/usr/lib/])
  551. fi
  552. fi
  553. dnl Make sure to enable support for large off_t if available.
  554. AC_SYS_LARGEFILE
  555. AC_CHECK_HEADERS(
  556. assert.h \
  557. errno.h \
  558. fcntl.h \
  559. signal.h \
  560. string.h \
  561. sys/fcntl.h \
  562. sys/stat.h \
  563. sys/time.h \
  564. sys/types.h \
  565. time.h \
  566. unistd.h
  567. , , 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.))
  568. dnl These headers are not essential
  569. AC_CHECK_HEADERS(
  570. arpa/inet.h \
  571. crt_externs.h \
  572. grp.h \
  573. ifaddrs.h \
  574. inttypes.h \
  575. limits.h \
  576. linux/types.h \
  577. machine/limits.h \
  578. malloc.h \
  579. malloc/malloc.h \
  580. malloc_np.h \
  581. netdb.h \
  582. netinet/in.h \
  583. netinet/in6.h \
  584. pwd.h \
  585. stdint.h \
  586. sys/file.h \
  587. sys/ioctl.h \
  588. sys/limits.h \
  589. sys/mman.h \
  590. sys/param.h \
  591. sys/prctl.h \
  592. sys/resource.h \
  593. sys/socket.h \
  594. sys/syslimits.h \
  595. sys/time.h \
  596. sys/types.h \
  597. sys/un.h \
  598. sys/utime.h \
  599. sys/wait.h \
  600. syslog.h \
  601. utime.h
  602. )
  603. AC_CHECK_HEADERS(sys/param.h)
  604. AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
  605. [#ifdef HAVE_SYS_TYPES_H
  606. #include <sys/types.h>
  607. #endif
  608. #ifdef HAVE_SYS_SOCKET_H
  609. #include <sys/socket.h>
  610. #endif])
  611. AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
  612. [#ifdef HAVE_SYS_TYPES_H
  613. #include <sys/types.h>
  614. #endif
  615. #ifdef HAVE_SYS_SOCKET_H
  616. #include <sys/socket.h>
  617. #endif
  618. #ifdef HAVE_NET_IF_H
  619. #include <net/if.h>
  620. #endif])
  621. AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
  622. linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
  623. [#ifdef HAVE_SYS_TYPES_H
  624. #include <sys/types.h>
  625. #endif
  626. #ifdef HAVE_SYS_SOCKET_H
  627. #include <sys/socket.h>
  628. #endif
  629. #ifdef HAVE_LIMITS_H
  630. #include <limits.h>
  631. #endif
  632. #ifdef HAVE_LINUX_TYPES_H
  633. #include <linux/types.h>
  634. #endif
  635. #ifdef HAVE_NETINET_IN6_H
  636. #include <netinet/in6.h>
  637. #endif
  638. #ifdef HAVE_NETINET_IN_H
  639. #include <netinet/in.h>
  640. #endif])
  641. if test x$transparent = xtrue ; then
  642. transparent_ok=0
  643. if test x$net_if_found = x1 && test x$net_pfvar_found = x1 ; then
  644. transparent_ok=1
  645. fi
  646. if test x$linux_netfilter_ipv4 = x1 ; then
  647. transparent_ok=1
  648. fi
  649. if test x$transparent_ok = x1 ; then
  650. AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
  651. case $host in
  652. *-*-openbsd*)
  653. AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
  654. esac
  655. else
  656. AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
  657. fi
  658. fi
  659. AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
  660. [#ifdef HAVE_SYS_TYPES_H
  661. #include <sys/types.h>
  662. #endif
  663. #ifdef HAVE_SYS_TIME_H
  664. #include <sys/time.h>
  665. #endif])
  666. dnl In case we aren't given a working stdint.h, we'll need to grow our own.
  667. dnl Watch out.
  668. AC_CHECK_SIZEOF(int8_t)
  669. AC_CHECK_SIZEOF(int16_t)
  670. AC_CHECK_SIZEOF(int32_t)
  671. AC_CHECK_SIZEOF(int64_t)
  672. AC_CHECK_SIZEOF(uint8_t)
  673. AC_CHECK_SIZEOF(uint16_t)
  674. AC_CHECK_SIZEOF(uint32_t)
  675. AC_CHECK_SIZEOF(uint64_t)
  676. AC_CHECK_SIZEOF(intptr_t)
  677. AC_CHECK_SIZEOF(uintptr_t)
  678. dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
  679. AC_CHECK_SIZEOF(char)
  680. AC_CHECK_SIZEOF(short)
  681. AC_CHECK_SIZEOF(int)
  682. AC_CHECK_SIZEOF(long)
  683. AC_CHECK_SIZEOF(long long)
  684. AC_CHECK_SIZEOF(__int64)
  685. AC_CHECK_SIZEOF(void *)
  686. AC_CHECK_SIZEOF(time_t)
  687. AC_CHECK_SIZEOF(size_t)
  688. AC_CHECK_TYPES([uint, u_char, ssize_t])
  689. dnl used to include sockaddr_storage, but everybody has that.
  690. AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
  691. [#ifdef HAVE_SYS_TYPES_H
  692. #include <sys/types.h>
  693. #endif
  694. #ifdef HAVE_NETINET_IN_H
  695. #include <netinet/in.h>
  696. #endif
  697. #ifdef HAVE_NETINET_IN6_H
  698. #include <netinet/in6.h>
  699. #endif
  700. #ifdef HAVE_SYS_SOCKET_H
  701. #include <sys/socket.h>
  702. #endif
  703. #ifdef _WIN32
  704. #define _WIN32_WINNT 0x0501
  705. #define WIN32_LEAN_AND_MEAN
  706. #if defined(_MSC_VER) && (_MSC_VER < 1300)
  707. #include <winsock.h>
  708. #else
  709. #include <winsock2.h>
  710. #include <ws2tcpip.h>
  711. #endif
  712. #endif
  713. ])
  714. AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
  715. [#ifdef HAVE_SYS_TYPES_H
  716. #include <sys/types.h>
  717. #endif
  718. #ifdef HAVE_NETINET_IN_H
  719. #include <netinet/in.h>
  720. #endif
  721. #ifdef HAVE_NETINET_IN6_H
  722. #include <netinet/in6.h>
  723. #endif
  724. #ifdef HAVE_SYS_SOCKET_H
  725. #include <sys/socket.h>
  726. #endif
  727. #ifdef _WIN32
  728. #define _WIN32_WINNT 0x0501
  729. #define WIN32_LEAN_AND_MEAN
  730. #if defined(_MSC_VER) && (_MSC_VER < 1300)
  731. #include <winsock.h>
  732. #else
  733. #include <winsock2.h>
  734. #include <ws2tcpip.h>
  735. #endif
  736. #endif
  737. ])
  738. AC_CHECK_TYPES([rlim_t], , ,
  739. [#ifdef HAVE_SYS_TYPES_H
  740. #include <sys/types.h>
  741. #endif
  742. #ifdef HAVE_SYS_TIME_H
  743. #include <sys/time.h>
  744. #endif
  745. #ifdef HAVE_SYS_RESOURCE_H
  746. #include <sys/resource.h>
  747. #endif
  748. ])
  749. AC_CACHE_CHECK([whether time_t is signed], tor_cv_time_t_signed, [
  750. AC_RUN_IFELSE([AC_LANG_SOURCE([
  751. #ifdef HAVE_SYS_TYPES_H
  752. #include <sys/types.h>
  753. #endif
  754. #ifdef HAVE_SYS_TIME_H
  755. #include <sys/time.h>
  756. #endif
  757. #ifdef HAVE_TIME_H
  758. #include <time.h>
  759. #endif
  760. int main(int c, char**v) { if (((time_t)-1)<0) return 1; else return 0; }])],
  761. tor_cv_time_t_signed=no, tor_cv_time_t_signed=yes, tor_cv_time_t_signed=cross)
  762. ])
  763. if test "$tor_cv_time_t_signed" = cross; then
  764. AC_MSG_NOTICE([Cross compiling: assuming that time_t is signed.])
  765. fi
  766. if test "$tor_cv_time_t_signed" != no; then
  767. AC_DEFINE([TIME_T_IS_SIGNED], 1,
  768. [Define to 1 iff time_t is signed])
  769. fi
  770. AC_CACHE_CHECK([whether size_t is signed], tor_cv_size_t_signed, [
  771. AC_RUN_IFELSE([AC_LANG_SOURCE([
  772. #ifdef HAVE_SYS_TYPES_H
  773. #include <sys/types.h>
  774. #endif
  775. int main(int c, char**v) { if (((size_t)-1)<0) return 1; else return 0; }])],
  776. tor_cv_size_t_signed=no, tor_cv_size_t_signed=yes, tor_cv_size_t_signed=cross)
  777. ])
  778. if test "$tor_cv_size_t_signed" = cross; then
  779. AC_MSG_NOTICE([Cross compiling: assuming that size_t is not signed.])
  780. fi
  781. if test "$tor_cv_size_t_signed" = yes; then
  782. AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
  783. fi
  784. AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
  785. #ifdef HAVE_SYS_SOCKET_H
  786. #include <sys/socket.h>
  787. #endif
  788. ])
  789. # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
  790. AC_CHECK_SIZEOF(cell_t)
  791. # Now make sure that NULL can be represented as zero bytes.
  792. AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
  793. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  794. [[#include <stdlib.h>
  795. #include <string.h>
  796. #include <stdio.h>
  797. #ifdef HAVE_STDDEF_H
  798. #include <stddef.h>
  799. #endif
  800. int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
  801. return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
  802. [tor_cv_null_is_zero=yes],
  803. [tor_cv_null_is_zero=no],
  804. [tor_cv_null_is_zero=cross])])
  805. if test "$tor_cv_null_is_zero" = cross ; then
  806. # Cross-compiling; let's hope that the target isn't raving mad.
  807. AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
  808. fi
  809. if test "$tor_cv_null_is_zero" != no; then
  810. AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
  811. [Define to 1 iff memset(0) sets pointers to NULL])
  812. fi
  813. # And what happens when we malloc zero?
  814. AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
  815. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  816. [[#include <stdlib.h>
  817. #include <string.h>
  818. #include <stdio.h>
  819. #ifdef HAVE_STDDEF_H
  820. #include <stddef.h>
  821. #endif
  822. int main () { return malloc(0)?0:1; }]])],
  823. [tor_cv_malloc_zero_works=yes],
  824. [tor_cv_malloc_zero_works=no],
  825. [tor_cv_malloc_zero_works=cross])])
  826. if test "$tor_cv_malloc_zero_works" = cross; then
  827. # Cross-compiling; let's hope that the target isn't raving mad.
  828. AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
  829. fi
  830. if test "$tor_cv_malloc_zero_works" = yes; then
  831. AC_DEFINE([MALLOC_ZERO_WORKS], 1,
  832. [Define to 1 iff malloc(0) returns a pointer])
  833. fi
  834. # whether we seem to be in a 2s-complement world.
  835. AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
  836. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  837. [[int main () { int problem = ((-99) != (~99)+1);
  838. return problem ? 1 : 0; }]])],
  839. [tor_cv_twos_complement=yes],
  840. [tor_cv_twos_complement=no],
  841. [tor_cv_twos_complement=cross])])
  842. if test "$tor_cv_twos_complement" = cross ; then
  843. # Cross-compiling; let's hope that the target isn't raving mad.
  844. AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
  845. fi
  846. if test "$tor_cv_twos_complement" != no ; then
  847. AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
  848. [Define to 1 iff we represent negative integers with two's complement])
  849. fi
  850. # What does shifting a negative value do?
  851. AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
  852. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  853. [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
  854. [tor_cv_sign_extend=yes],
  855. [tor_cv_sign_extend=no],
  856. [tor_cv_sign_extend=cross])])
  857. if test "$tor_cv_sign_extend" = cross ; then
  858. # Cross-compiling; let's hope that the target isn't raving mad.
  859. AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
  860. fi
  861. if test "$tor_cv_sign_extend" != no ; then
  862. AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
  863. [Define to 1 iff right-shifting a negative value performs sign-extension])
  864. fi
  865. # Whether we should use the dmalloc memory allocation debugging library.
  866. AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
  867. AC_ARG_WITH(dmalloc,
  868. [ --with-dmalloc Use debug memory allocation library. ],
  869. [if [[ "$withval" = "yes" ]]; then
  870. dmalloc=1
  871. AC_MSG_RESULT(yes)
  872. else
  873. dmalloc=1
  874. AC_MSG_RESULT(no)
  875. fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
  876. )
  877. if [[ $dmalloc -eq 1 ]]; then
  878. AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
  879. AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
  880. AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
  881. AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
  882. AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
  883. fi
  884. AC_ARG_WITH(tcmalloc,
  885. [ --with-tcmalloc Use tcmalloc memory allocation library. ],
  886. [ tcmalloc=yes ], [ tcmalloc=no ])
  887. if test x$tcmalloc = xyes ; then
  888. LDFLAGS="-ltcmalloc $LDFLAGS"
  889. fi
  890. using_custom_malloc=no
  891. if test x$enable_openbsd_malloc = xyes ; then
  892. using_custom_malloc=yes
  893. fi
  894. if test x$tcmalloc = xyes ; then
  895. using_custom_malloc=yes
  896. fi
  897. if test $using_custom_malloc = no ; then
  898. AC_CHECK_FUNCS(mallinfo)
  899. fi
  900. # By default, we're going to assume we don't have mlockall()
  901. # bionic and other platforms have various broken mlockall subsystems.
  902. # Some systems don't have a working mlockall, some aren't linkable,
  903. # and some have it but don't declare it.
  904. AC_CHECK_FUNCS(mlockall)
  905. AC_CHECK_DECLS([mlockall], , , [
  906. #ifdef HAVE_SYS_MMAN_H
  907. #include <sys/mman.h>
  908. #endif])
  909. # Allow user to specify an alternate syslog facility
  910. AC_ARG_WITH(syslog-facility,
  911. [ --with-syslog-facility=LOG syslog facility to use (default=LOG_DAEMON)],
  912. syslog_facility="$withval", syslog_facility="LOG_DAEMON")
  913. AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
  914. AC_SUBST(LOGFACILITY)
  915. # Check if we have getresuid and getresgid
  916. AC_CHECK_FUNCS(getresuid getresgid)
  917. # Check for gethostbyname_r in all its glorious incompatible versions.
  918. # (This logic is based on that in Python's configure.in)
  919. AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
  920. [Define this if you have any gethostbyname_r()])
  921. AC_CHECK_FUNC(gethostbyname_r, [
  922. AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
  923. OLD_CFLAGS=$CFLAGS
  924. CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
  925. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
  926. #include <netdb.h>
  927. ], [[
  928. char *cp1, *cp2;
  929. struct hostent *h1, *h2;
  930. int i1, i2;
  931. (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
  932. ]])],[
  933. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  934. AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
  935. [Define this if gethostbyname_r takes 6 arguments])
  936. AC_MSG_RESULT(6)
  937. ], [
  938. AC_TRY_COMPILE([
  939. #include <netdb.h>
  940. ], [
  941. char *cp1, *cp2;
  942. struct hostent *h1;
  943. int i1, i2;
  944. (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
  945. ], [
  946. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  947. AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
  948. [Define this if gethostbyname_r takes 5 arguments])
  949. AC_MSG_RESULT(5)
  950. ], [
  951. AC_TRY_COMPILE([
  952. #include <netdb.h>
  953. ], [
  954. char *cp1;
  955. struct hostent *h1;
  956. struct hostent_data hd;
  957. (void) gethostbyname_r(cp1,h1,&hd);
  958. ], [
  959. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  960. AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
  961. [Define this if gethostbyname_r takes 3 arguments])
  962. AC_MSG_RESULT(3)
  963. ], [
  964. AC_MSG_RESULT(0)
  965. ])
  966. ])
  967. ])
  968. CFLAGS=$OLD_CFLAGS
  969. ])
  970. AC_CACHE_CHECK([whether the C compiler supports __func__],
  971. tor_cv_have_func_macro,
  972. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  973. #include <stdio.h>
  974. int main(int c, char **v) { puts(__func__); }])],
  975. tor_cv_have_func_macro=yes,
  976. tor_cv_have_func_macro=no))
  977. AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
  978. tor_cv_have_FUNC_macro,
  979. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  980. #include <stdio.h>
  981. int main(int c, char **v) { puts(__FUNC__); }])],
  982. tor_cv_have_FUNC_macro=yes,
  983. tor_cv_have_FUNC_macro=no))
  984. AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
  985. tor_cv_have_FUNCTION_macro,
  986. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  987. #include <stdio.h>
  988. int main(int c, char **v) { puts(__FUNCTION__); }])],
  989. tor_cv_have_FUNCTION_macro=yes,
  990. tor_cv_have_FUNCTION_macro=no))
  991. AC_CACHE_CHECK([whether we have extern char **environ already declared],
  992. tor_cv_have_environ_declared,
  993. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  994. /* We define _GNU_SOURCE here because it is also defined in compat.c.
  995. * Without it environ doesn't get declared. */
  996. #define _GNU_SOURCE
  997. #ifdef HAVE_UNISTD_H
  998. #include <unistd.h>
  999. #endif
  1000. #include <stdlib.h>
  1001. int main(int c, char **v) { char **t = environ; }])],
  1002. tor_cv_have_environ_declared=yes,
  1003. tor_cv_have_environ_declared=no))
  1004. if test "$tor_cv_have_func_macro" = 'yes'; then
  1005. AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
  1006. fi
  1007. if test "$tor_cv_have_FUNC_macro" = 'yes'; then
  1008. AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
  1009. fi
  1010. if test "$tor_cv_have_FUNCTION_macro" = 'yes'; then
  1011. AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
  1012. [Defined if the compiler supports __FUNCTION__])
  1013. fi
  1014. if test "$tor_cv_have_environ_declared" = 'yes'; then
  1015. AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
  1016. [Defined if we have extern char **environ already declared])
  1017. fi
  1018. # $prefix stores the value of the --prefix command line option, or
  1019. # NONE if the option wasn't set. In the case that it wasn't set, make
  1020. # it be the default, so that we can use it to expand directories now.
  1021. if test "x$prefix" = "xNONE"; then
  1022. prefix=$ac_default_prefix
  1023. fi
  1024. # and similarly for $exec_prefix
  1025. if test "x$exec_prefix" = "xNONE"; then
  1026. exec_prefix=$prefix
  1027. fi
  1028. if test "x$BUILDDIR" = "x"; then
  1029. BUILDDIR=`pwd`
  1030. fi
  1031. AC_SUBST(BUILDDIR)
  1032. AH_TEMPLATE([BUILDDIR],[tor's build directory])
  1033. AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
  1034. if test "x$CONFDIR" = "x"; then
  1035. CONFDIR=`eval echo $sysconfdir/tor`
  1036. fi
  1037. AC_SUBST(CONFDIR)
  1038. AH_TEMPLATE([CONFDIR],[tor's configuration directory])
  1039. AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
  1040. BINDIR=`eval echo $bindir`
  1041. AC_SUBST(BINDIR)
  1042. LOCALSTATEDIR=`eval echo $localstatedir`
  1043. AC_SUBST(LOCALSTATEDIR)
  1044. if test "$bwin32" = true; then
  1045. # Test if the linker supports the --nxcompat and --dynamicbase options
  1046. # for Windows
  1047. save_LDFLAGS="$LDFLAGS"
  1048. LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
  1049. AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
  1050. AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
  1051. [AC_MSG_RESULT([yes])]
  1052. [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
  1053. [AC_MSG_RESULT([no])]
  1054. )
  1055. LDFLAGS="$save_LDFLAGS"
  1056. fi
  1057. # Set CFLAGS _after_ all the above checks, since our warnings are stricter
  1058. # than autoconf's macros like.
  1059. if test "$GCC" = yes; then
  1060. # Disable GCC's strict aliasing checks. They are an hours-to-debug
  1061. # accident waiting to happen.
  1062. CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
  1063. else
  1064. # Autoconf sets -g -O2 by default. Override optimization level
  1065. # for non-gcc compilers
  1066. CFLAGS="$CFLAGS -O"
  1067. enable_gcc_warnings=no
  1068. enable_gcc_warnings_advisory=no
  1069. fi
  1070. # OS X Lion started deprecating the system openssl. Let's just disable
  1071. # all deprecation warnings on OS X. Also, to potentially make the binary
  1072. # a little smaller, let's enable dead_strip.
  1073. case "$host_os" in
  1074. darwin*)
  1075. CFLAGS="$CFLAGS -Wno-deprecated-declarations"
  1076. LDFLAGS="$LDFLAGS -dead_strip" ;;
  1077. esac
  1078. # Add some more warnings which we use in development but not in the
  1079. # released versions. (Some relevant gcc versions can't handle these.)
  1080. if test x$enable_gcc_warnings = xyes || test x$enable_gcc_warnings_advisory = xyes; then
  1081. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
  1082. #if !defined(__GNUC__) || (__GNUC__ < 4)
  1083. #error
  1084. #endif])], have_gcc4=yes, have_gcc4=no)
  1085. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
  1086. #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
  1087. #error
  1088. #endif])], have_gcc42=yes, have_gcc42=no)
  1089. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
  1090. #if !defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)
  1091. #error
  1092. #endif])], have_gcc43=yes, have_gcc43=no)
  1093. save_CFLAGS="$CFLAGS"
  1094. CFLAGS="$CFLAGS -Wshorten-64-to-32"
  1095. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], have_shorten64_flag=yes,
  1096. have_shorten64_flag=no)
  1097. CFLAGS="$save_CFLAGS"
  1098. case $host in
  1099. *-*-openbsd*)
  1100. # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
  1101. # That's fine, except that the headers don't pass -Wredundant-decls.
  1102. # Therefore, let's disable -Wsystem-headers when we're building
  1103. # with maximal warnings on OpenBSD.
  1104. CFLAGS="$CFLAGS -Wno-system-headers" ;;
  1105. esac
  1106. CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
  1107. CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
  1108. CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
  1109. CFLAGS="$CFLAGS -Wwrite-strings -Wmissing-declarations -Wredundant-decls"
  1110. CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
  1111. if test x$enable_gcc_warnings = xyes; then
  1112. CFLAGS="$CFLAGS -Werror"
  1113. fi
  1114. # Disabled, so we can use mallinfo(): -Waggregate-return
  1115. if test x$have_gcc4 = xyes ; then
  1116. # These warnings break gcc 3.3.5 and work on gcc 4.0.2
  1117. CFLAGS="$CFLAGS -Winit-self -Wmissing-field-initializers -Wdeclaration-after-statement -Wold-style-definition"
  1118. fi
  1119. if test x$have_gcc42 = xyes ; then
  1120. # These warnings break gcc 4.0.2 and work on gcc 4.2
  1121. # XXXX020 See if any of these work with earlier versions.
  1122. CFLAGS="$CFLAGS -Waddress -Wmissing-noreturn -Wstrict-overflow=1"
  1123. # We used to use -Wstrict-overflow=5, but that breaks us heavily under 4.3.
  1124. fi
  1125. if test x$have_gcc42 = xyes && test x$have_clang = xno; then
  1126. # These warnings break gcc 4.0.2 and clang, but work on gcc 4.2
  1127. CFLAGS="$CFLAGS -Wnormalized=id -Woverride-init"
  1128. fi
  1129. if test x$have_gcc43 = xyes ; then
  1130. # These warnings break gcc 4.2 and work on gcc 4.3
  1131. # XXXX020 See if any of these work with earlier versions.
  1132. CFLAGS="$CFLAGS -Wextra -Warray-bounds"
  1133. fi
  1134. if test x$have_shorten64_flag = xyes ; then
  1135. CFLAGS="$CFLAGS -Wshorten-64-to-32"
  1136. fi
  1137. ##This will break the world on some 64-bit architectures
  1138. # CFLAGS="$CFLAGS -Winline"
  1139. fi
  1140. CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
  1141. AC_CONFIG_FILES([
  1142. Doxyfile
  1143. Makefile
  1144. contrib/suse/tor.sh
  1145. contrib/tor.logrotate
  1146. contrib/tor.sh
  1147. contrib/torctl
  1148. contrib/torify
  1149. src/config/torrc.sample
  1150. tor.spec
  1151. ])
  1152. AC_OUTPUT
  1153. if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
  1154. ./contrib/updateVersions.pl
  1155. fi