configure.in 40 KB

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