configure.ac 44 KB

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