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