configure.ac 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989
  1. dnl Copyright (c) 2001-2004, Roger Dingledine
  2. dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
  3. dnl Copyright (c) 2007-2015, The Tor Project, Inc.
  4. dnl See LICENSE for licensing information
  5. AC_PREREQ([2.63])
  6. AC_INIT([tor],[0.3.0.2-alpha-dev])
  7. AC_CONFIG_SRCDIR([src/or/main.c])
  8. AC_CONFIG_MACRO_DIR([m4])
  9. # "foreign" means we don't follow GNU package layout standards
  10. # "1.11" means we require automake version 1.11 or newer
  11. # "subdir-objects" means put .o files in the same directory as the .c files
  12. AM_INIT_AUTOMAKE([foreign 1.11 subdir-objects -Wall -Werror])
  13. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
  14. AC_CONFIG_HEADERS([orconfig.h])
  15. AC_USE_SYSTEM_EXTENSIONS
  16. AC_CANONICAL_HOST
  17. PKG_PROG_PKG_CONFIG
  18. if test -f "/etc/redhat-release"; then
  19. if test -f "/usr/kerberos/include"; then
  20. CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
  21. fi
  22. fi
  23. # Not a no-op; we want to make sure that CPPFLAGS is set before we use
  24. # the += operator on it in src/or/Makefile.am
  25. CPPFLAGS="$CPPFLAGS -I\${top_srcdir}/src/common"
  26. AC_ARG_ENABLE(openbsd-malloc,
  27. AS_HELP_STRING(--enable-openbsd-malloc, [use malloc code from OpenBSD. Linux only]))
  28. AC_ARG_ENABLE(static-openssl,
  29. AS_HELP_STRING(--enable-static-openssl, [link against a static openssl library. Requires --with-openssl-dir]))
  30. AC_ARG_ENABLE(static-libevent,
  31. AS_HELP_STRING(--enable-static-libevent, [link against a static libevent library. Requires --with-libevent-dir]))
  32. AC_ARG_ENABLE(static-zlib,
  33. AS_HELP_STRING(--enable-static-zlib, [link against a static zlib library. Requires --with-zlib-dir]))
  34. AC_ARG_ENABLE(static-tor,
  35. AS_HELP_STRING(--enable-static-tor, [create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir]))
  36. AC_ARG_ENABLE(unittests,
  37. AS_HELP_STRING(--disable-unittests, [don't build unit tests for Tor. Risky!]))
  38. AC_ARG_ENABLE(coverage,
  39. AS_HELP_STRING(--enable-coverage, [enable coverage support in the unit-test build]))
  40. AC_ARG_ENABLE(asserts-in-tests,
  41. AS_HELP_STRING(--disable-asserts-in-tests, [disable tor_assert() calls in the unit tests, for branch coverage]))
  42. AC_ARG_ENABLE(system-torrc,
  43. AS_HELP_STRING(--disable-system-torrc, [don't look for a system-wide torrc file]))
  44. AC_ARG_ENABLE(libfuzzer,
  45. AS_HELP_STRING(--enable-libfuzzer, [build extra fuzzers based on 'libfuzzer']))
  46. AC_ARG_ENABLE(oss-fuzz,
  47. AS_HELP_STRING(--enable-oss-fuzz, [build extra fuzzers based on 'oss-fuzz' environment]))
  48. if test "x$enable_coverage" != "xyes" -a "x$enable_asserts_in_tests" = "xno" ; then
  49. AC_MSG_ERROR([Can't disable assertions outside of coverage build])
  50. fi
  51. AM_CONDITIONAL(UNITTESTS_ENABLED, test "x$enable_unittests" != "xno")
  52. AM_CONDITIONAL(COVERAGE_ENABLED, test "x$enable_coverage" = "xyes")
  53. AM_CONDITIONAL(DISABLE_ASSERTS_IN_UNIT_TESTS, test "x$enable_asserts_in_tests" = "xno")
  54. AM_CONDITIONAL(LIBFUZZER_ENABLED, test "x$enable_libfuzzer" = "xyes")
  55. AM_CONDITIONAL(OSS_FUZZ_ENABLED, test "x$enable_oss_fuzz" = "xyes")
  56. if test "$enable_static_tor" = "yes"; then
  57. enable_static_libevent="yes";
  58. enable_static_openssl="yes";
  59. enable_static_zlib="yes";
  60. CFLAGS="$CFLAGS -static"
  61. fi
  62. if test "$enable_system_torrc" = "no"; then
  63. AC_DEFINE(DISABLE_SYSTEM_TORRC, 1,
  64. [Defined if we're not going to look for a torrc in SYSCONF])
  65. fi
  66. AM_CONDITIONAL(USE_OPENBSD_MALLOC, test "x$enable_openbsd_malloc" = "xyes")
  67. AC_ARG_ENABLE(asciidoc,
  68. AS_HELP_STRING(--disable-asciidoc, [don't use asciidoc (disables building of manpages)]),
  69. [case "${enableval}" in
  70. "yes") asciidoc=true ;;
  71. "no") asciidoc=false ;;
  72. *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
  73. esac], [asciidoc=true])
  74. # systemd notify support
  75. AC_ARG_ENABLE(systemd,
  76. AS_HELP_STRING(--enable-systemd, [enable systemd notification support]),
  77. [case "${enableval}" in
  78. "yes") systemd=true ;;
  79. "no") systemd=false ;;
  80. * ) AC_MSG_ERROR(bad value for --enable-systemd) ;;
  81. esac], [systemd=auto])
  82. # systemd support
  83. if test "x$enable_systemd" = "xno"; then
  84. have_systemd=no;
  85. else
  86. PKG_CHECK_MODULES(SYSTEMD,
  87. [libsystemd-daemon],
  88. have_systemd=yes,
  89. have_systemd=no)
  90. if test "x$have_systemd" = "xno"; then
  91. AC_MSG_NOTICE([Okay, checking for systemd a different way...])
  92. PKG_CHECK_MODULES(SYSTEMD,
  93. [libsystemd],
  94. have_systemd=yes,
  95. have_systemd=no)
  96. fi
  97. fi
  98. if test "x$have_systemd" = "xyes"; then
  99. AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
  100. TOR_SYSTEMD_CFLAGS="${SYSTEMD_CFLAGS}"
  101. TOR_SYSTEMD_LIBS="${SYSTEMD_LIBS}"
  102. PKG_CHECK_MODULES(LIBSYSTEMD209, [libsystemd >= 209],
  103. [AC_DEFINE(HAVE_SYSTEMD_209,1,[Have systemd v209 or more])], [])
  104. fi
  105. AC_SUBST(TOR_SYSTEMD_CFLAGS)
  106. AC_SUBST(TOR_SYSTEMD_LIBS)
  107. if test "x$enable_systemd" = "xyes" -a "x$have_systemd" != "xyes" ; then
  108. AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found])
  109. fi
  110. case "$host" in
  111. *-*-solaris* )
  112. AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
  113. ;;
  114. esac
  115. AC_ARG_ENABLE(gcc-warnings,
  116. AS_HELP_STRING(--enable-gcc-warnings, [deprecated alias for enable-fatal-warnings]))
  117. AC_ARG_ENABLE(fatal-warnings,
  118. AS_HELP_STRING(--enable-fatal-warnings, [tell the compiler to treat all warnings as errors.]))
  119. AC_ARG_ENABLE(gcc-warnings-advisory,
  120. AS_HELP_STRING(--disable-gcc-warnings-advisory, [disable the regular verbose warnings]))
  121. dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
  122. AC_ARG_ENABLE(gcc-hardening,
  123. AS_HELP_STRING(--disable-gcc-hardening, [disable compiler security checks]))
  124. dnl Deprecated --enable-expensive-hardening but keep it for now for backward compat.
  125. AC_ARG_ENABLE(expensive-hardening,
  126. AS_HELP_STRING(--enable-expensive-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
  127. AC_ARG_ENABLE(fragile-hardening,
  128. AS_HELP_STRING(--enable-fragile-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
  129. if test "x$enable_expensive_hardening" = "xyes" || test "x$enable_fragile_hardening" = "xyes"; then
  130. fragile_hardening="yes"
  131. fi
  132. dnl Linker hardening options
  133. dnl Currently these options are ELF specific - you can't use this with MacOSX
  134. AC_ARG_ENABLE(linker-hardening,
  135. AS_HELP_STRING(--disable-linker-hardening, [disable linker security fixups]))
  136. AC_ARG_ENABLE(local-appdata,
  137. AS_HELP_STRING(--enable-local-appdata, [default to host local application data paths on Windows]))
  138. if test "$enable_local_appdata" = "yes"; then
  139. AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
  140. [Defined if we default to host local appdata paths on Windows])
  141. fi
  142. # Tor2web mode flag
  143. AC_ARG_ENABLE(tor2web-mode,
  144. AS_HELP_STRING(--enable-tor2web-mode, [support tor2web non-anonymous mode]),
  145. [if test "x$enableval" = "xyes"; then
  146. CFLAGS="$CFLAGS -D ENABLE_TOR2WEB_MODE=1"
  147. fi])
  148. AC_ARG_ENABLE(tool-name-check,
  149. AS_HELP_STRING(--disable-tool-name-check, [check for sanely named toolchain when cross-compiling]))
  150. AC_ARG_ENABLE(seccomp,
  151. AS_HELP_STRING(--disable-seccomp, [do not attempt to use libseccomp]))
  152. AC_ARG_ENABLE(libscrypt,
  153. AS_HELP_STRING(--disable-libscrypt, [do not attempt to use libscrypt]))
  154. dnl check for the correct "ar" when cross-compiling.
  155. dnl (AM_PROG_AR was new in automake 1.11.2, which we do not yet require,
  156. dnl so kludge up a replacement for the case where it isn't there yet.)
  157. m4_ifdef([AM_PROG_AR],
  158. [AM_PROG_AR],
  159. [AN_MAKEVAR([AR], [AC_PROG_AR])
  160. AN_PROGRAM([ar], [AC_PROG_AR])
  161. AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [:])])
  162. AC_PROG_AR])
  163. dnl Check whether the above macro has settled for a simply named tool even
  164. dnl though we're cross compiling. We must do this before running AC_PROG_CC,
  165. dnl because that will find any cc on the system, not only the cross-compiler,
  166. dnl and then verify that a binary built with this compiler runs on the
  167. dnl build system. It will then come to the false conclusion that we're not
  168. dnl cross-compiling.
  169. if test "x$enable_tool_name_check" != "xno"; then
  170. if test "x$ac_tool_warned" = "xyes"; then
  171. AC_MSG_ERROR([We are cross compiling but could not find a properly named toolchain. Do you have your cross-compiling toolchain in PATH? (You can --disable-tool-name-check to ignore this.)])
  172. elif test "x$ac_ct_AR" != "x" -a "x$cross_compiling" = "xmaybe"; then
  173. AC_MSG_ERROR([We think we are cross compiling but could not find a properly named toolchain. Do you have your cross-compiling toolchain in PATH? (You can --disable-tool-name-check to ignore this.)])
  174. fi
  175. fi
  176. AC_PROG_CC
  177. AC_PROG_CPP
  178. AC_PROG_MAKE_SET
  179. AC_PROG_RANLIB
  180. AC_PROG_SED
  181. AC_ARG_VAR([PERL], [path to Perl binary])
  182. AC_CHECK_PROGS([PERL], [perl])
  183. AM_CONDITIONAL(USE_PERL, [test "x$ac_cv_prog_PERL" != "x"])
  184. dnl check for asciidoc and a2x
  185. AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
  186. AC_PATH_PROGS([A2X], [a2x a2x.py], none)
  187. AM_CONDITIONAL(USE_ASCIIDOC, test "x$asciidoc" = "xtrue")
  188. AM_PROG_CC_C_O
  189. AC_PROG_CC_C99
  190. AC_ARG_VAR([PYTHON], [path to Python binary])
  191. AC_CHECK_PROGS(PYTHON, [python python2 python2.7 python3 python3.3])
  192. if test "x$PYTHON" = "x"; then
  193. AC_MSG_WARN([Python unavailable; some tests will not be run.])
  194. fi
  195. AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
  196. ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
  197. AC_C_FLEXIBLE_ARRAY_MEMBER
  198. ], [
  199. dnl Maybe we've got an old autoconf...
  200. AC_CACHE_CHECK([for flexible array members],
  201. tor_cv_c_flexarray,
  202. [AC_COMPILE_IFELSE(
  203. AC_LANG_PROGRAM([
  204. struct abc { int a; char b[]; };
  205. ], [
  206. struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
  207. def->b[0] = 33;
  208. ]),
  209. [tor_cv_c_flexarray=yes],
  210. [tor_cv_c_flexarray=no])])
  211. if test "$tor_cv_flexarray" = "yes"; then
  212. AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
  213. else
  214. AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
  215. fi
  216. ])
  217. AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
  218. tor_cv_c_c99_decl,
  219. [AC_COMPILE_IFELSE(
  220. [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
  221. [tor_cv_c_c99_decl=yes],
  222. [tor_cv_c_c99_decl=no] )])
  223. if test "$tor_cv_c_c99_decl" != "yes"; then
  224. AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
  225. fi
  226. AC_CACHE_CHECK([for working C99 designated initializers],
  227. tor_cv_c_c99_designated_init,
  228. [AC_COMPILE_IFELSE(
  229. [AC_LANG_PROGRAM([struct s { int a; int b; };],
  230. [[ struct s ss = { .b = 5, .a = 6 }; ]])],
  231. [tor_cv_c_c99_designated_init=yes],
  232. [tor_cv_c_c99_designated_init=no] )])
  233. if test "$tor_cv_c_c99_designated_init" != "yes"; then
  234. AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
  235. fi
  236. TORUSER=_tor
  237. AC_ARG_WITH(tor-user,
  238. AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
  239. [
  240. TORUSER=$withval
  241. ]
  242. )
  243. AC_SUBST(TORUSER)
  244. TORGROUP=_tor
  245. AC_ARG_WITH(tor-group,
  246. AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
  247. [
  248. TORGROUP=$withval
  249. ]
  250. )
  251. AC_SUBST(TORGROUP)
  252. dnl If _WIN32 is defined and non-zero, we are building for win32
  253. AC_MSG_CHECKING([for win32])
  254. AC_RUN_IFELSE([AC_LANG_SOURCE([
  255. int main(int c, char **v) {
  256. #ifdef _WIN32
  257. #if _WIN32
  258. return 0;
  259. #else
  260. return 1;
  261. #endif
  262. #else
  263. return 2;
  264. #endif
  265. }])],
  266. bwin32=true; AC_MSG_RESULT([yes]),
  267. bwin32=false; AC_MSG_RESULT([no]),
  268. bwin32=cross; AC_MSG_RESULT([cross])
  269. )
  270. if test "$bwin32" = "cross"; then
  271. AC_MSG_CHECKING([for win32 (cross)])
  272. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  273. #ifdef _WIN32
  274. int main(int c, char **v) {return 0;}
  275. #else
  276. #error
  277. int main(int c, char **v) {return x(y);}
  278. #endif
  279. ])],
  280. bwin32=true; AC_MSG_RESULT([yes]),
  281. bwin32=false; AC_MSG_RESULT([no]))
  282. fi
  283. AH_BOTTOM([
  284. #ifdef _WIN32
  285. /* Defined to access windows functions and definitions for >=WinXP */
  286. # ifndef WINVER
  287. # define WINVER 0x0501
  288. # endif
  289. /* Defined to access _other_ windows functions and definitions for >=WinXP */
  290. # ifndef _WIN32_WINNT
  291. # define _WIN32_WINNT 0x0501
  292. # endif
  293. /* Defined to avoid including some windows headers as part of Windows.h */
  294. # ifndef WIN32_LEAN_AND_MEAN
  295. # define WIN32_LEAN_AND_MEAN 1
  296. # endif
  297. #endif
  298. ])
  299. AM_CONDITIONAL(BUILD_NT_SERVICES, test "x$bwin32" = "xtrue")
  300. dnl Enable C99 when compiling with MIPSpro
  301. AC_MSG_CHECKING([for MIPSpro compiler])
  302. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
  303. #if (defined(__sgi) && defined(_COMPILER_VERSION))
  304. #error
  305. return x(y);
  306. #endif
  307. ])],
  308. bmipspro=false; AC_MSG_RESULT(no),
  309. bmipspro=true; AC_MSG_RESULT(yes))
  310. if test "$bmipspro" = "true"; then
  311. CFLAGS="$CFLAGS -c99"
  312. fi
  313. AC_C_BIGENDIAN
  314. AC_SEARCH_LIBS(socket, [socket network])
  315. AC_SEARCH_LIBS(gethostbyname, [nsl])
  316. AC_SEARCH_LIBS(dlopen, [dl])
  317. AC_SEARCH_LIBS(inet_aton, [resolv])
  318. AC_SEARCH_LIBS(backtrace, [execinfo])
  319. saved_LIBS="$LIBS"
  320. AC_SEARCH_LIBS([clock_gettime], [rt])
  321. if test "$LIBS" != "$saved_LIBS"; then
  322. # Looks like we need -lrt for clock_gettime().
  323. have_rt=yes
  324. fi
  325. AC_SEARCH_LIBS(pthread_create, [pthread])
  326. AC_SEARCH_LIBS(pthread_detach, [pthread])
  327. AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
  328. AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
  329. AC_CHECK_FUNCS(
  330. _NSGetEnviron \
  331. RtlSecureZeroMemory \
  332. SecureZeroMemory \
  333. accept4 \
  334. backtrace \
  335. backtrace_symbols_fd \
  336. eventfd \
  337. explicit_bzero \
  338. timingsafe_memcmp \
  339. flock \
  340. ftime \
  341. getaddrinfo \
  342. getifaddrs \
  343. getpass \
  344. getrlimit \
  345. gettimeofday \
  346. gmtime_r \
  347. htonll \
  348. inet_aton \
  349. ioctl \
  350. issetugid \
  351. llround \
  352. localtime_r \
  353. lround \
  354. memmem \
  355. memset_s \
  356. pipe \
  357. pipe2 \
  358. prctl \
  359. readpassphrase \
  360. rint \
  361. sigaction \
  362. socketpair \
  363. statvfs \
  364. strlcat \
  365. strlcpy \
  366. strnlen \
  367. strptime \
  368. strtok_r \
  369. strtoull \
  370. sysconf \
  371. sysctl \
  372. truncate \
  373. uname \
  374. usleep \
  375. vasprintf \
  376. _vscprintf
  377. )
  378. # Apple messed up when they added two functions functions in Sierra: they
  379. # forgot to decorate them with appropriate AVAILABLE_MAC_OS_VERSION
  380. # checks. So we should only probe for those functions if we are sure that we
  381. # are not targetting OSX 10.11 or earlier.
  382. AC_MSG_CHECKING([for a pre-Sierra OSX build target])
  383. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  384. #ifdef __APPLE__
  385. # include <AvailabilityMacros.h>
  386. # ifndef MAC_OS_X_VERSION_10_12
  387. # define MAC_OS_X_VERSION_10_12 101200
  388. # endif
  389. # if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
  390. # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
  391. # error "Running on Mac OSX 10.11 or earlier"
  392. # endif
  393. # endif
  394. #endif
  395. ]], [[]])],
  396. [on_macos_pre_10_12=no ; AC_MSG_RESULT([no])],
  397. [on_macos_pre_10_12=yes; AC_MSG_RESULT([yes])])
  398. if test "$on_macos_pre_10_12" = "no"; then
  399. AC_CHECK_FUNCS(
  400. clock_gettime \
  401. getentropy \
  402. )
  403. fi
  404. if test "$bwin32" != "true"; then
  405. AC_CHECK_HEADERS(pthread.h)
  406. AC_CHECK_FUNCS(pthread_create)
  407. AC_CHECK_FUNCS(pthread_condattr_setclock)
  408. fi
  409. if test "$bwin32" = "true"; then
  410. AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
  411. #include <windows.h>
  412. #include <conio.h>
  413. #include <wchar.h>
  414. ])
  415. fi
  416. AM_CONDITIONAL(BUILD_READPASSPHRASE_C,
  417. test "x$ac_cv_func_readpassphrase" = "xno" && test "$bwin32" = "false")
  418. dnl ------------------------------------------------------
  419. dnl Where do you live, libevent? And how do we call you?
  420. if test "$bwin32" = "true"; then
  421. TOR_LIB_WS32=-lws2_32
  422. TOR_LIB_IPHLPAPI=-liphlpapi
  423. # Some of the cargo-cults recommend -lwsock32 as well, but I don't
  424. # think it's actually necessary.
  425. TOR_LIB_GDI=-lgdi32
  426. else
  427. TOR_LIB_WS32=
  428. TOR_LIB_GDI=
  429. fi
  430. AC_SUBST(TOR_LIB_WS32)
  431. AC_SUBST(TOR_LIB_GDI)
  432. AC_SUBST(TOR_LIB_IPHLPAPI)
  433. tor_libevent_pkg_redhat="libevent"
  434. tor_libevent_pkg_debian="libevent-dev"
  435. tor_libevent_devpkg_redhat="libevent-devel"
  436. tor_libevent_devpkg_debian="libevent-dev"
  437. dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
  438. dnl linking for static builds.
  439. STATIC_LIBEVENT_FLAGS=""
  440. if test "$enable_static_libevent" = "yes"; then
  441. if test "$have_rt" = "yes"; then
  442. STATIC_LIBEVENT_FLAGS=" -lrt "
  443. fi
  444. fi
  445. TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
  446. #ifdef _WIN32
  447. #include <winsock2.h>
  448. #endif
  449. #include <sys/time.h>
  450. #include <sys/types.h>
  451. #include <event2/event.h>], [
  452. #ifdef _WIN32
  453. #include <winsock2.h>
  454. #endif
  455. struct event_base;
  456. struct event_base *event_base_new(void);],
  457. [
  458. #ifdef _WIN32
  459. {WSADATA d; WSAStartup(0x101,&d); }
  460. #endif
  461. event_base_new();
  462. ], [--with-libevent-dir], [/opt/libevent])
  463. dnl Determine the incantation needed to link libevent.
  464. save_LIBS="$LIBS"
  465. save_LDFLAGS="$LDFLAGS"
  466. save_CPPFLAGS="$CPPFLAGS"
  467. LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
  468. LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
  469. CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
  470. AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
  471. if test "$enable_static_libevent" = "yes"; then
  472. if test "$tor_cv_library_libevent_dir" = "(system)"; then
  473. AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
  474. else
  475. TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
  476. fi
  477. else
  478. if test "x$ac_cv_header_event2_event_h" = "xyes"; then
  479. AC_SEARCH_LIBS(event_new, [event event_core], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for event_new"))
  480. AC_SEARCH_LIBS(evdns_base_new, [event event_extra], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for evdns_base_new"))
  481. if test "$ac_cv_search_event_new" != "none required"; then
  482. TOR_LIBEVENT_LIBS="$ac_cv_search_event_new"
  483. fi
  484. if test "$ac_cv_search_evdns_base_new" != "none required"; then
  485. TOR_LIBEVENT_LIBS="$ac_cv_search_evdns_base_new $TOR_LIBEVENT_LIBS"
  486. fi
  487. else
  488. AC_MSG_ERROR("libevent2 is required but the headers could not be found")
  489. fi
  490. fi
  491. dnl Now check for particular libevent functions.
  492. AC_CHECK_FUNCS([evutil_secure_rng_set_urandom_device_file \
  493. evutil_secure_rng_add_bytes \
  494. ])
  495. LIBS="$save_LIBS"
  496. LDFLAGS="$save_LDFLAGS"
  497. CPPFLAGS="$save_CPPFLAGS"
  498. dnl Check that libevent is at least at version 2.0.10, the first stable
  499. dnl release of its series
  500. CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
  501. AC_MSG_CHECKING([whether Libevent is new enough])
  502. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  503. #include <event2/event.h>
  504. #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000a00
  505. #error
  506. int x = y(zz);
  507. #else
  508. int x = 1;
  509. #endif
  510. ])], [ AC_MSG_RESULT([yes]) ],
  511. [ AC_MSG_RESULT([no])
  512. AC_MSG_ERROR([Libevent is not new enough. We require 2.0.10-stable or later]) ] )
  513. LIBS="$save_LIBS"
  514. LDFLAGS="$save_LDFLAGS"
  515. CPPFLAGS="$save_CPPFLAGS"
  516. AC_SUBST(TOR_LIBEVENT_LIBS)
  517. dnl ------------------------------------------------------
  518. dnl Where do you live, libm?
  519. dnl On some platforms (Haiku/BeOS) the math library is
  520. dnl part of libroot. In which case don't link against lm
  521. TOR_LIB_MATH=""
  522. save_LIBS="$LIBS"
  523. AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
  524. if test "$ac_cv_search_pow" != "none required"; then
  525. TOR_LIB_MATH="$ac_cv_search_pow"
  526. fi
  527. LIBS="$save_LIBS"
  528. AC_SUBST(TOR_LIB_MATH)
  529. dnl ------------------------------------------------------
  530. dnl Where do you live, openssl? And how do we call you?
  531. tor_openssl_pkg_redhat="openssl"
  532. tor_openssl_pkg_debian="libssl-dev"
  533. tor_openssl_devpkg_redhat="openssl-devel"
  534. tor_openssl_devpkg_debian="libssl-dev"
  535. ALT_openssl_WITHVAL=""
  536. AC_ARG_WITH(ssl-dir,
  537. AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
  538. [
  539. if test "x$withval" != "xno" && test "x$withval" != "x"; then
  540. ALT_openssl_WITHVAL="$withval"
  541. fi
  542. ])
  543. TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI],
  544. [#include <openssl/rand.h>],
  545. [void RAND_add(const void *buf, int num, double entropy);],
  546. [RAND_add((void*)0,0,0);], [],
  547. [/usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /opt/openssl])
  548. dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
  549. if test "$enable_static_openssl" = "yes"; then
  550. if test "$tor_cv_library_openssl_dir" = "(system)"; then
  551. AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
  552. else
  553. TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
  554. fi
  555. else
  556. TOR_OPENSSL_LIBS="-lssl -lcrypto"
  557. fi
  558. AC_SUBST(TOR_OPENSSL_LIBS)
  559. dnl Now check for particular openssl functions.
  560. save_LIBS="$LIBS"
  561. save_LDFLAGS="$LDFLAGS"
  562. save_CPPFLAGS="$CPPFLAGS"
  563. LIBS="$TOR_OPENSSL_LIBS $LIBS"
  564. LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
  565. CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
  566. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  567. #include <openssl/opensslv.h>
  568. #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1000100fL
  569. #error "too old"
  570. #endif
  571. ]], [[]])],
  572. [ : ],
  573. [ AC_MSG_ERROR([OpenSSL is too old. We require 1.0.1 or later. You can specify a path to a newer one with --with-openssl-dir.]) ])
  574. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  575. #include <openssl/opensslv.h>
  576. #include <openssl/evp.h>
  577. #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_ECDSA)
  578. #error "no ECC"
  579. #endif
  580. #if !defined(NID_X9_62_prime256v1) || !defined(NID_secp224r1)
  581. #error "curves unavailable"
  582. #endif
  583. ]], [[]])],
  584. [ : ],
  585. [ AC_MSG_ERROR([OpenSSL is built without full ECC support, including curves P256 and P224. You can specify a path to one with ECC support with --with-openssl-dir.]) ])
  586. AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
  587. [#include <openssl/ssl.h>
  588. ])
  589. AC_CHECK_FUNCS([ \
  590. SSL_SESSION_get_master_key \
  591. SSL_get_server_random \
  592. SSL_get_client_ciphers \
  593. SSL_get_client_random \
  594. SSL_CIPHER_find \
  595. TLS_method
  596. ])
  597. dnl Check if OpenSSL has scrypt implementation.
  598. AC_CHECK_FUNCS([ EVP_PBE_scrypt ])
  599. dnl Check if OpenSSL structures are opaque
  600. AC_CHECK_MEMBERS([SSL.state], , ,
  601. [#include <openssl/ssl.h>
  602. ])
  603. LIBS="$save_LIBS"
  604. LDFLAGS="$save_LDFLAGS"
  605. CPPFLAGS="$save_CPPFLAGS"
  606. dnl ------------------------------------------------------
  607. dnl Where do you live, zlib? And how do we call you?
  608. tor_zlib_pkg_redhat="zlib"
  609. tor_zlib_pkg_debian="zlib1g"
  610. tor_zlib_devpkg_redhat="zlib-devel"
  611. tor_zlib_devpkg_debian="zlib1g-dev"
  612. TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
  613. [#include <zlib.h>],
  614. [const char * zlibVersion(void);],
  615. [zlibVersion();], [--with-zlib-dir],
  616. [/opt/zlib])
  617. if test "$enable_static_zlib" = "yes"; then
  618. if test "$tor_cv_library_zlib_dir" = "(system)"; then
  619. AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
  620. using --enable-static-zlib")
  621. else
  622. TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
  623. fi
  624. else
  625. TOR_ZLIB_LIBS="-lz"
  626. fi
  627. AC_SUBST(TOR_ZLIB_LIBS)
  628. dnl ----------------------------------------------------------------------
  629. dnl Check if libcap is available for capabilities.
  630. tor_cap_pkg_debian="libcap2"
  631. tor_cap_pkg_redhat="libcap"
  632. tor_cap_devpkg_debian="libcap-dev"
  633. tor_cap_devpkg_redhat="libcap-devel"
  634. AC_CHECK_LIB([cap], [cap_init], [],
  635. AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
  636. )
  637. AC_CHECK_FUNCS(cap_set_proc)
  638. dnl ---------------------------------------------------------------------
  639. dnl Now that we know about our major libraries, we can check for compiler
  640. dnl and linker hardening options. We need to do this with the libraries known,
  641. dnl since sometimes the linker will like an option but not be willing to
  642. dnl use it with a build of a library.
  643. all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
  644. all_libs_for_check="$TOR_ZLIB_LIBS $TOR_LIB_MATH $TOR_LIBEVENT_LIBS $TOR_OPENSSL_LIBS $TOR_SYSTEMD_LIBS $TOR_LIB_WS32 $TOR_LIB_GDI $TOR_CAP_LIBS"
  645. CFLAGS_FTRAPV=
  646. CFLAGS_FWRAPV=
  647. CFLAGS_ASAN=
  648. CFLAGS_UBSAN=
  649. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
  650. #if !defined(__clang__)
  651. #error
  652. #endif])], have_clang=yes, have_clang=no)
  653. if test "x$enable_gcc_hardening" != "xno"; then
  654. CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
  655. if test "x$have_clang" = "xyes"; then
  656. TOR_CHECK_CFLAGS(-Qunused-arguments)
  657. fi
  658. TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
  659. AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
  660. AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
  661. m4_ifdef([AS_VAR_IF],[
  662. AS_VAR_IF(can_compile, [yes],
  663. AS_VAR_IF(can_link, [yes],
  664. [],
  665. AC_MSG_ERROR([We tried to build with stack protection; it looks like your compiler supports it but your libc does not provide it. Are you missing libssp? (You can --disable-gcc-hardening to ignore this error.)]))
  666. )])
  667. AS_VAR_POPDEF([can_link])
  668. AS_VAR_POPDEF([can_compile])
  669. TOR_CHECK_CFLAGS(-Wstack-protector)
  670. TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
  671. if test "$bwin32" = "false" && test "$enable_libfuzzer" != "yes" && test "$enable_oss_fuzz" != "yes"; then
  672. TOR_CHECK_CFLAGS(-fPIE)
  673. TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
  674. fi
  675. TOR_TRY_COMPILE_WITH_CFLAGS(-fwrapv, also_link, CFLAGS_FWRAPV="-fwrapv", true)
  676. fi
  677. if test "$fragile_hardening" = "yes"; then
  678. TOR_TRY_COMPILE_WITH_CFLAGS(-ftrapv, also_link, CFLAGS_FTRAPV="-ftrapv", true)
  679. if test "$tor_cv_cflags__ftrapv" = "yes" && test "$tor_can_link__ftrapv" != "yes"; then
  680. AC_MSG_WARN([The compiler supports -ftrapv, but for some reason I was not able to link with -ftrapv. Are you missing run-time support? Run-time hardening will not work as well as it should.])
  681. fi
  682. if test "$tor_cv_cflags__ftrapv" != "yes"; then
  683. AC_MSG_ERROR([You requested fragile hardening, but the compiler does not seem to support -ftrapv.])
  684. fi
  685. TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=address], also_link, CFLAGS_ASAN="-fsanitize=address", true)
  686. if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
  687. AC_MSG_ERROR([The compiler supports -fsanitize=address, but for some reason I was not able to link when using it. Are you missing run-time support? With GCC you need libubsan.so, and with Clang you need libclang_rt.ubsan*])
  688. fi
  689. TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=undefined], also_link, CFLAGS_UBSAN="-fsanitize=undefined", true)
  690. if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
  691. AC_MSG_ERROR([The compiler supports -fsanitize=undefined, but for some reason I was not able to link when using it. Are you missing run-time support? With GCC you need libasan.so, and with Clang you need libclang_rt.ubsan*])
  692. fi
  693. TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
  694. fi
  695. CFLAGS_BUGTRAP="$CFLAGS_FTRAPV $CFLAGS_ASAN $CFLAGS_UBSAN"
  696. CFLAGS_CONSTTIME="$CFLAGS_FWRAPV"
  697. mulodi_fixes_ftrapv=no
  698. if test "$have_clang" = "yes"; then
  699. saved_CFLAGS="$CFLAGS"
  700. CFLAGS="$CFLAGS $CFLAGS_FTRAPV"
  701. AC_MSG_CHECKING([whether clang -ftrapv can link a 64-bit int multiply])
  702. AC_LINK_IFELSE([
  703. AC_LANG_SOURCE([[
  704. #include <stdint.h>
  705. #include <stdlib.h>
  706. int main(int argc, char **argv)
  707. {
  708. int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
  709. * (int64_t)atoi(argv[3]);
  710. return x == 9;
  711. } ]])],
  712. [ftrapv_can_link=yes; AC_MSG_RESULT([yes])],
  713. [ftrapv_can_link=no; AC_MSG_RESULT([no])])
  714. if test "$ftrapv_can_link" = "no"; then
  715. AC_MSG_CHECKING([whether defining __mulodi4 fixes that])
  716. AC_LINK_IFELSE([
  717. AC_LANG_SOURCE([[
  718. #include <stdint.h>
  719. #include <stdlib.h>
  720. int64_t __mulodi4(int64_t a, int64_t b, int *overflow) {
  721. *overflow=0;
  722. return a;
  723. }
  724. int main(int argc, char **argv)
  725. {
  726. int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
  727. * (int64_t)atoi(argv[3]);
  728. return x == 9;
  729. } ]])],
  730. [mulodi_fixes_ftrapv=yes; AC_MSG_RESULT([yes])],
  731. [mulodi_fixes_ftrapv=no; AC_MSG_RESULT([no])])
  732. fi
  733. CFLAGS="$saved_CFLAGS"
  734. fi
  735. AM_CONDITIONAL(ADD_MULODI4, test "$mulodi_fixes_ftrapv" = "yes")
  736. dnl These cflags add bunches of branches, and we haven't been able to
  737. dnl persuade ourselves that they're suitable for code that needs to be
  738. dnl constant time.
  739. AC_SUBST(CFLAGS_BUGTRAP)
  740. dnl These cflags are variant ones sutable for code that needs to be
  741. dnl constant-time.
  742. AC_SUBST(CFLAGS_CONSTTIME)
  743. if test "x$enable_linker_hardening" != "xno"; then
  744. TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
  745. fi
  746. # For backtrace support
  747. TOR_CHECK_LDFLAGS(-rdynamic)
  748. dnl ------------------------------------------------------
  749. dnl Now see if we have a -fomit-frame-pointer compiler option.
  750. saved_CFLAGS="$CFLAGS"
  751. TOR_CHECK_CFLAGS(-fomit-frame-pointer)
  752. F_OMIT_FRAME_POINTER=''
  753. if test "$saved_CFLAGS" != "$CFLAGS"; then
  754. if test "$fragile_hardening" = "yes"; then
  755. F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
  756. fi
  757. fi
  758. CFLAGS="$saved_CFLAGS"
  759. AC_SUBST(F_OMIT_FRAME_POINTER)
  760. dnl ------------------------------------------------------
  761. dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
  762. dnl for us, as GCC 4.6 and later do at many optimization levels), then
  763. dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
  764. dnl code will work.
  765. TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
  766. dnl ============================================================
  767. dnl Check for libseccomp
  768. if test "x$enable_seccomp" != "xno"; then
  769. AC_CHECK_HEADERS([seccomp.h])
  770. AC_SEARCH_LIBS(seccomp_init, [seccomp])
  771. fi
  772. dnl ============================================================
  773. dnl Check for libscrypt
  774. if test "x$enable_libscrypt" != "xno"; then
  775. AC_CHECK_HEADERS([libscrypt.h])
  776. AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
  777. AC_CHECK_FUNCS([libscrypt_scrypt])
  778. fi
  779. dnl ============================================================
  780. dnl We need an implementation of curve25519.
  781. dnl set these defaults.
  782. build_curve25519_donna=no
  783. build_curve25519_donna_c64=no
  784. use_curve25519_donna=no
  785. use_curve25519_nacl=no
  786. CURVE25519_LIBS=
  787. dnl The best choice is using curve25519-donna-c64, but that requires
  788. dnl that we
  789. AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
  790. tor_cv_can_use_curve25519_donna_c64,
  791. [AC_RUN_IFELSE(
  792. [AC_LANG_PROGRAM([dnl
  793. #include <stdint.h>
  794. typedef unsigned uint128_t __attribute__((mode(TI)));
  795. int func(uint64_t a, uint64_t b) {
  796. uint128_t c = ((uint128_t)a) * b;
  797. int ok = ((uint64_t)(c>>96)) == 522859 &&
  798. (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
  799. (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
  800. (((uint64_t)(c))&0xffffffffL) == 0;
  801. return ok;
  802. }
  803. ], [dnl
  804. int ok = func( ((uint64_t)2000000000) * 1000000000,
  805. ((uint64_t)1234567890) << 24);
  806. return !ok;
  807. ])],
  808. [tor_cv_can_use_curve25519_donna_c64=yes],
  809. [tor_cv_can_use_curve25519_donna_c64=no],
  810. [AC_LINK_IFELSE(
  811. [AC_LANG_PROGRAM([dnl
  812. #include <stdint.h>
  813. typedef unsigned uint128_t __attribute__((mode(TI)));
  814. int func(uint64_t a, uint64_t b) {
  815. uint128_t c = ((uint128_t)a) * b;
  816. int ok = ((uint64_t)(c>>96)) == 522859 &&
  817. (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
  818. (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
  819. (((uint64_t)(c))&0xffffffffL) == 0;
  820. return ok;
  821. }
  822. ], [dnl
  823. int ok = func( ((uint64_t)2000000000) * 1000000000,
  824. ((uint64_t)1234567890) << 24);
  825. return !ok;
  826. ])],
  827. [tor_cv_can_use_curve25519_donna_c64=cross],
  828. [tor_cv_can_use_curve25519_donna_c64=no])])])
  829. AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
  830. nacl/crypto_scalarmult_curve25519.h])
  831. AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
  832. tor_cv_can_use_curve25519_nacl,
  833. [tor_saved_LIBS="$LIBS"
  834. LIBS="$LIBS -lnacl"
  835. AC_LINK_IFELSE(
  836. [AC_LANG_PROGRAM([dnl
  837. #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
  838. #include <crypto_scalarmult_curve25519.h>
  839. #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
  840. #include <nacl/crypto_scalarmult_curve25519.h>
  841. #endif
  842. #ifdef crypto_scalarmult_curve25519_ref_BYTES
  843. #error Hey, this is the reference implementation! That's not fast.
  844. #endif
  845. ], [
  846. unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
  847. ])], [tor_cv_can_use_curve25519_nacl=yes],
  848. [tor_cv_can_use_curve25519_nacl=no])
  849. LIBS="$tor_saved_LIBS" ])
  850. dnl Okay, now we need to figure out which one to actually use. Fall back
  851. dnl to curve25519-donna.c
  852. if test "x$tor_cv_can_use_curve25519_donna_c64" != "xno"; then
  853. build_curve25519_donna_c64=yes
  854. use_curve25519_donna=yes
  855. elif test "x$tor_cv_can_use_curve25519_nacl" = "xyes"; then
  856. use_curve25519_nacl=yes
  857. CURVE25519_LIBS=-lnacl
  858. else
  859. build_curve25519_donna=yes
  860. use_curve25519_donna=yes
  861. fi
  862. if test "x$use_curve25519_donna" = "xyes"; then
  863. AC_DEFINE(USE_CURVE25519_DONNA, 1,
  864. [Defined if we should use an internal curve25519_donna{,_c64} implementation])
  865. fi
  866. if test "x$use_curve25519_nacl" = "xyes"; then
  867. AC_DEFINE(USE_CURVE25519_NACL, 1,
  868. [Defined if we should use a curve25519 from nacl])
  869. fi
  870. AM_CONDITIONAL(BUILD_CURVE25519_DONNA,
  871. test "x$build_curve25519_donna" = "xyes")
  872. AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64,
  873. test "x$build_curve25519_donna_c64" = "xyes")
  874. AC_SUBST(CURVE25519_LIBS)
  875. dnl Make sure to enable support for large off_t if available.
  876. AC_SYS_LARGEFILE
  877. AC_CHECK_HEADERS([assert.h \
  878. errno.h \
  879. fcntl.h \
  880. signal.h \
  881. string.h \
  882. sys/capability.h \
  883. sys/fcntl.h \
  884. sys/stat.h \
  885. sys/time.h \
  886. sys/types.h \
  887. time.h \
  888. unistd.h \
  889. arpa/inet.h \
  890. crt_externs.h \
  891. execinfo.h \
  892. grp.h \
  893. ifaddrs.h \
  894. inttypes.h \
  895. limits.h \
  896. linux/types.h \
  897. machine/limits.h \
  898. malloc.h \
  899. malloc/malloc.h \
  900. malloc_np.h \
  901. netdb.h \
  902. netinet/in.h \
  903. netinet/in6.h \
  904. pwd.h \
  905. readpassphrase.h \
  906. stdint.h \
  907. sys/eventfd.h \
  908. sys/file.h \
  909. sys/ioctl.h \
  910. sys/limits.h \
  911. sys/mman.h \
  912. sys/param.h \
  913. sys/prctl.h \
  914. sys/random.h \
  915. sys/resource.h \
  916. sys/select.h \
  917. sys/socket.h \
  918. sys/statvfs.h \
  919. sys/syscall.h \
  920. sys/sysctl.h \
  921. sys/syslimits.h \
  922. sys/time.h \
  923. sys/types.h \
  924. sys/un.h \
  925. sys/utime.h \
  926. sys/wait.h \
  927. syslog.h \
  928. utime.h])
  929. AC_CHECK_HEADERS(sys/param.h)
  930. AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
  931. [#ifdef HAVE_SYS_TYPES_H
  932. #include <sys/types.h>
  933. #endif
  934. #ifdef HAVE_SYS_SOCKET_H
  935. #include <sys/socket.h>
  936. #endif])
  937. AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
  938. [#ifdef HAVE_SYS_TYPES_H
  939. #include <sys/types.h>
  940. #endif
  941. #ifdef HAVE_SYS_SOCKET_H
  942. #include <sys/socket.h>
  943. #endif
  944. #ifdef HAVE_NET_IF_H
  945. #include <net/if.h>
  946. #endif
  947. #ifdef HAVE_NETINET_IN_H
  948. #include <netinet/in.h>
  949. #endif])
  950. AC_CHECK_HEADERS(linux/if.h,[],[],
  951. [
  952. #ifdef HAVE_SYS_SOCKET_H
  953. #include <sys/socket.h>
  954. #endif
  955. ])
  956. AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
  957. linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
  958. [#ifdef HAVE_SYS_TYPES_H
  959. #include <sys/types.h>
  960. #endif
  961. #ifdef HAVE_SYS_SOCKET_H
  962. #include <sys/socket.h>
  963. #endif
  964. #ifdef HAVE_LIMITS_H
  965. #include <limits.h>
  966. #endif
  967. #ifdef HAVE_LINUX_TYPES_H
  968. #include <linux/types.h>
  969. #endif
  970. #ifdef HAVE_NETINET_IN6_H
  971. #include <netinet/in6.h>
  972. #endif
  973. #ifdef HAVE_NETINET_IN_H
  974. #include <netinet/in.h>
  975. #endif])
  976. AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
  977. linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
  978. [#ifdef HAVE_SYS_TYPES_H
  979. #include <sys/types.h>
  980. #endif
  981. #ifdef HAVE_SYS_SOCKET_H
  982. #include <sys/socket.h>
  983. #endif
  984. #ifdef HAVE_LIMITS_H
  985. #include <limits.h>
  986. #endif
  987. #ifdef HAVE_LINUX_TYPES_H
  988. #include <linux/types.h>
  989. #endif
  990. #ifdef HAVE_NETINET_IN6_H
  991. #include <netinet/in6.h>
  992. #endif
  993. #ifdef HAVE_NETINET_IN_H
  994. #include <netinet/in.h>
  995. #endif
  996. #ifdef HAVE_LINUX_IF_H
  997. #include <linux/if.h>
  998. #endif])
  999. transparent_ok=0
  1000. if test "x$net_if_found" = "x1" && test "x$net_pfvar_found" = "x1"; then
  1001. transparent_ok=1
  1002. fi
  1003. if test "x$linux_netfilter_ipv4" = "x1"; then
  1004. transparent_ok=1
  1005. fi
  1006. if test "x$linux_netfilter_ipv6_ip6_tables" = "x1"; then
  1007. transparent_ok=1
  1008. fi
  1009. if test "x$transparent_ok" = "x1"; then
  1010. AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
  1011. case "$host" in
  1012. *-*-openbsd* | *-*-bitrig*)
  1013. AC_DEFINE(OPENBSD, 1, "Define to handle pf on OpenBSD properly") ;;
  1014. esac
  1015. else
  1016. AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
  1017. fi
  1018. AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
  1019. [#ifdef HAVE_SYS_TYPES_H
  1020. #include <sys/types.h>
  1021. #endif
  1022. #ifdef HAVE_SYS_TIME_H
  1023. #include <sys/time.h>
  1024. #endif])
  1025. dnl In case we aren't given a working stdint.h, we'll need to grow our own.
  1026. dnl Watch out.
  1027. AC_CHECK_SIZEOF(int8_t)
  1028. AC_CHECK_SIZEOF(int16_t)
  1029. AC_CHECK_SIZEOF(int32_t)
  1030. AC_CHECK_SIZEOF(int64_t)
  1031. AC_CHECK_SIZEOF(uint8_t)
  1032. AC_CHECK_SIZEOF(uint16_t)
  1033. AC_CHECK_SIZEOF(uint32_t)
  1034. AC_CHECK_SIZEOF(uint64_t)
  1035. AC_CHECK_SIZEOF(intptr_t)
  1036. AC_CHECK_SIZEOF(uintptr_t)
  1037. dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
  1038. AC_CHECK_SIZEOF(char)
  1039. AC_CHECK_SIZEOF(short)
  1040. AC_CHECK_SIZEOF(int)
  1041. AC_CHECK_SIZEOF(long)
  1042. AC_CHECK_SIZEOF(long long)
  1043. AC_CHECK_SIZEOF(__int64)
  1044. AC_CHECK_SIZEOF(void *)
  1045. AC_CHECK_SIZEOF(time_t)
  1046. AC_CHECK_SIZEOF(size_t)
  1047. AC_CHECK_SIZEOF(pid_t)
  1048. AC_CHECK_TYPES([uint, u_char, ssize_t])
  1049. AC_PC_FROM_UCONTEXT([:])
  1050. dnl used to include sockaddr_storage, but everybody has that.
  1051. AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
  1052. [#ifdef HAVE_SYS_TYPES_H
  1053. #include <sys/types.h>
  1054. #endif
  1055. #ifdef HAVE_NETINET_IN_H
  1056. #include <netinet/in.h>
  1057. #endif
  1058. #ifdef HAVE_NETINET_IN6_H
  1059. #include <netinet/in6.h>
  1060. #endif
  1061. #ifdef HAVE_SYS_SOCKET_H
  1062. #include <sys/socket.h>
  1063. #endif
  1064. #ifdef _WIN32
  1065. #define _WIN32_WINNT 0x0501
  1066. #define WIN32_LEAN_AND_MEAN
  1067. #include <winsock2.h>
  1068. #include <ws2tcpip.h>
  1069. #endif
  1070. ])
  1071. AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
  1072. [#ifdef HAVE_SYS_TYPES_H
  1073. #include <sys/types.h>
  1074. #endif
  1075. #ifdef HAVE_NETINET_IN_H
  1076. #include <netinet/in.h>
  1077. #endif
  1078. #ifdef HAVE_NETINET_IN6_H
  1079. #include <netinet/in6.h>
  1080. #endif
  1081. #ifdef HAVE_SYS_SOCKET_H
  1082. #include <sys/socket.h>
  1083. #endif
  1084. #ifdef _WIN32
  1085. #define _WIN32_WINNT 0x0501
  1086. #define WIN32_LEAN_AND_MEAN
  1087. #include <winsock2.h>
  1088. #include <ws2tcpip.h>
  1089. #endif
  1090. ])
  1091. AC_CHECK_TYPES([rlim_t], , ,
  1092. [#ifdef HAVE_SYS_TYPES_H
  1093. #include <sys/types.h>
  1094. #endif
  1095. #ifdef HAVE_SYS_TIME_H
  1096. #include <sys/time.h>
  1097. #endif
  1098. #ifdef HAVE_SYS_RESOURCE_H
  1099. #include <sys/resource.h>
  1100. #endif
  1101. ])
  1102. AX_CHECK_SIGN([time_t],
  1103. [ : ],
  1104. [ : ], [
  1105. #ifdef HAVE_SYS_TYPES_H
  1106. #include <sys/types.h>
  1107. #endif
  1108. #ifdef HAVE_SYS_TIME_H
  1109. #include <sys/time.h>
  1110. #endif
  1111. #ifdef HAVE_TIME_H
  1112. #include <time.h>
  1113. #endif
  1114. ])
  1115. if test "$ax_cv_decl_time_t_signed" = "no"; then
  1116. AC_MSG_ERROR([You have an unsigned time_t; Tor does not support that. Please tell the Tor developers about your interesting platform.])
  1117. fi
  1118. AX_CHECK_SIGN([size_t],
  1119. [ tor_cv_size_t_signed=yes ],
  1120. [ tor_cv_size_t_signed=no ], [
  1121. #ifdef HAVE_SYS_TYPES_H
  1122. #include <sys/types.h>
  1123. #endif
  1124. ])
  1125. if test "$ax_cv_decl_size_t_signed" = "yes"; then
  1126. AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
  1127. fi
  1128. AX_CHECK_SIGN([enum always],
  1129. [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
  1130. [ : ], [
  1131. enum always { AAA, BBB, CCC };
  1132. ])
  1133. AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
  1134. #ifdef HAVE_SYS_SOCKET_H
  1135. #include <sys/socket.h>
  1136. #endif
  1137. ])
  1138. # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
  1139. AC_CHECK_SIZEOF(cell_t)
  1140. # Now make sure that NULL can be represented as zero bytes.
  1141. AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
  1142. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1143. [[#include <stdlib.h>
  1144. #include <string.h>
  1145. #include <stdio.h>
  1146. #ifdef HAVE_STDDEF_H
  1147. #include <stddef.h>
  1148. #endif
  1149. int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
  1150. return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
  1151. [tor_cv_null_is_zero=yes],
  1152. [tor_cv_null_is_zero=no],
  1153. [tor_cv_null_is_zero=cross])])
  1154. if test "$tor_cv_null_is_zero" = "cross"; then
  1155. # Cross-compiling; let's hope that the target isn't raving mad.
  1156. AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
  1157. fi
  1158. if test "$tor_cv_null_is_zero" != "no"; then
  1159. AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
  1160. [Define to 1 iff memset(0) sets pointers to NULL])
  1161. fi
  1162. AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
  1163. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1164. [[#include <stdlib.h>
  1165. #include <string.h>
  1166. #include <stdio.h>
  1167. #ifdef HAVE_STDDEF_H
  1168. #include <stddef.h>
  1169. #endif
  1170. int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
  1171. return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
  1172. [tor_cv_dbl0_is_zero=yes],
  1173. [tor_cv_dbl0_is_zero=no],
  1174. [tor_cv_dbl0_is_zero=cross])])
  1175. if test "$tor_cv_dbl0_is_zero" = "cross"; then
  1176. # Cross-compiling; let's hope that the target isn't raving mad.
  1177. AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
  1178. fi
  1179. if test "$tor_cv_dbl0_is_zero" != "no"; then
  1180. AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
  1181. [Define to 1 iff memset(0) sets doubles to 0.0])
  1182. fi
  1183. # And what happens when we malloc zero?
  1184. AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
  1185. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1186. [[#include <stdlib.h>
  1187. #include <string.h>
  1188. #include <stdio.h>
  1189. #ifdef HAVE_STDDEF_H
  1190. #include <stddef.h>
  1191. #endif
  1192. int main () { return malloc(0)?0:1; }]])],
  1193. [tor_cv_malloc_zero_works=yes],
  1194. [tor_cv_malloc_zero_works=no],
  1195. [tor_cv_malloc_zero_works=cross])])
  1196. if test "$tor_cv_malloc_zero_works" = "cross"; then
  1197. # Cross-compiling; let's hope that the target isn't raving mad.
  1198. AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
  1199. fi
  1200. if test "$tor_cv_malloc_zero_works" = "yes"; then
  1201. AC_DEFINE([MALLOC_ZERO_WORKS], 1,
  1202. [Define to 1 iff malloc(0) returns a pointer])
  1203. fi
  1204. # whether we seem to be in a 2s-complement world.
  1205. AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
  1206. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1207. [[int main () { int problem = ((-99) != (~99)+1);
  1208. return problem ? 1 : 0; }]])],
  1209. [tor_cv_twos_complement=yes],
  1210. [tor_cv_twos_complement=no],
  1211. [tor_cv_twos_complement=cross])])
  1212. if test "$tor_cv_twos_complement" = "cross"; then
  1213. # Cross-compiling; let's hope that the target isn't raving mad.
  1214. AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
  1215. fi
  1216. if test "$tor_cv_twos_complement" != "no"; then
  1217. AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
  1218. [Define to 1 iff we represent negative integers with
  1219. two's complement])
  1220. fi
  1221. # What does shifting a negative value do?
  1222. AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
  1223. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1224. [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
  1225. [tor_cv_sign_extend=yes],
  1226. [tor_cv_sign_extend=no],
  1227. [tor_cv_sign_extend=cross])])
  1228. if test "$tor_cv_sign_extend" = "cross"; then
  1229. # Cross-compiling; let's hope that the target isn't raving mad.
  1230. AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
  1231. fi
  1232. if test "$tor_cv_sign_extend" != "no"; then
  1233. AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
  1234. [Define to 1 iff right-shifting a negative value performs sign-extension])
  1235. fi
  1236. # Whether we should use the dmalloc memory allocation debugging library.
  1237. AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
  1238. AC_ARG_WITH(dmalloc,
  1239. AS_HELP_STRING(--with-dmalloc, [use debug memory allocation library]),
  1240. [if [[ "$withval" = "yes" ]]; then
  1241. dmalloc=1
  1242. AC_MSG_RESULT(yes)
  1243. else
  1244. dmalloc=1
  1245. AC_MSG_RESULT(no)
  1246. fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
  1247. )
  1248. if [[ $dmalloc -eq 1 ]]; then
  1249. AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
  1250. AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
  1251. AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
  1252. AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
  1253. fi
  1254. AC_ARG_WITH(tcmalloc,
  1255. AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library]),
  1256. [ tcmalloc=yes ], [ tcmalloc=no ])
  1257. if test "x$tcmalloc" = "xyes"; then
  1258. LDFLAGS="-ltcmalloc $LDFLAGS"
  1259. fi
  1260. using_custom_malloc=no
  1261. if test "x$enable_openbsd_malloc" = "xyes"; then
  1262. using_custom_malloc=yes
  1263. fi
  1264. if test "x$tcmalloc" = "xyes"; then
  1265. using_custom_malloc=yes
  1266. fi
  1267. if test "$using_custom_malloc" = "no"; then
  1268. AC_CHECK_FUNCS(mallinfo)
  1269. fi
  1270. # By default, we're going to assume we don't have mlockall()
  1271. # bionic and other platforms have various broken mlockall subsystems.
  1272. # Some systems don't have a working mlockall, some aren't linkable,
  1273. # and some have it but don't declare it.
  1274. AC_CHECK_FUNCS(mlockall)
  1275. AC_CHECK_DECLS([mlockall], , , [
  1276. #ifdef HAVE_SYS_MMAN_H
  1277. #include <sys/mman.h>
  1278. #endif])
  1279. # Some MinGW environments don't have getpagesize in unistd.h. We don't use
  1280. # AC_CHECK_FUNCS(getpagesize), because other environments rename getpagesize
  1281. # using macros
  1282. AC_CHECK_DECLS([getpagesize], , , [
  1283. #ifdef HAVE_UNISTD_H
  1284. #include <unistd.h>
  1285. #endif])
  1286. # Allow user to specify an alternate syslog facility
  1287. AC_ARG_WITH(syslog-facility,
  1288. AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
  1289. syslog_facility="$withval", syslog_facility="LOG_DAEMON")
  1290. AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
  1291. AC_SUBST(LOGFACILITY)
  1292. # Check if we have getresuid and getresgid
  1293. AC_CHECK_FUNCS(getresuid getresgid)
  1294. # Check for gethostbyname_r in all its glorious incompatible versions.
  1295. # (This logic is based on that in Python's configure.in)
  1296. AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
  1297. [Define this if you have any gethostbyname_r()])
  1298. AC_CHECK_FUNC(gethostbyname_r, [
  1299. AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
  1300. OLD_CFLAGS=$CFLAGS
  1301. CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
  1302. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1303. #include <netdb.h>
  1304. ]], [[
  1305. char *cp1, *cp2;
  1306. struct hostent *h1, *h2;
  1307. int i1, i2;
  1308. (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
  1309. ]])],[
  1310. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  1311. AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
  1312. [Define this if gethostbyname_r takes 6 arguments])
  1313. AC_MSG_RESULT(6)
  1314. ], [
  1315. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1316. #include <netdb.h>
  1317. ]], [[
  1318. char *cp1, *cp2;
  1319. struct hostent *h1;
  1320. int i1, i2;
  1321. (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
  1322. ]])], [
  1323. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  1324. AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
  1325. [Define this if gethostbyname_r takes 5 arguments])
  1326. AC_MSG_RESULT(5)
  1327. ], [
  1328. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1329. #include <netdb.h>
  1330. ]], [[
  1331. char *cp1;
  1332. struct hostent *h1;
  1333. struct hostent_data hd;
  1334. (void) gethostbyname_r(cp1,h1,&hd);
  1335. ]])], [
  1336. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  1337. AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
  1338. [Define this if gethostbyname_r takes 3 arguments])
  1339. AC_MSG_RESULT(3)
  1340. ], [
  1341. AC_MSG_RESULT(0)
  1342. ])
  1343. ])
  1344. ])
  1345. CFLAGS=$OLD_CFLAGS
  1346. ])
  1347. AC_CACHE_CHECK([whether the C compiler supports __func__],
  1348. tor_cv_have_func_macro,
  1349. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  1350. #include <stdio.h>
  1351. int main(int c, char **v) { puts(__func__); }])],
  1352. tor_cv_have_func_macro=yes,
  1353. tor_cv_have_func_macro=no))
  1354. AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
  1355. tor_cv_have_FUNC_macro,
  1356. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  1357. #include <stdio.h>
  1358. int main(int c, char **v) { puts(__FUNC__); }])],
  1359. tor_cv_have_FUNC_macro=yes,
  1360. tor_cv_have_FUNC_macro=no))
  1361. AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
  1362. tor_cv_have_FUNCTION_macro,
  1363. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  1364. #include <stdio.h>
  1365. int main(int c, char **v) { puts(__FUNCTION__); }])],
  1366. tor_cv_have_FUNCTION_macro=yes,
  1367. tor_cv_have_FUNCTION_macro=no))
  1368. AC_CACHE_CHECK([whether we have extern char **environ already declared],
  1369. tor_cv_have_environ_declared,
  1370. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  1371. #ifdef HAVE_UNISTD_H
  1372. #include <unistd.h>
  1373. #endif
  1374. #include <stdlib.h>
  1375. int main(int c, char **v) { char **t = environ; }])],
  1376. tor_cv_have_environ_declared=yes,
  1377. tor_cv_have_environ_declared=no))
  1378. if test "$tor_cv_have_func_macro" = "yes"; then
  1379. AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
  1380. fi
  1381. if test "$tor_cv_have_FUNC_macro" = "yes"; then
  1382. AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
  1383. fi
  1384. if test "$tor_cv_have_FUNCTION_macro" = "yes"; then
  1385. AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
  1386. [Defined if the compiler supports __FUNCTION__])
  1387. fi
  1388. if test "$tor_cv_have_environ_declared" = "yes"; then
  1389. AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
  1390. [Defined if we have extern char **environ already declared])
  1391. fi
  1392. # $prefix stores the value of the --prefix command line option, or
  1393. # NONE if the option wasn't set. In the case that it wasn't set, make
  1394. # it be the default, so that we can use it to expand directories now.
  1395. if test "x$prefix" = "xNONE"; then
  1396. prefix=$ac_default_prefix
  1397. fi
  1398. # and similarly for $exec_prefix
  1399. if test "x$exec_prefix" = "xNONE"; then
  1400. exec_prefix=$prefix
  1401. fi
  1402. if test "x$BUILDDIR" = "x"; then
  1403. BUILDDIR=`pwd`
  1404. fi
  1405. AC_SUBST(BUILDDIR)
  1406. AH_TEMPLATE([BUILDDIR],[tor's build directory])
  1407. AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
  1408. if test "x$CONFDIR" = "x"; then
  1409. CONFDIR=`eval echo $sysconfdir/tor`
  1410. fi
  1411. AC_SUBST(CONFDIR)
  1412. AH_TEMPLATE([CONFDIR],[tor's configuration directory])
  1413. AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
  1414. BINDIR=`eval echo $bindir`
  1415. AC_SUBST(BINDIR)
  1416. LOCALSTATEDIR=`eval echo $localstatedir`
  1417. AC_SUBST(LOCALSTATEDIR)
  1418. if test "$bwin32" = "true"; then
  1419. # Test if the linker supports the --nxcompat and --dynamicbase options
  1420. # for Windows
  1421. save_LDFLAGS="$LDFLAGS"
  1422. LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
  1423. AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
  1424. AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
  1425. [AC_MSG_RESULT([yes])]
  1426. [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
  1427. [AC_MSG_RESULT([no])]
  1428. )
  1429. LDFLAGS="$save_LDFLAGS"
  1430. fi
  1431. # Set CFLAGS _after_ all the above checks, since our warnings are stricter
  1432. # than autoconf's macros like.
  1433. if test "$GCC" = "yes"; then
  1434. # Disable GCC's strict aliasing checks. They are an hours-to-debug
  1435. # accident waiting to happen.
  1436. CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
  1437. else
  1438. # Override optimization level for non-gcc compilers
  1439. CFLAGS="$CFLAGS -O"
  1440. enable_gcc_warnings=no
  1441. enable_gcc_warnings_advisory=no
  1442. fi
  1443. # Warnings implies advisory-warnings and -Werror.
  1444. if test "$enable_gcc_warnings" = "yes"; then
  1445. enable_gcc_warnings_advisory=yes
  1446. enable_fatal_warnings=yes
  1447. fi
  1448. # OS X Lion started deprecating the system openssl. Let's just disable
  1449. # all deprecation warnings on OS X. Also, to potentially make the binary
  1450. # a little smaller, let's enable dead_strip.
  1451. case "$host_os" in
  1452. darwin*)
  1453. CFLAGS="$CFLAGS -Wno-deprecated-declarations"
  1454. LDFLAGS="$LDFLAGS -dead_strip" ;;
  1455. esac
  1456. # Add some more warnings which we use in development but not in the
  1457. # released versions. (Some relevant gcc versions can't handle these.)
  1458. #
  1459. # Note that we have to do this near the end of the autoconf process, or
  1460. # else we may run into problems when these warnings hit on the testing C
  1461. # programs that autoconf wants to build.
  1462. if test "x$enable_gcc_warnings_advisory" != "xno"; then
  1463. case "$host" in
  1464. *-*-openbsd* | *-*-bitrig*)
  1465. # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
  1466. # That's fine, except that the headers don't pass -Wredundant-decls.
  1467. # Therefore, let's disable -Wsystem-headers when we're building
  1468. # with maximal warnings on OpenBSD.
  1469. CFLAGS="$CFLAGS -Wno-system-headers" ;;
  1470. esac
  1471. # GCC4.3 users once report trouble with -Wstrict-overflow=5. GCC5 users
  1472. # have it work better.
  1473. # CFLAGS="$CFLAGS -Wstrict-overflow=1"
  1474. # This warning was added in gcc 4.3, but it appears to generate
  1475. # spurious warnings in gcc 4.4. I don't know if it works in 4.5.
  1476. #CFLAGS="$CFLAGS -Wlogical-op"
  1477. m4_foreach_w([warning_flag], [
  1478. -Waddress
  1479. -Waddress-of-array-temporary
  1480. -Waddress-of-temporary
  1481. -Wambiguous-macro
  1482. -Wanonymous-pack-parens
  1483. -Warc
  1484. -Warc-abi
  1485. -Warc-bridge-casts-disallowed-in-nonarc
  1486. -Warc-maybe-repeated-use-of-weak
  1487. -Warc-performSelector-leaks
  1488. -Warc-repeated-use-of-weak
  1489. -Warray-bounds
  1490. -Warray-bounds-pointer-arithmetic
  1491. -Wasm
  1492. -Wasm-operand-widths
  1493. -Watomic-properties
  1494. -Watomic-property-with-user-defined-accessor
  1495. -Wauto-import
  1496. -Wauto-storage-class
  1497. -Wauto-var-id
  1498. -Wavailability
  1499. -Wbackslash-newline-escape
  1500. -Wbad-array-new-length
  1501. -Wbind-to-temporary-copy
  1502. -Wbitfield-constant-conversion
  1503. -Wbool-conversion
  1504. -Wbool-conversions
  1505. -Wbuiltin-requires-header
  1506. -Wchar-align
  1507. -Wcompare-distinct-pointer-types
  1508. -Wcomplex-component-init
  1509. -Wconditional-type-mismatch
  1510. -Wconfig-macros
  1511. -Wconstant-conversion
  1512. -Wconstant-logical-operand
  1513. -Wconstexpr-not-const
  1514. -Wcustom-atomic-properties
  1515. -Wdangling-field
  1516. -Wdangling-initializer-list
  1517. -Wdate-time
  1518. -Wdelegating-ctor-cycles
  1519. -Wdeprecated-implementations
  1520. -Wdeprecated-register
  1521. -Wdirect-ivar-access
  1522. -Wdiscard-qual
  1523. -Wdistributed-object-modifiers
  1524. -Wdivision-by-zero
  1525. -Wdollar-in-identifier-extension
  1526. -Wdouble-promotion
  1527. -Wduplicate-decl-specifier
  1528. -Wduplicate-enum
  1529. -Wduplicate-method-arg
  1530. -Wduplicate-method-match
  1531. -Wduplicated-cond
  1532. -Wdynamic-class-memaccess
  1533. -Wembedded-directive
  1534. -Wempty-translation-unit
  1535. -Wenum-conversion
  1536. -Wexit-time-destructors
  1537. -Wexplicit-ownership-type
  1538. -Wextern-initializer
  1539. -Wextra
  1540. -Wextra-semi
  1541. -Wextra-tokens
  1542. -Wflexible-array-extensions
  1543. -Wfloat-conversion
  1544. -Wformat-non-iso
  1545. -Wfour-char-constants
  1546. -Wgcc-compat
  1547. -Wglobal-constructors
  1548. -Wgnu-array-member-paren-init
  1549. -Wgnu-designator
  1550. -Wgnu-static-float-init
  1551. -Wheader-guard
  1552. -Wheader-hygiene
  1553. -Widiomatic-parentheses
  1554. -Wignored-attributes
  1555. -Wimplicit-atomic-properties
  1556. -Wimplicit-conversion-floating-point-to-bool
  1557. -Wimplicit-exception-spec-mismatch
  1558. -Wimplicit-fallthrough
  1559. -Wimplicit-fallthrough-per-function
  1560. -Wimplicit-retain-self
  1561. -Wimport-preprocessor-directive-pedantic
  1562. -Wincompatible-library-redeclaration
  1563. -Wincompatible-pointer-types-discards-qualifiers
  1564. -Wincomplete-implementation
  1565. -Wincomplete-module
  1566. -Wincomplete-umbrella
  1567. -Winit-self
  1568. -Wint-conversions
  1569. -Wint-to-void-pointer-cast
  1570. -Winteger-overflow
  1571. -Winvalid-constexpr
  1572. -Winvalid-iboutlet
  1573. -Winvalid-noreturn
  1574. -Winvalid-pp-token
  1575. -Winvalid-source-encoding
  1576. -Winvalid-token-paste
  1577. -Wknr-promoted-parameter
  1578. -Wlanguage-extension-token
  1579. -Wlarge-by-value-copy
  1580. -Wliteral-conversion
  1581. -Wliteral-range
  1582. -Wlocal-type-template-args
  1583. -Wlogical-op
  1584. -Wloop-analysis
  1585. -Wmain-return-type
  1586. -Wmalformed-warning-check
  1587. -Wmethod-signatures
  1588. -Wmicrosoft
  1589. -Wmicrosoft-exists
  1590. -Wmismatched-parameter-types
  1591. -Wmismatched-return-types
  1592. -Wmissing-field-initializers
  1593. -Wmissing-format-attribute
  1594. -Wmissing-noreturn
  1595. -Wmissing-selector-name
  1596. -Wmissing-sysroot
  1597. -Wmissing-variable-declarations
  1598. -Wmodule-conflict
  1599. -Wnested-anon-types
  1600. -Wnewline-eof
  1601. -Wnon-literal-null-conversion
  1602. -Wnon-pod-varargs
  1603. -Wnonportable-cfstrings
  1604. -Wnormalized=id
  1605. -Wnull-arithmetic
  1606. -Wnull-character
  1607. -Wnull-conversion
  1608. -Wnull-dereference
  1609. -Wout-of-line-declaration
  1610. -Wover-aligned
  1611. -Woverlength-strings
  1612. -Woverride-init
  1613. -Woverriding-method-mismatch
  1614. -Wpointer-type-mismatch
  1615. -Wpredefined-identifier-outside-function
  1616. -Wprotocol-property-synthesis-ambiguity
  1617. -Wreadonly-iboutlet-property
  1618. -Wreadonly-setter-attrs
  1619. -Wreceiver-expr
  1620. -Wreceiver-forward-class
  1621. -Wreceiver-is-weak
  1622. -Wreinterpret-base-class
  1623. -Wrequires-super-attribute
  1624. -Wreserved-user-defined-literal
  1625. -Wreturn-stack-address
  1626. -Wsection
  1627. -Wselector-type-mismatch
  1628. -Wsentinel
  1629. -Wserialized-diagnostics
  1630. -Wshadow
  1631. -Wshift-count-negative
  1632. -Wshift-count-overflow
  1633. -Wshift-negative-value
  1634. -Wshift-overflow=2
  1635. -Wshift-sign-overflow
  1636. -Wshorten-64-to-32
  1637. -Wsizeof-array-argument
  1638. -Wsource-uses-openmp
  1639. -Wstatic-float-init
  1640. -Wstatic-in-inline
  1641. -Wstatic-local-in-inline
  1642. -Wstrict-overflow=1
  1643. -Wstring-compare
  1644. -Wstring-conversion
  1645. -Wstrlcpy-strlcat-size
  1646. -Wstrncat-size
  1647. -Wsuggest-attribute=format
  1648. -Wsuggest-attribute=noreturn
  1649. -Wsuper-class-method-mismatch
  1650. -Wswitch-bool
  1651. -Wsync-nand
  1652. -Wtautological-constant-out-of-range-compare
  1653. -Wtentative-definition-incomplete-type
  1654. -Wtrampolines
  1655. -Wtype-safety
  1656. -Wtypedef-redefinition
  1657. -Wtypename-missing
  1658. -Wundefined-inline
  1659. -Wundefined-internal
  1660. -Wundefined-reinterpret-cast
  1661. -Wunicode
  1662. -Wunicode-whitespace
  1663. -Wunknown-warning-option
  1664. -Wunnamed-type-template-args
  1665. -Wunneeded-member-function
  1666. -Wunsequenced
  1667. -Wunsupported-visibility
  1668. -Wunused-but-set-parameter
  1669. -Wunused-but-set-variable
  1670. -Wunused-command-line-argument
  1671. -Wunused-const-variable=2
  1672. -Wunused-exception-parameter
  1673. -Wunused-local-typedefs
  1674. -Wunused-member-function
  1675. -Wunused-sanitize-argument
  1676. -Wunused-volatile-lvalue
  1677. -Wuser-defined-literals
  1678. -Wvariadic-macros
  1679. -Wvector-conversion
  1680. -Wvector-conversions
  1681. -Wvexing-parse
  1682. -Wvisibility
  1683. -Wvla-extension
  1684. -Wzero-length-array
  1685. ], [ TOR_CHECK_CFLAGS([warning_flag]) ])
  1686. dnl We should re-enable this in some later version. Clang doesn't
  1687. dnl mind, but it causes trouble with GCC.
  1688. dnl -Wstrict-overflow=2
  1689. dnl These seem to require annotations that we don't currently use,
  1690. dnl and they give false positives in our pthreads wrappers. (Clang 4)
  1691. dnl -Wthread-safety
  1692. dnl -Wthread-safety-analysis
  1693. dnl -Wthread-safety-attributes
  1694. dnl -Wthread-safety-beta
  1695. dnl -Wthread-safety-precise
  1696. CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
  1697. CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
  1698. CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
  1699. CFLAGS="$CFLAGS -Wwrite-strings"
  1700. CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
  1701. CFLAGS="$CFLAGS -Waggregate-return -Wpacked -Wunused"
  1702. CFLAGS="$CFLAGS -Wunused-parameter "
  1703. # These interfere with building main() { return 0; }, which autoconf
  1704. # likes to use as its default program.
  1705. CFLAGS="$CFLAGS -Wold-style-definition -Wmissing-declarations"
  1706. if test "$tor_cv_cflags__Wnull_dereference" = "yes"; then
  1707. AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference])
  1708. fi
  1709. if test "$tor_cv_cflags__Woverlength_strings" = "yes"; then
  1710. AC_DEFINE([HAVE_CFLAG_WOVERLENGTH_STRINGS], 1, [True if we have -Woverlength-strings])
  1711. fi
  1712. if test "x$enable_fatal_warnings" = "xyes"; then
  1713. # I'd like to use TOR_CHECK_CFLAGS here, but I can't, since the
  1714. # default autoconf programs are full of errors.
  1715. CFLAGS="$CFLAGS -Werror"
  1716. fi
  1717. fi
  1718. if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then
  1719. case "$host_os" in
  1720. darwin*)
  1721. AC_MSG_WARN([Tried to enable coverage on OSX without using the clang compiler. This might not work! If coverage fails, use CC=clang when configuring with --enable-coverage.])
  1722. esac
  1723. fi
  1724. CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
  1725. AC_CONFIG_FILES([
  1726. Doxyfile
  1727. Makefile
  1728. contrib/dist/suse/tor.sh
  1729. contrib/operator-tools/tor.logrotate
  1730. contrib/dist/tor.sh
  1731. contrib/dist/torctl
  1732. contrib/dist/tor.service
  1733. src/config/torrc.sample
  1734. src/config/torrc.minimal
  1735. scripts/maint/checkOptionDocs.pl
  1736. scripts/maint/updateVersions.pl
  1737. ])
  1738. if test "x$asciidoc" = "xtrue" && test "$ASCIIDOC" = "none"; then
  1739. regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
  1740. for file in $regular_mans ; do
  1741. if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
  1742. echo "==================================";
  1743. echo;
  1744. echo "Building Tor has failed since manpages cannot be built.";
  1745. echo;
  1746. echo "You need asciidoc installed to be able to build the manpages.";
  1747. echo "To build without manpages, use the --disable-asciidoc argument";
  1748. echo "when calling configure.";
  1749. echo;
  1750. echo "==================================";
  1751. exit 1;
  1752. fi
  1753. done
  1754. fi
  1755. if test "$fragile_hardening" = "yes"; then
  1756. AC_MSG_WARN([
  1757. ============
  1758. Warning! Building Tor with --enable-fragile-hardening (also known as
  1759. --enable-expensive-hardening) makes some kinds of attacks harder, but makes
  1760. other kinds of attacks easier. A Tor instance build with this option will be
  1761. somewhat less vulnerable to remote code execution, arithmetic overflow, or
  1762. out-of-bounds read/writes... but at the cost of becoming more vulnerable to
  1763. denial of service attacks. For more information, see
  1764. https://trac.torproject.org/projects/tor/wiki/doc/TorFragileHardening
  1765. ============
  1766. ])
  1767. fi
  1768. AC_OUTPUT