configure.ac 44 KB

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