configure.ac 40 KB

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