configure.in 41 KB

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