configure.ac 45 KB

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