configure.ac 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529
  1. dnl Copyright (c) 2001-2004, Roger Dingledine
  2. dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
  3. dnl Copyright (c) 2007-2019, The Tor Project, Inc.
  4. dnl See LICENSE for licensing information
  5. AC_PREREQ([2.63])
  6. AC_INIT([tor],[0.3.5.18])
  7. AC_CONFIG_SRCDIR([src/app/main/tor_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. AC_ARG_ENABLE(openbsd-malloc,
  19. AS_HELP_STRING(--enable-openbsd-malloc, [use malloc code from OpenBSD. Linux only. Deprecated: see --with-malloc]))
  20. AC_ARG_ENABLE(static-openssl,
  21. AS_HELP_STRING(--enable-static-openssl, [link against a static openssl library. Requires --with-openssl-dir]))
  22. AC_ARG_ENABLE(static-libevent,
  23. AS_HELP_STRING(--enable-static-libevent, [link against a static libevent library. Requires --with-libevent-dir]))
  24. AC_ARG_ENABLE(static-zlib,
  25. AS_HELP_STRING(--enable-static-zlib, [link against a static zlib library. Requires --with-zlib-dir]))
  26. AC_ARG_ENABLE(static-tor,
  27. AS_HELP_STRING(--enable-static-tor, [create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir]))
  28. AC_ARG_ENABLE(unittests,
  29. AS_HELP_STRING(--disable-unittests, [don't build unit tests for Tor. Risky!]))
  30. AC_ARG_ENABLE(coverage,
  31. AS_HELP_STRING(--enable-coverage, [enable coverage support in the unit-test build]))
  32. AC_ARG_ENABLE(asserts-in-tests,
  33. AS_HELP_STRING(--disable-asserts-in-tests, [disable tor_assert() calls in the unit tests, for branch coverage]))
  34. AC_ARG_ENABLE(system-torrc,
  35. AS_HELP_STRING(--disable-system-torrc, [don't look for a system-wide torrc file]))
  36. AC_ARG_ENABLE(libfuzzer,
  37. AS_HELP_STRING(--enable-libfuzzer, [build extra fuzzers based on 'libfuzzer']))
  38. AC_ARG_ENABLE(oss-fuzz,
  39. AS_HELP_STRING(--enable-oss-fuzz, [build extra fuzzers based on 'oss-fuzz' environment]))
  40. AC_ARG_ENABLE(memory-sentinels,
  41. AS_HELP_STRING(--disable-memory-sentinels, [disable code that tries to prevent some kinds of memory access bugs. For fuzzing only.]))
  42. AC_ARG_ENABLE(rust,
  43. AS_HELP_STRING(--enable-rust, [enable rust integration]))
  44. AC_ARG_ENABLE(cargo-online-mode,
  45. AS_HELP_STRING(--enable-cargo-online-mode, [Allow cargo to make network requests to fetch crates. For builds with rust only.]))
  46. AC_ARG_ENABLE(restart-debugging,
  47. AS_HELP_STRING(--enable-restart-debugging, [Build Tor with support for debugging in-process restart. Developers only.]))
  48. AC_ARG_ENABLE(zstd-advanced-apis,
  49. AS_HELP_STRING(--disable-zstd-advanced-apis, [Build without support for zstd's "static-only" APIs.]))
  50. AC_ARG_ENABLE(nss,
  51. AS_HELP_STRING(--enable-nss, [Use Mozilla's NSS TLS library. (EXPERIMENTAL)]))
  52. AC_ARG_ENABLE(pic,
  53. AS_HELP_STRING(--enable-pic, [Build Tor's binaries as position-independent code, suitable to link as a library.]))
  54. if test "x$enable_coverage" != "xyes" -a "x$enable_asserts_in_tests" = "xno" ; then
  55. AC_MSG_ERROR([Can't disable assertions outside of coverage build])
  56. fi
  57. AM_CONDITIONAL(UNITTESTS_ENABLED, test "x$enable_unittests" != "xno")
  58. AM_CONDITIONAL(COVERAGE_ENABLED, test "x$enable_coverage" = "xyes")
  59. AM_CONDITIONAL(DISABLE_ASSERTS_IN_UNIT_TESTS, test "x$enable_asserts_in_tests" = "xno")
  60. AM_CONDITIONAL(LIBFUZZER_ENABLED, test "x$enable_libfuzzer" = "xyes")
  61. AM_CONDITIONAL(OSS_FUZZ_ENABLED, test "x$enable_oss_fuzz" = "xyes")
  62. AM_CONDITIONAL(USE_RUST, test "x$enable_rust" = "xyes")
  63. AM_CONDITIONAL(USE_NSS, test "x$enable_nss" = "xyes")
  64. AM_CONDITIONAL(USE_OPENSSL, test "x$enable_nss" != "xyes")
  65. if test "x$enable_nss" = "xyes"; then
  66. AC_DEFINE(ENABLE_NSS, 1,
  67. [Defined if we're building with NSS.])
  68. else
  69. AC_DEFINE(ENABLE_OPENSSL, 1,
  70. [Defined if we're building with OpenSSL or LibreSSL])
  71. fi
  72. if test "$enable_static_tor" = "yes"; then
  73. enable_static_libevent="yes";
  74. enable_static_openssl="yes";
  75. enable_static_zlib="yes";
  76. CFLAGS="$CFLAGS -static"
  77. fi
  78. if test "$enable_system_torrc" = "no"; then
  79. AC_DEFINE(DISABLE_SYSTEM_TORRC, 1,
  80. [Defined if we're not going to look for a torrc in SYSCONF])
  81. fi
  82. if test "$enable_memory_sentinels" = "no"; then
  83. AC_DEFINE(DISABLE_MEMORY_SENTINELS, 1,
  84. [Defined if we're turning off memory safety code to look for bugs])
  85. fi
  86. AC_ARG_ENABLE(asciidoc,
  87. AS_HELP_STRING(--disable-asciidoc, [don't use asciidoc (disables building of manpages)]),
  88. [case "${enableval}" in
  89. "yes") asciidoc=true ;;
  90. "no") asciidoc=false ;;
  91. *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
  92. esac], [asciidoc=true])
  93. # systemd notify support
  94. AC_ARG_ENABLE(systemd,
  95. AS_HELP_STRING(--enable-systemd, [enable systemd notification support]),
  96. [case "${enableval}" in
  97. "yes") systemd=true ;;
  98. "no") systemd=false ;;
  99. * ) AC_MSG_ERROR(bad value for --enable-systemd) ;;
  100. esac], [systemd=auto])
  101. if test "$enable_restart_debugging" = "yes"; then
  102. AC_DEFINE(ENABLE_RESTART_DEBUGGING, 1,
  103. [Defined if we're building with support for in-process restart debugging.])
  104. fi
  105. if test "$enable_zstd_advanced_apis" != "no"; then
  106. AC_DEFINE(ENABLE_ZSTD_ADVANCED_APIS, 1,
  107. [Defined if we're going to try to use zstd's "static-only" APIs.])
  108. fi
  109. # systemd support
  110. if test "x$enable_systemd" = "xno"; then
  111. have_systemd=no;
  112. else
  113. PKG_CHECK_MODULES(SYSTEMD,
  114. [libsystemd-daemon],
  115. have_systemd=yes,
  116. have_systemd=no)
  117. if test "x$have_systemd" = "xno"; then
  118. AC_MSG_NOTICE([Okay, checking for systemd a different way...])
  119. PKG_CHECK_MODULES(SYSTEMD,
  120. [libsystemd],
  121. have_systemd=yes,
  122. have_systemd=no)
  123. fi
  124. fi
  125. if test "x$have_systemd" = "xyes"; then
  126. AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
  127. TOR_SYSTEMD_CFLAGS="${SYSTEMD_CFLAGS}"
  128. TOR_SYSTEMD_LIBS="${SYSTEMD_LIBS}"
  129. PKG_CHECK_MODULES(LIBSYSTEMD209, [libsystemd >= 209],
  130. [AC_DEFINE(HAVE_SYSTEMD_209,1,[Have systemd v209 or more])], [])
  131. fi
  132. AC_SUBST(TOR_SYSTEMD_CFLAGS)
  133. AC_SUBST(TOR_SYSTEMD_LIBS)
  134. if test "x$enable_systemd" = "xyes" -a "x$have_systemd" != "xyes" ; then
  135. AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found])
  136. fi
  137. case "$host" in
  138. *-*-solaris* )
  139. AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
  140. ;;
  141. esac
  142. AC_ARG_ENABLE(gcc-warnings,
  143. AS_HELP_STRING(--enable-gcc-warnings, [deprecated alias for enable-fatal-warnings]))
  144. AC_ARG_ENABLE(fatal-warnings,
  145. AS_HELP_STRING(--enable-fatal-warnings, [tell the compiler to treat all warnings as errors.]))
  146. AC_ARG_ENABLE(gcc-warnings-advisory,
  147. AS_HELP_STRING(--disable-gcc-warnings-advisory, [disable the regular verbose warnings]))
  148. dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
  149. AC_ARG_ENABLE(gcc-hardening,
  150. AS_HELP_STRING(--disable-gcc-hardening, [disable compiler security checks]))
  151. dnl Deprecated --enable-expensive-hardening but keep it for now for backward compat.
  152. AC_ARG_ENABLE(expensive-hardening,
  153. AS_HELP_STRING(--enable-expensive-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
  154. AC_ARG_ENABLE(fragile-hardening,
  155. AS_HELP_STRING(--enable-fragile-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
  156. if test "x$enable_expensive_hardening" = "xyes" || test "x$enable_fragile_hardening" = "xyes"; then
  157. fragile_hardening="yes"
  158. AC_DEFINE(DEBUG_SMARTLIST, 1, [Enable smartlist debugging])
  159. fi
  160. dnl Linker hardening options
  161. dnl Currently these options are ELF specific - you can't use this with MacOSX
  162. AC_ARG_ENABLE(linker-hardening,
  163. AS_HELP_STRING(--disable-linker-hardening, [disable linker security fixups]))
  164. AC_ARG_ENABLE(local-appdata,
  165. AS_HELP_STRING(--enable-local-appdata, [default to host local application data paths on Windows]))
  166. if test "$enable_local_appdata" = "yes"; then
  167. AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
  168. [Defined if we default to host local appdata paths on Windows])
  169. fi
  170. AC_ARG_ENABLE(tool-name-check,
  171. AS_HELP_STRING(--disable-tool-name-check, [check for sanely named toolchain when cross-compiling]))
  172. AC_ARG_ENABLE(seccomp,
  173. AS_HELP_STRING(--disable-seccomp, [do not attempt to use libseccomp]))
  174. AC_ARG_ENABLE(libscrypt,
  175. AS_HELP_STRING(--disable-libscrypt, [do not attempt to use libscrypt]))
  176. dnl Enable event tracing which are transformed to debug log statement.
  177. AC_ARG_ENABLE(event-tracing-debug,
  178. AS_HELP_STRING(--enable-event-tracing-debug, [build with event tracing to debug log]))
  179. AM_CONDITIONAL([USE_EVENT_TRACING_DEBUG], [test "x$enable_event_tracing_debug" = "xyes"])
  180. if test x$enable_event_tracing_debug = xyes; then
  181. AC_DEFINE([USE_EVENT_TRACING_DEBUG], [1], [Tracing framework to log debug])
  182. AC_DEFINE([TOR_EVENT_TRACING_ENABLED], [1], [Compile the event tracing instrumentation])
  183. fi
  184. dnl Enable Android only features.
  185. AC_ARG_ENABLE(android,
  186. AS_HELP_STRING(--enable-android, [build with Android features enabled]))
  187. AM_CONDITIONAL([USE_ANDROID], [test "x$enable_android" = "xyes"])
  188. if test "x$enable_android" = "xyes"; then
  189. AC_DEFINE([USE_ANDROID], [1], [Compile with Android specific features enabled])
  190. dnl Check if the Android log library is available.
  191. AC_CHECK_HEADERS([android/log.h])
  192. AC_SEARCH_LIBS(__android_log_write, [log])
  193. fi
  194. dnl ---
  195. dnl Tor modules options. These options are namespaced with --disable-module-XXX
  196. dnl ---
  197. dnl All our modules.
  198. m4_define(MODULES, dirauth)
  199. dnl Directory Authority module.
  200. AC_ARG_ENABLE([module-dirauth],
  201. AS_HELP_STRING([--disable-module-dirauth],
  202. [Do not build tor with the dirauth module]),
  203. [], dnl Action if-given
  204. AC_DEFINE([HAVE_MODULE_DIRAUTH], [1],
  205. [Compile with Directory Authority feature support]))
  206. AM_CONDITIONAL(BUILD_MODULE_DIRAUTH, [test "x$enable_module_dirauth" != "xno"])
  207. dnl Helper variables.
  208. TOR_MODULES_ALL_ENABLED=
  209. AC_DEFUN([ADD_MODULE], [
  210. MODULE=m4_toupper($1)
  211. TOR_MODULES_ALL_ENABLED="${TOR_MODULES_ALL_ENABLED} -DHAVE_MODULE_${MODULE}=1"
  212. ])
  213. m4_foreach_w([module], MODULES, [ADD_MODULE([module])])
  214. AC_SUBST(TOR_MODULES_ALL_ENABLED)
  215. dnl check for the correct "ar" when cross-compiling.
  216. dnl (AM_PROG_AR was new in automake 1.11.2, which we do not yet require,
  217. dnl so kludge up a replacement for the case where it isn't there yet.)
  218. m4_ifdef([AM_PROG_AR],
  219. [AM_PROG_AR],
  220. [AN_MAKEVAR([AR], [AC_PROG_AR])
  221. AN_PROGRAM([ar], [AC_PROG_AR])
  222. AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [:])])
  223. AC_PROG_AR])
  224. dnl Check whether the above macro has settled for a simply named tool even
  225. dnl though we're cross compiling. We must do this before running AC_PROG_CC,
  226. dnl because that will find any cc on the system, not only the cross-compiler,
  227. dnl and then verify that a binary built with this compiler runs on the
  228. dnl build system. It will then come to the false conclusion that we're not
  229. dnl cross-compiling.
  230. if test "x$enable_tool_name_check" != "xno"; then
  231. if test "x$ac_tool_warned" = "xyes"; then
  232. 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.)])
  233. elif test "x$ac_ct_AR" != "x" -a "x$cross_compiling" = "xmaybe"; then
  234. 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.)])
  235. fi
  236. fi
  237. AC_PROG_CC
  238. AC_PROG_CPP
  239. AC_PROG_MAKE_SET
  240. AC_PROG_RANLIB
  241. AC_PROG_SED
  242. AC_ARG_VAR([PERL], [path to Perl binary])
  243. AC_CHECK_PROGS([PERL], [perl])
  244. AM_CONDITIONAL(USE_PERL, [test "x$ac_cv_prog_PERL" != "x"])
  245. dnl check for asciidoc and a2x
  246. AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
  247. AC_PATH_PROGS([A2X], [a2x a2x.py], none)
  248. AM_CONDITIONAL(USE_ASCIIDOC, test "x$asciidoc" = "xtrue")
  249. AM_PROG_CC_C_O
  250. AC_PROG_CC_C99
  251. AC_ARG_VAR([PYTHON], [path to Python binary])
  252. AC_CHECK_PROGS(PYTHON, [ \
  253. python3 \
  254. python3.8 python3.7 python3.6 python3.5 python3.4 \
  255. python \
  256. python2 python2.7])
  257. if test "x$PYTHON" = "x"; then
  258. AC_MSG_WARN([Python unavailable; some tests will not be run.])
  259. fi
  260. AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
  261. dnl List all external rust crates we depend on here. Include the version
  262. rust_crates=" \
  263. digest-0.7.2 \
  264. libc-0.2.39 \
  265. "
  266. AC_SUBST(rust_crates)
  267. ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
  268. AC_C_FLEXIBLE_ARRAY_MEMBER
  269. ], [
  270. dnl Maybe we've got an old autoconf...
  271. AC_CACHE_CHECK([for flexible array members],
  272. tor_cv_c_flexarray,
  273. [AC_COMPILE_IFELSE(
  274. AC_LANG_PROGRAM([
  275. struct abc { int a; char b[]; };
  276. ], [
  277. struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
  278. def->b[0] = 33;
  279. ]),
  280. [tor_cv_c_flexarray=yes],
  281. [tor_cv_c_flexarray=no])])
  282. if test "$tor_cv_flexarray" = "yes"; then
  283. AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
  284. else
  285. AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
  286. fi
  287. ])
  288. AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
  289. tor_cv_c_c99_decl,
  290. [AC_COMPILE_IFELSE(
  291. [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
  292. [tor_cv_c_c99_decl=yes],
  293. [tor_cv_c_c99_decl=no] )])
  294. if test "$tor_cv_c_c99_decl" != "yes"; then
  295. AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
  296. fi
  297. AC_CACHE_CHECK([for working C99 designated initializers],
  298. tor_cv_c_c99_designated_init,
  299. [AC_COMPILE_IFELSE(
  300. [AC_LANG_PROGRAM([struct s { int a; int b; };],
  301. [[ struct s ss = { .b = 5, .a = 6 }; ]])],
  302. [tor_cv_c_c99_designated_init=yes],
  303. [tor_cv_c_c99_designated_init=no] )])
  304. if test "$tor_cv_c_c99_designated_init" != "yes"; then
  305. AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
  306. fi
  307. saved_CFLAGS="$CFLAGS"
  308. CFLAGS="$CFLAGS -Werror"
  309. AC_CACHE_CHECK([for __attribute__((fallthrough))],
  310. tor_cv_c_attr_fallthrough,
  311. [AC_COMPILE_IFELSE(
  312. [AC_LANG_PROGRAM([extern int x; void fn(void) ;],
  313. [[ switch (x) { case 1: fn(); __attribute__((fallthrough));
  314. case 2: fn(); break; } ]])],
  315. [tor_cv_c_attr_fallthrough=yes],
  316. [tor_cv_c_attr_fallthrough=no] )])
  317. CFLAGS="$saved_CFLAGS"
  318. if test "$tor_cv_c_attr_fallthrough" = "yes"; then
  319. AC_DEFINE(HAVE_ATTR_FALLTHROUGH, [1], [defined if we have the fallthrough attribute.])
  320. fi
  321. TORUSER=_tor
  322. AC_ARG_WITH(tor-user,
  323. AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
  324. [
  325. TORUSER=$withval
  326. ]
  327. )
  328. AC_SUBST(TORUSER)
  329. TORGROUP=_tor
  330. AC_ARG_WITH(tor-group,
  331. AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
  332. [
  333. TORGROUP=$withval
  334. ]
  335. )
  336. AC_SUBST(TORGROUP)
  337. dnl If _WIN32 is defined and non-zero, we are building for win32
  338. AC_MSG_CHECKING([for win32])
  339. AC_RUN_IFELSE([AC_LANG_SOURCE([
  340. int main(int c, char **v) {
  341. #ifdef _WIN32
  342. #if _WIN32
  343. return 0;
  344. #else
  345. return 1;
  346. #endif
  347. #else
  348. return 2;
  349. #endif
  350. }])],
  351. bwin32=true; AC_MSG_RESULT([yes]),
  352. bwin32=false; AC_MSG_RESULT([no]),
  353. bwin32=cross; AC_MSG_RESULT([cross])
  354. )
  355. if test "$bwin32" = "cross"; then
  356. AC_MSG_CHECKING([for win32 (cross)])
  357. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  358. #ifdef _WIN32
  359. int main(int c, char **v) {return 0;}
  360. #else
  361. #error
  362. int main(int c, char **v) {return x(y);}
  363. #endif
  364. ])],
  365. bwin32=true; AC_MSG_RESULT([yes]),
  366. bwin32=false; AC_MSG_RESULT([no]))
  367. fi
  368. AH_BOTTOM([
  369. #ifdef _WIN32
  370. /* Defined to access windows functions and definitions for >=WinXP */
  371. # ifndef WINVER
  372. # define WINVER 0x0501
  373. # endif
  374. /* Defined to access _other_ windows functions and definitions for >=WinXP */
  375. # ifndef _WIN32_WINNT
  376. # define _WIN32_WINNT 0x0501
  377. # endif
  378. /* Defined to avoid including some windows headers as part of Windows.h */
  379. # ifndef WIN32_LEAN_AND_MEAN
  380. # define WIN32_LEAN_AND_MEAN 1
  381. # endif
  382. #endif
  383. ])
  384. AM_CONDITIONAL(WIN32, test "x$bwin32" = "xtrue")
  385. AM_CONDITIONAL(BUILD_NT_SERVICES, test "x$bwin32" = "xtrue")
  386. AM_CONDITIONAL(BUILD_LIBTORRUNNER, test "x$bwin32" != "xtrue")
  387. dnl Enable C99 when compiling with MIPSpro
  388. AC_MSG_CHECKING([for MIPSpro compiler])
  389. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
  390. #if (defined(__sgi) && defined(_COMPILER_VERSION))
  391. #error
  392. return x(y);
  393. #endif
  394. ])],
  395. bmipspro=false; AC_MSG_RESULT(no),
  396. bmipspro=true; AC_MSG_RESULT(yes))
  397. if test "$bmipspro" = "true"; then
  398. CFLAGS="$CFLAGS -c99"
  399. fi
  400. AC_C_BIGENDIAN
  401. AC_ARG_VAR([TOR_RUST_TARGET], [Rust target, must be specified when cross-compiling (HOST != BUILD). example: i686-pc-windows-gnu])
  402. if test "x$enable_rust" = "xyes"; then
  403. AC_ARG_VAR([RUSTC], [path to the rustc binary])
  404. AC_CHECK_PROG([RUSTC], [rustc], [rustc],[no])
  405. if test "x$RUSTC" = "xno"; then
  406. AC_MSG_ERROR([rustc unavailable but rust integration requested.])
  407. fi
  408. AC_ARG_VAR([CARGO], [path to the cargo binary])
  409. AC_CHECK_PROG([CARGO], [cargo], [cargo],[no])
  410. if test "x$CARGO" = "xno"; then
  411. AC_MSG_ERROR([cargo unavailable but rust integration requested.])
  412. fi
  413. AC_DEFINE([HAVE_RUST], 1, [have Rust])
  414. if test "x$enable_fatal_warnings" = "xyes"; then
  415. RUST_WARN=
  416. else
  417. RUST_WARN=#
  418. fi
  419. if test "x$enable_cargo_online_mode" = "xyes"; then
  420. CARGO_ONLINE=
  421. RUST_DL=#
  422. else
  423. CARGO_ONLINE=--frozen
  424. RUST_DL=
  425. dnl When we're not allowed to touch the network, we need crate dependencies
  426. dnl locally available.
  427. AC_MSG_CHECKING([rust crate dependencies])
  428. AC_ARG_VAR([TOR_RUST_DEPENDENCIES], [path to directory with local crate mirror])
  429. if test "x$TOR_RUST_DEPENDENCIES" = "x"; then
  430. TOR_RUST_DEPENDENCIES="${srcdir}/src/ext/rust/crates"
  431. fi
  432. dnl Check whether the path exists before we try to cd into it.
  433. if test ! -d "$TOR_RUST_DEPENDENCIES"; then
  434. AC_MSG_ERROR([Rust dependency directory $TOR_RUST_DEPENDENCIES does not exist. Specify a dependency directory using the TOR_RUST_DEPENDENCIES variable or allow cargo to fetch crates using --enable-cargo-online-mode.])
  435. ERRORED=1
  436. fi
  437. dnl Make the path absolute, since we'll be using it from within a
  438. dnl subdirectory.
  439. TOR_RUST_DEPENDENCIES=$(cd "$TOR_RUST_DEPENDENCIES" ; pwd)
  440. for dep in $rust_crates; do
  441. if test ! -d "$TOR_RUST_DEPENDENCIES"/"$dep"; then
  442. AC_MSG_ERROR([Failure to find rust dependency $TOR_RUST_DEPENDENCIES/$dep. Specify a dependency directory using the TOR_RUST_DEPENDENCIES variable or allow cargo to fetch crates using --enable-cargo-online-mode.])
  443. ERRORED=1
  444. fi
  445. done
  446. if test "x$ERRORED" = "x"; then
  447. AC_MSG_RESULT([yes])
  448. fi
  449. fi
  450. dnl This is a workaround for #46797
  451. dnl (a.k.a https://github.com/rust-lang/rust/issues/46797 ). Once the
  452. dnl upstream bug is fixed, we can remove this workaround.
  453. case "$host_os" in
  454. darwin*)
  455. TOR_RUST_EXTRA_LIBS="-lresolv"
  456. ;;
  457. esac
  458. dnl For now both MSVC and MinGW rust libraries will output static libs with
  459. dnl the MSVC naming convention.
  460. if test "$bwin32" = "true"; then
  461. tor_rust_static_name=tor_rust.lib
  462. else
  463. tor_rust_static_name=libtor_rust.a
  464. fi
  465. AC_CANONICAL_BUILD
  466. if test -n "$TOR_RUST_TARGET"; then
  467. if test "$host" = "$build"; then
  468. AC_MSG_ERROR([HOST = BUILD is invalid if TOR_RUST_TARGET is specified, see configure --help for more information.])
  469. fi
  470. RUST_TARGET_PROP="target = '$TOR_RUST_TARGET'"
  471. TOR_RUST_LIB_PATH="src/rust/target/$TOR_RUST_TARGET/release/$tor_rust_static_name"
  472. else
  473. if test "$host" != "$build"; then
  474. AC_MSG_ERROR([TOR_RUST_TARGET must be specified when cross-compiling with Rust enabled.])
  475. fi
  476. RUST_TARGET_PROP=
  477. TOR_RUST_LIB_PATH="src/rust/target/release/$tor_rust_static_name"
  478. fi
  479. AC_SUBST(RUST_TARGET_PROP)
  480. AC_SUBST(TOR_RUST_LIB_PATH)
  481. AC_SUBST(CARGO_ONLINE)
  482. AC_SUBST(RUST_WARN)
  483. AC_SUBST(RUST_DL)
  484. dnl Let's check the rustc version, too
  485. AC_MSG_CHECKING([rust version])
  486. RUSTC_VERSION=`$RUSTC --version`
  487. RUSTC_VERSION_MAJOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 1`
  488. RUSTC_VERSION_MINOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 2`
  489. if test "x$RUSTC_VERSION_MAJOR" = "x" -o "x$RUSTC_VERSION_MINOR" = "x"; then
  490. AC_MSG_ERROR([rustc version couldn't be identified])
  491. fi
  492. if test "$RUSTC_VERSION_MAJOR" -lt 2 -a "$RUSTC_VERSION_MINOR" -lt 14; then
  493. AC_MSG_ERROR([rustc must be at least version 1.14])
  494. fi
  495. AC_MSG_RESULT([$RUSTC_VERSION])
  496. fi
  497. AC_SUBST(TOR_RUST_EXTRA_LIBS)
  498. AC_SEARCH_LIBS(socket, [socket network])
  499. AC_SEARCH_LIBS(gethostbyname, [nsl])
  500. AC_SEARCH_LIBS(dlopen, [dl])
  501. AC_SEARCH_LIBS(inet_aton, [resolv])
  502. AC_SEARCH_LIBS(backtrace, [execinfo])
  503. saved_LIBS="$LIBS"
  504. AC_SEARCH_LIBS([clock_gettime], [rt])
  505. if test "$LIBS" != "$saved_LIBS"; then
  506. # Looks like we need -lrt for clock_gettime().
  507. have_rt=yes
  508. fi
  509. if test "$bwin32" = "false"; then
  510. AC_SEARCH_LIBS(pthread_create, [pthread])
  511. AC_SEARCH_LIBS(pthread_detach, [pthread])
  512. fi
  513. AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
  514. AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
  515. AC_CHECK_FUNCS(
  516. _NSGetEnviron \
  517. RtlSecureZeroMemory \
  518. SecureZeroMemory \
  519. accept4 \
  520. backtrace \
  521. backtrace_symbols_fd \
  522. eventfd \
  523. explicit_bzero \
  524. timingsafe_memcmp \
  525. flock \
  526. ftime \
  527. get_current_dir_name \
  528. getaddrinfo \
  529. getdelim \
  530. getifaddrs \
  531. getline \
  532. getpass \
  533. getrlimit \
  534. gettimeofday \
  535. gmtime_r \
  536. gnu_get_libc_version \
  537. htonll \
  538. inet_aton \
  539. ioctl \
  540. issetugid \
  541. llround \
  542. localtime_r \
  543. lround \
  544. memmem \
  545. memset_s \
  546. mmap \
  547. pipe \
  548. pipe2 \
  549. prctl \
  550. readpassphrase \
  551. rint \
  552. sigaction \
  553. socketpair \
  554. statvfs \
  555. strncasecmp \
  556. strcasecmp \
  557. strlcat \
  558. strlcpy \
  559. strnlen \
  560. strptime \
  561. strtok_r \
  562. strtoull \
  563. sysconf \
  564. sysctl \
  565. truncate \
  566. uname \
  567. usleep \
  568. vasprintf \
  569. _vscprintf
  570. )
  571. # Apple messed up when they added some functions: they
  572. # forgot to decorate them with appropriate AVAILABLE_MAC_OS_VERSION
  573. # checks.
  574. # We should only probe for these functions if we are sure that we
  575. # are not targeting OS X 10.9 or earlier.
  576. AC_MSG_CHECKING([for a pre-Yosemite OS X build target])
  577. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  578. #ifdef __APPLE__
  579. # include <AvailabilityMacros.h>
  580. # ifndef MAC_OS_X_VERSION_10_10
  581. # define MAC_OS_X_VERSION_10_10 101000
  582. # endif
  583. # if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
  584. # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10
  585. # error "Running on Mac OS X 10.9 or earlier"
  586. # endif
  587. # endif
  588. #endif
  589. ]], [[]])],
  590. [on_macos_pre_10_10=no ; AC_MSG_RESULT([no])],
  591. [on_macos_pre_10_10=yes; AC_MSG_RESULT([yes])])
  592. if test "$on_macos_pre_10_10" = "no"; then
  593. AC_CHECK_FUNCS(
  594. mach_approximate_time \
  595. )
  596. fi
  597. # We should only probe for these functions if we are sure that we
  598. # are not targeting OSX 10.11 or earlier.
  599. AC_MSG_CHECKING([for a pre-Sierra OSX build target])
  600. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  601. #ifdef __APPLE__
  602. # include <AvailabilityMacros.h>
  603. # ifndef MAC_OS_X_VERSION_10_12
  604. # define MAC_OS_X_VERSION_10_12 101200
  605. # endif
  606. # if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
  607. # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
  608. # error "Running on Mac OSX 10.11 or earlier"
  609. # endif
  610. # endif
  611. #endif
  612. ]], [[]])],
  613. [on_macos_pre_10_12=no ; AC_MSG_RESULT([no])],
  614. [on_macos_pre_10_12=yes; AC_MSG_RESULT([yes])])
  615. if test "$on_macos_pre_10_12" = "no"; then
  616. AC_CHECK_FUNCS(
  617. clock_gettime \
  618. getentropy \
  619. )
  620. fi
  621. if test "$bwin32" != "true"; then
  622. AC_CHECK_HEADERS(pthread.h)
  623. AC_CHECK_FUNCS(pthread_create)
  624. AC_CHECK_FUNCS(pthread_condattr_setclock)
  625. fi
  626. if test "$bwin32" = "true"; then
  627. AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
  628. #include <windows.h>
  629. #include <conio.h>
  630. #include <wchar.h>
  631. ])
  632. fi
  633. AM_CONDITIONAL(BUILD_READPASSPHRASE_C,
  634. test "x$ac_cv_func_readpassphrase" = "xno" && test "$bwin32" = "false")
  635. AC_MSG_CHECKING([whether free(NULL) works])
  636. AC_RUN_IFELSE([AC_LANG_PROGRAM([
  637. #include <stdlib.h>
  638. ], [
  639. char *p = NULL;
  640. free(p);
  641. ])],
  642. [free_null_ok=true; AC_MSG_RESULT(yes)],
  643. [free_null_ok=false; AC_MSG_RESULT(no)],
  644. [free_null_ok=cross; AC_MSG_RESULT(cross)])
  645. if test "$free_null_ok" = "false"; then
  646. AC_MSG_ERROR([Your libc implementation doesn't allow free(NULL), as required by C99.])
  647. fi
  648. dnl ------------------------------------------------------
  649. dnl Where do you live, libevent? And how do we call you?
  650. if test "$bwin32" = "true"; then
  651. TOR_LIB_WS32=-lws2_32
  652. TOR_LIB_IPHLPAPI=-liphlpapi
  653. # Some of the cargo-cults recommend -lwsock32 as well, but I don't
  654. # think it's actually necessary.
  655. TOR_LIB_GDI=-lgdi32
  656. TOR_LIB_USERENV=-luserenv
  657. else
  658. TOR_LIB_WS32=
  659. TOR_LIB_GDI=
  660. TOR_LIB_USERENV=
  661. fi
  662. AC_SUBST(TOR_LIB_WS32)
  663. AC_SUBST(TOR_LIB_GDI)
  664. AC_SUBST(TOR_LIB_IPHLPAPI)
  665. AC_SUBST(TOR_LIB_USERENV)
  666. tor_libevent_pkg_redhat="libevent"
  667. tor_libevent_pkg_debian="libevent-dev"
  668. tor_libevent_devpkg_redhat="libevent-devel"
  669. tor_libevent_devpkg_debian="libevent-dev"
  670. dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
  671. dnl linking for static builds.
  672. STATIC_LIBEVENT_FLAGS=""
  673. if test "$enable_static_libevent" = "yes"; then
  674. if test "$have_rt" = "yes"; then
  675. STATIC_LIBEVENT_FLAGS=" -lrt "
  676. fi
  677. fi
  678. TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
  679. #ifdef _WIN32
  680. #include <winsock2.h>
  681. #endif
  682. #include <sys/time.h>
  683. #include <sys/types.h>
  684. #include <event2/event.h>], [
  685. #ifdef _WIN32
  686. #include <winsock2.h>
  687. #endif
  688. struct event_base;
  689. struct event_base *event_base_new(void);
  690. void event_base_free(struct event_base *);],
  691. [
  692. #ifdef _WIN32
  693. {WSADATA d; WSAStartup(0x101,&d); }
  694. #endif
  695. event_base_free(event_base_new());
  696. ], [--with-libevent-dir], [/opt/libevent])
  697. dnl Determine the incantation needed to link libevent.
  698. save_LIBS="$LIBS"
  699. save_LDFLAGS="$LDFLAGS"
  700. save_CPPFLAGS="$CPPFLAGS"
  701. LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
  702. LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
  703. CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
  704. AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
  705. if test "$enable_static_libevent" = "yes"; then
  706. if test "$tor_cv_library_libevent_dir" = "(system)"; then
  707. AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
  708. else
  709. TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
  710. fi
  711. else
  712. if test "x$ac_cv_header_event2_event_h" = "xyes"; then
  713. AC_SEARCH_LIBS(event_new, [event event_core], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for event_new"))
  714. 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"))
  715. if test "$ac_cv_search_event_new" != "none required"; then
  716. TOR_LIBEVENT_LIBS="$ac_cv_search_event_new"
  717. fi
  718. if test "$ac_cv_search_evdns_base_new" != "none required"; then
  719. TOR_LIBEVENT_LIBS="$ac_cv_search_evdns_base_new $TOR_LIBEVENT_LIBS"
  720. fi
  721. else
  722. AC_MSG_ERROR("libevent2 is required but the headers could not be found")
  723. fi
  724. fi
  725. dnl Now check for particular libevent functions.
  726. AC_CHECK_FUNCS([evutil_secure_rng_set_urandom_device_file \
  727. evutil_secure_rng_add_bytes \
  728. ])
  729. LIBS="$save_LIBS"
  730. LDFLAGS="$save_LDFLAGS"
  731. CPPFLAGS="$save_CPPFLAGS"
  732. dnl Check that libevent is at least at version 2.0.10, the first stable
  733. dnl release of its series
  734. CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
  735. AC_MSG_CHECKING([whether Libevent is new enough])
  736. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  737. #include <event2/event.h>
  738. #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000a00
  739. #error
  740. int x = y(zz);
  741. #else
  742. int x = 1;
  743. #endif
  744. ])], [ AC_MSG_RESULT([yes]) ],
  745. [ AC_MSG_RESULT([no])
  746. AC_MSG_ERROR([Libevent is not new enough. We require 2.0.10-stable or later]) ] )
  747. LIBS="$save_LIBS"
  748. LDFLAGS="$save_LDFLAGS"
  749. CPPFLAGS="$save_CPPFLAGS"
  750. AC_SUBST(TOR_LIBEVENT_LIBS)
  751. dnl ------------------------------------------------------
  752. dnl Where do you live, libm?
  753. dnl On some platforms (Haiku/BeOS) the math library is
  754. dnl part of libroot. In which case don't link against lm
  755. TOR_LIB_MATH=""
  756. save_LIBS="$LIBS"
  757. AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
  758. if test "$ac_cv_search_pow" != "none required"; then
  759. TOR_LIB_MATH="$ac_cv_search_pow"
  760. fi
  761. LIBS="$save_LIBS"
  762. AC_SUBST(TOR_LIB_MATH)
  763. dnl ------------------------------------------------------
  764. dnl Hello, NSS. You're new around here.
  765. if test "x$enable_nss" = "xyes"; then
  766. PKG_CHECK_MODULES(NSS,
  767. [nss],
  768. [have_nss=yes],
  769. [have_nss=no; AC_MSG_ERROR([You asked for NSS but I can't find it.])])
  770. AC_SUBST(NSS_CFLAGS)
  771. AC_SUBST(NSS_LIBS)
  772. fi
  773. dnl ------------------------------------------------------
  774. dnl Where do you live, openssl? And how do we call you?
  775. if test "x$enable_nss" != "xyes"; then
  776. tor_openssl_pkg_redhat="openssl"
  777. tor_openssl_pkg_debian="libssl-dev"
  778. tor_openssl_devpkg_redhat="openssl-devel"
  779. tor_openssl_devpkg_debian="libssl-dev"
  780. ALT_openssl_WITHVAL=""
  781. AC_ARG_WITH(ssl-dir,
  782. AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
  783. [
  784. if test "x$withval" != "xno" && test "x$withval" != "x"; then
  785. ALT_openssl_WITHVAL="$withval"
  786. fi
  787. ])
  788. AC_MSG_NOTICE([Now, we'll look for OpenSSL >= 1.0.1])
  789. TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI $TOR_LIB_WS32],
  790. [#include <openssl/ssl.h>
  791. char *getenv(const char *);],
  792. [struct ssl_cipher_st;
  793. unsigned SSL_CIPHER_get_id(const struct ssl_cipher_st *);
  794. char *getenv(const char *);],
  795. dnl This funny-looking test program calls getenv, so that the compiler
  796. dnl will neither make code that call SSL_CIPHER_get_id(NULL) [producing
  797. dnl a crash], nor optimize out the call to SSL_CIPHER_get_id().
  798. dnl We look for SSL_cipher_get_id() because it is present in
  799. dnl OpenSSL >=1.0.1, because it is not deprecated, and because Tor
  800. dnl depends on it.
  801. [if (getenv("THIS_SHOULDNT_BE_SET_X201803")) SSL_CIPHER_get_id((void *)0);], [],
  802. [/usr/local/opt/openssl /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /opt/openssl])
  803. dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
  804. if test "$enable_static_openssl" = "yes"; then
  805. if test "$tor_cv_library_openssl_dir" = "(system)"; then
  806. AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
  807. else
  808. TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
  809. fi
  810. else
  811. TOR_OPENSSL_LIBS="-lssl -lcrypto"
  812. fi
  813. AC_SUBST(TOR_OPENSSL_LIBS)
  814. dnl Now check for particular openssl functions.
  815. save_LIBS="$LIBS"
  816. save_LDFLAGS="$LDFLAGS"
  817. save_CPPFLAGS="$CPPFLAGS"
  818. LIBS="$TOR_OPENSSL_LIBS $LIBS"
  819. LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
  820. CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
  821. dnl Tor currently uses a number of APIs that are deprecated in OpenSSL 3.0.0
  822. dnl and later. We want to migrate away from them, but that will be a lot of
  823. dnl work. (See ticket tor#40166.) For now, we disable the deprecation
  824. dnl warnings.
  825. AC_MSG_CHECKING([for OpenSSL >= 3.0.0])
  826. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  827. #include <openssl/opensslv.h>
  828. #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x30000000L
  829. #error "you_have_version_3"
  830. #endif
  831. ]], [[]])],
  832. [ AC_MSG_RESULT([no]) ],
  833. [ AC_MSG_RESULT([yes]);
  834. AC_DEFINE(OPENSSL_SUPPRESS_DEPRECATED, 1, [disable openssl deprecated-function warnings]) ])
  835. AC_MSG_CHECKING([for OpenSSL < 1.0.1])
  836. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  837. #include <openssl/opensslv.h>
  838. #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1000100fL
  839. #error "too old"
  840. #endif
  841. ]], [[]])],
  842. [ AC_MSG_RESULT([no]) ],
  843. [ 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.]) ])
  844. AC_MSG_CHECKING([whether LibreSSL TLS 1.3 APIs are busted])
  845. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  846. #include <openssl/opensslv.h>
  847. #if defined(LIBRESSL_VERSION_NUMBER) && \
  848. LIBRESSL_VERSION_NUMBER >= 0x3020100fL && \
  849. LIBRESSL_VERSION_NUMBER < 0x3040100fL
  850. #error "oh no"
  851. #endif
  852. ]], [[]])],
  853. [ AC_MSG_RESULT([no]) ],
  854. [ AC_MSG_ERROR([This version of LibreSSL won't work with Tor. Please upgrade to LibreSSL 3.4.1 or later. (Or downgrade to 3.2.0 if you really must.)]) ])
  855. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  856. #include <openssl/opensslv.h>
  857. #include <openssl/evp.h>
  858. #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_ECDSA)
  859. #error "no ECC"
  860. #endif
  861. #if !defined(NID_X9_62_prime256v1) || !defined(NID_secp224r1)
  862. #error "curves unavailable"
  863. #endif
  864. ]], [[]])],
  865. [ : ],
  866. [ 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.]) ])
  867. AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
  868. [#include <openssl/ssl.h>
  869. ])
  870. AC_CHECK_FUNCS([ \
  871. ERR_load_KDF_strings \
  872. SSL_SESSION_get_master_key \
  873. SSL_get_server_random \
  874. SSL_get_client_ciphers \
  875. SSL_get_client_random \
  876. SSL_CTX_set1_groups_list \
  877. SSL_CIPHER_find \
  878. SSL_CTX_set_security_level \
  879. TLS_method
  880. ])
  881. dnl Check if OpenSSL has scrypt implementation.
  882. AC_CHECK_FUNCS([ EVP_PBE_scrypt ])
  883. dnl Check if OpenSSL structures are opaque
  884. AC_CHECK_MEMBERS([SSL.state], , ,
  885. [#include <openssl/ssl.h>
  886. ])
  887. AC_CHECK_SIZEOF(SHA_CTX, , [AC_INCLUDES_DEFAULT()
  888. #include <openssl/sha.h>
  889. ])
  890. fi # enable_nss
  891. dnl ======================================================================
  892. dnl Can we use KIST?
  893. dnl Define the set of checks for KIST scheduler support.
  894. AC_DEFUN([CHECK_KIST_SUPPORT],[
  895. dnl KIST needs struct tcp_info and for certain members to exist.
  896. AC_CHECK_MEMBERS(
  897. [struct tcp_info.tcpi_unacked, struct tcp_info.tcpi_snd_mss],
  898. , ,[[#include <netinet/tcp.h>]])
  899. dnl KIST needs SIOCOUTQNSD to exist for an ioctl call.
  900. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
  901. #include <linux/sockios.h>
  902. #ifndef SIOCOUTQNSD
  903. #error
  904. #endif
  905. ])], have_siocoutqnsd=yes, have_siocoutqnsd=no)
  906. if test "x$have_siocoutqnsd" = "xyes"; then
  907. if test "x$ac_cv_member_struct_tcp_info_tcpi_unacked" = "xyes"; then
  908. if test "x$ac_cv_member_struct_tcp_info_tcpi_snd_mss" = "xyes"; then
  909. have_kist_support=yes
  910. fi
  911. fi
  912. fi
  913. ])
  914. dnl Now, trigger the check.
  915. CHECK_KIST_SUPPORT
  916. AS_IF([test "x$have_kist_support" = "xyes"],
  917. [AC_DEFINE(HAVE_KIST_SUPPORT, 1, [Defined if KIST scheduler is supported
  918. on this system])],
  919. [AC_MSG_NOTICE([KIST scheduler can't be used. Missing support.])])
  920. LIBS="$save_LIBS"
  921. LDFLAGS="$save_LDFLAGS"
  922. CPPFLAGS="$save_CPPFLAGS"
  923. dnl ------------------------------------------------------
  924. dnl Where do you live, zlib? And how do we call you?
  925. tor_zlib_pkg_redhat="zlib"
  926. tor_zlib_pkg_debian="zlib1g"
  927. tor_zlib_devpkg_redhat="zlib-devel"
  928. tor_zlib_devpkg_debian="zlib1g-dev"
  929. TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
  930. [#include <zlib.h>],
  931. [const char * zlibVersion(void);],
  932. [zlibVersion();], [--with-zlib-dir],
  933. [/opt/zlib])
  934. if test "$enable_static_zlib" = "yes"; then
  935. if test "$tor_cv_library_zlib_dir" = "(system)"; then
  936. AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
  937. using --enable-static-zlib")
  938. else
  939. TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
  940. fi
  941. else
  942. TOR_ZLIB_LIBS="-lz"
  943. fi
  944. AC_SUBST(TOR_ZLIB_LIBS)
  945. dnl ------------------------------------------------------
  946. dnl Where we do we find lzma?
  947. AC_ARG_ENABLE(lzma,
  948. AS_HELP_STRING(--enable-lzma, [enable support for the LZMA compression scheme.]),
  949. [case "${enableval}" in
  950. "yes") lzma=true ;;
  951. "no") lzma=false ;;
  952. * ) AC_MSG_ERROR(bad value for --enable-lzma) ;;
  953. esac], [lzma=auto])
  954. if test "x$enable_lzma" = "xno"; then
  955. have_lzma=no;
  956. else
  957. PKG_CHECK_MODULES([LZMA],
  958. [liblzma],
  959. have_lzma=yes,
  960. have_lzma=no)
  961. if test "x$have_lzma" = "xno" ; then
  962. AC_MSG_WARN([Unable to find liblzma.])
  963. fi
  964. fi
  965. if test "x$have_lzma" = "xyes"; then
  966. AC_DEFINE(HAVE_LZMA,1,[Have LZMA])
  967. TOR_LZMA_CFLAGS="${LZMA_CFLAGS}"
  968. TOR_LZMA_LIBS="${LZMA_LIBS}"
  969. fi
  970. AC_SUBST(TOR_LZMA_CFLAGS)
  971. AC_SUBST(TOR_LZMA_LIBS)
  972. dnl ------------------------------------------------------
  973. dnl Where we do we find zstd?
  974. AC_ARG_ENABLE(zstd,
  975. AS_HELP_STRING(--enable-zstd, [enable support for the Zstandard compression scheme.]),
  976. [case "${enableval}" in
  977. "yes") zstd=true ;;
  978. "no") zstd=false ;;
  979. * ) AC_MSG_ERROR(bad value for --enable-zstd) ;;
  980. esac], [zstd=auto])
  981. if test "x$enable_zstd" = "xno"; then
  982. have_zstd=no;
  983. else
  984. PKG_CHECK_MODULES([ZSTD],
  985. [libzstd >= 1.1],
  986. have_zstd=yes,
  987. have_zstd=no)
  988. if test "x$have_zstd" = "xno" ; then
  989. AC_MSG_WARN([Unable to find libzstd.])
  990. fi
  991. fi
  992. if test "x$have_zstd" = "xyes"; then
  993. AC_DEFINE(HAVE_ZSTD,1,[Have Zstd])
  994. TOR_ZSTD_CFLAGS="${ZSTD_CFLAGS}"
  995. TOR_ZSTD_LIBS="${ZSTD_LIBS}"
  996. dnl now check for zstd functions
  997. save_LIBS="$LIBS"
  998. save_CFLAGS="$CFLAGS"
  999. LIBS="$LIBS $ZSTD_LIBS"
  1000. CFLAGS="$CFLAGS $ZSTD_CFLAGS"
  1001. AC_CHECK_FUNCS(ZSTD_estimateCStreamSize \
  1002. ZSTD_estimateDCtxSize)
  1003. LIBS="$save_LIBS"
  1004. CFLAGS="$save_CFLAGS"
  1005. fi
  1006. AC_SUBST(TOR_ZSTD_CFLAGS)
  1007. AC_SUBST(TOR_ZSTD_LIBS)
  1008. dnl ----------------------------------------------------------------------
  1009. dnl Check if libcap is available for capabilities.
  1010. tor_cap_pkg_debian="libcap2"
  1011. tor_cap_pkg_redhat="libcap"
  1012. tor_cap_devpkg_debian="libcap-dev"
  1013. tor_cap_devpkg_redhat="libcap-devel"
  1014. AC_CHECK_LIB([cap], [cap_init], [],
  1015. AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
  1016. )
  1017. AC_CHECK_FUNCS(cap_set_proc)
  1018. dnl ---------------------------------------------------------------------
  1019. dnl Now that we know about our major libraries, we can check for compiler
  1020. dnl and linker hardening options. We need to do this with the libraries known,
  1021. dnl since sometimes the linker will like an option but not be willing to
  1022. dnl use it with a build of a library.
  1023. all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
  1024. 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_LIB_USERENV $TOR_CAP_LIBS"
  1025. CFLAGS_FTRAPV=
  1026. CFLAGS_FWRAPV=
  1027. CFLAGS_ASAN=
  1028. CFLAGS_UBSAN=
  1029. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
  1030. #if !defined(__clang__)
  1031. #error
  1032. #endif])], have_clang=yes, have_clang=no)
  1033. if test "x$enable_pic" = "xyes"; then
  1034. TOR_CHECK_CFLAGS(-fPIC)
  1035. fi
  1036. if test "x$enable_gcc_hardening" != "xno"; then
  1037. CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
  1038. if test "x$have_clang" = "xyes"; then
  1039. TOR_CHECK_CFLAGS(-Qunused-arguments)
  1040. fi
  1041. TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
  1042. AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
  1043. AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
  1044. m4_ifdef([AS_VAR_IF],[
  1045. AS_VAR_IF(can_compile, [yes],
  1046. AS_VAR_IF(can_link, [yes],
  1047. [],
  1048. 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.)]))
  1049. )])
  1050. AS_VAR_POPDEF([can_link])
  1051. AS_VAR_POPDEF([can_compile])
  1052. TOR_CHECK_CFLAGS(-Wstack-protector)
  1053. TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
  1054. if test "$bwin32" = "false" && test "$enable_libfuzzer" != "yes" && test "$enable_oss_fuzz" != "yes"; then
  1055. if test "$enable_pic" != "yes"; then
  1056. # If we have already enabled -fPIC, then we don't also need to
  1057. # compile with -fPIE...
  1058. TOR_CHECK_CFLAGS(-fPIE)
  1059. fi
  1060. # ... but we want to link our executables with -pie in any case, since
  1061. # they're executables, not a library.
  1062. TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
  1063. fi
  1064. TOR_TRY_COMPILE_WITH_CFLAGS(-fwrapv, also_link, CFLAGS_FWRAPV="-fwrapv", true)
  1065. fi
  1066. if test "$fragile_hardening" = "yes"; then
  1067. TOR_TRY_COMPILE_WITH_CFLAGS(-ftrapv, also_link, CFLAGS_FTRAPV="-ftrapv", true)
  1068. if test "$tor_cv_cflags__ftrapv" = "yes" && test "$tor_can_link__ftrapv" != "yes"; then
  1069. 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.])
  1070. fi
  1071. if test "$tor_cv_cflags__ftrapv" != "yes"; then
  1072. AC_MSG_ERROR([You requested fragile hardening, but the compiler does not seem to support -ftrapv.])
  1073. fi
  1074. TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=address], also_link, CFLAGS_ASAN="-fsanitize=address", true)
  1075. if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
  1076. 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.*, and with Clang you need libclang_rt.ubsan*])
  1077. fi
  1078. TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=undefined], also_link, CFLAGS_UBSAN="-fsanitize=undefined", true)
  1079. if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
  1080. 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.*, and with Clang you need libclang_rt.ubsan*])
  1081. fi
  1082. TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
  1083. fi
  1084. dnl Find the correct libraries to add in order to use the sanitizers.
  1085. dnl
  1086. dnl When building Rust, Cargo will run the linker with the -nodefaultlibs
  1087. dnl option, which will prevent the compiler from linking the sanitizer
  1088. dnl libraries it needs. We need to specify them manually.
  1089. dnl
  1090. dnl What's more, we need to specify them in a linker script rather than
  1091. dnl from build.rs: these options aren't allowed in the cargo:rustc-flags
  1092. dnl variable.
  1093. RUST_LINKER_OPTIONS=""
  1094. if test "x$have_clang" = "xyes"; then
  1095. if test "x$CFLAGS_ASAN" != "x"; then
  1096. RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=$CFLAGS_ASAN -Cdefault-linker-libraries"
  1097. fi
  1098. if test "x$CFLAGS_UBSAN" != "x"; then
  1099. RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=$CFLAGS_UBSAN -Cdefault-linker-libraries"
  1100. fi
  1101. else
  1102. if test "x$CFLAGS_ASAN" != "x"; then
  1103. RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=-fsanitize=address -Cdefault-linker-libraries"
  1104. fi
  1105. if test "x$CFLAGS_UBSAN" != "x"; then
  1106. RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -Clink-arg=-fsanitize=undefined -Cdefault-linker-libraries"
  1107. fi
  1108. fi
  1109. AC_SUBST(RUST_LINKER_OPTIONS)
  1110. CFLAGS_BUGTRAP="$CFLAGS_FTRAPV $CFLAGS_ASAN $CFLAGS_UBSAN"
  1111. CFLAGS_CONSTTIME="$CFLAGS_FWRAPV"
  1112. mulodi_fixes_ftrapv=no
  1113. if test "$have_clang" = "yes"; then
  1114. saved_CFLAGS="$CFLAGS"
  1115. CFLAGS="$CFLAGS $CFLAGS_FTRAPV"
  1116. AC_MSG_CHECKING([whether clang -ftrapv can link a 64-bit int multiply])
  1117. AC_LINK_IFELSE([
  1118. AC_LANG_SOURCE([[
  1119. #include <stdint.h>
  1120. #include <stdlib.h>
  1121. int main(int argc, char **argv)
  1122. {
  1123. int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
  1124. * (int64_t)atoi(argv[3]);
  1125. return x == 9;
  1126. } ]])],
  1127. [ftrapv_can_link=yes; AC_MSG_RESULT([yes])],
  1128. [ftrapv_can_link=no; AC_MSG_RESULT([no])])
  1129. if test "$ftrapv_can_link" = "no"; then
  1130. AC_MSG_CHECKING([whether defining __mulodi4 fixes that])
  1131. AC_LINK_IFELSE([
  1132. AC_LANG_SOURCE([[
  1133. #include <stdint.h>
  1134. #include <stdlib.h>
  1135. int64_t __mulodi4(int64_t a, int64_t b, int *overflow) {
  1136. *overflow=0;
  1137. return a;
  1138. }
  1139. int main(int argc, char **argv)
  1140. {
  1141. int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
  1142. * (int64_t)atoi(argv[3]);
  1143. return x == 9;
  1144. } ]])],
  1145. [mulodi_fixes_ftrapv=yes; AC_MSG_RESULT([yes])],
  1146. [mulodi_fixes_ftrapv=no; AC_MSG_RESULT([no])])
  1147. fi
  1148. CFLAGS="$saved_CFLAGS"
  1149. fi
  1150. AM_CONDITIONAL(ADD_MULODI4, test "$mulodi_fixes_ftrapv" = "yes")
  1151. dnl These cflags add bunches of branches, and we haven't been able to
  1152. dnl persuade ourselves that they're suitable for code that needs to be
  1153. dnl constant time.
  1154. AC_SUBST(CFLAGS_BUGTRAP)
  1155. dnl These cflags are variant ones sutable for code that needs to be
  1156. dnl constant-time.
  1157. AC_SUBST(CFLAGS_CONSTTIME)
  1158. if test "x$enable_linker_hardening" != "xno"; then
  1159. TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
  1160. fi
  1161. # For backtrace support
  1162. TOR_CHECK_LDFLAGS(-rdynamic)
  1163. dnl ------------------------------------------------------
  1164. dnl Now see if we have a -fomit-frame-pointer compiler option.
  1165. saved_CFLAGS="$CFLAGS"
  1166. TOR_CHECK_CFLAGS(-fomit-frame-pointer)
  1167. F_OMIT_FRAME_POINTER=''
  1168. if test "$saved_CFLAGS" != "$CFLAGS"; then
  1169. if test "$fragile_hardening" = "yes"; then
  1170. F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
  1171. fi
  1172. fi
  1173. CFLAGS="$saved_CFLAGS"
  1174. AC_SUBST(F_OMIT_FRAME_POINTER)
  1175. dnl ------------------------------------------------------
  1176. dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
  1177. dnl for us, as GCC 4.6 and later do at many optimization levels), then
  1178. dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
  1179. dnl code will work.
  1180. TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
  1181. dnl ============================================================
  1182. dnl Check for libseccomp
  1183. if test "x$enable_seccomp" != "xno"; then
  1184. AC_CHECK_HEADERS([seccomp.h])
  1185. AC_SEARCH_LIBS(seccomp_init, [seccomp])
  1186. fi
  1187. dnl ============================================================
  1188. dnl Check for libscrypt
  1189. if test "x$enable_libscrypt" != "xno"; then
  1190. AC_CHECK_HEADERS([libscrypt.h])
  1191. AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
  1192. AC_CHECK_FUNCS([libscrypt_scrypt])
  1193. fi
  1194. dnl ============================================================
  1195. dnl We need an implementation of curve25519.
  1196. dnl set these defaults.
  1197. build_curve25519_donna=no
  1198. build_curve25519_donna_c64=no
  1199. use_curve25519_donna=no
  1200. use_curve25519_nacl=no
  1201. CURVE25519_LIBS=
  1202. dnl The best choice is using curve25519-donna-c64, but that requires
  1203. dnl that we
  1204. AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
  1205. tor_cv_can_use_curve25519_donna_c64,
  1206. [AC_RUN_IFELSE(
  1207. [AC_LANG_PROGRAM([dnl
  1208. #include <stdint.h>
  1209. typedef unsigned uint128_t __attribute__((mode(TI)));
  1210. int func(uint64_t a, uint64_t b) {
  1211. uint128_t c = ((uint128_t)a) * b;
  1212. int ok = ((uint64_t)(c>>96)) == 522859 &&
  1213. (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
  1214. (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
  1215. (((uint64_t)(c))&0xffffffffL) == 0;
  1216. return ok;
  1217. }
  1218. ], [dnl
  1219. int ok = func( ((uint64_t)2000000000) * 1000000000,
  1220. ((uint64_t)1234567890) << 24);
  1221. return !ok;
  1222. ])],
  1223. [tor_cv_can_use_curve25519_donna_c64=yes],
  1224. [tor_cv_can_use_curve25519_donna_c64=no],
  1225. [AC_LINK_IFELSE(
  1226. [AC_LANG_PROGRAM([dnl
  1227. #include <stdint.h>
  1228. typedef unsigned uint128_t __attribute__((mode(TI)));
  1229. int func(uint64_t a, uint64_t b) {
  1230. uint128_t c = ((uint128_t)a) * b;
  1231. int ok = ((uint64_t)(c>>96)) == 522859 &&
  1232. (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
  1233. (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
  1234. (((uint64_t)(c))&0xffffffffL) == 0;
  1235. return ok;
  1236. }
  1237. ], [dnl
  1238. int ok = func( ((uint64_t)2000000000) * 1000000000,
  1239. ((uint64_t)1234567890) << 24);
  1240. return !ok;
  1241. ])],
  1242. [tor_cv_can_use_curve25519_donna_c64=cross],
  1243. [tor_cv_can_use_curve25519_donna_c64=no])])])
  1244. AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
  1245. nacl/crypto_scalarmult_curve25519.h])
  1246. AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
  1247. tor_cv_can_use_curve25519_nacl,
  1248. [tor_saved_LIBS="$LIBS"
  1249. LIBS="$LIBS -lnacl"
  1250. AC_LINK_IFELSE(
  1251. [AC_LANG_PROGRAM([dnl
  1252. #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
  1253. #include <crypto_scalarmult_curve25519.h>
  1254. #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
  1255. #include <nacl/crypto_scalarmult_curve25519.h>
  1256. #endif
  1257. #ifdef crypto_scalarmult_curve25519_ref_BYTES
  1258. #error Hey, this is the reference implementation! That's not fast.
  1259. #endif
  1260. ], [
  1261. unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
  1262. ])], [tor_cv_can_use_curve25519_nacl=yes],
  1263. [tor_cv_can_use_curve25519_nacl=no])
  1264. LIBS="$tor_saved_LIBS" ])
  1265. dnl Okay, now we need to figure out which one to actually use. Fall back
  1266. dnl to curve25519-donna.c
  1267. if test "x$tor_cv_can_use_curve25519_donna_c64" != "xno"; then
  1268. build_curve25519_donna_c64=yes
  1269. use_curve25519_donna=yes
  1270. elif test "x$tor_cv_can_use_curve25519_nacl" = "xyes"; then
  1271. use_curve25519_nacl=yes
  1272. CURVE25519_LIBS=-lnacl
  1273. else
  1274. build_curve25519_donna=yes
  1275. use_curve25519_donna=yes
  1276. fi
  1277. if test "x$use_curve25519_donna" = "xyes"; then
  1278. AC_DEFINE(USE_CURVE25519_DONNA, 1,
  1279. [Defined if we should use an internal curve25519_donna{,_c64} implementation])
  1280. fi
  1281. if test "x$use_curve25519_nacl" = "xyes"; then
  1282. AC_DEFINE(USE_CURVE25519_NACL, 1,
  1283. [Defined if we should use a curve25519 from nacl])
  1284. fi
  1285. AM_CONDITIONAL(BUILD_CURVE25519_DONNA,
  1286. test "x$build_curve25519_donna" = "xyes")
  1287. AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64,
  1288. test "x$build_curve25519_donna_c64" = "xyes")
  1289. AC_SUBST(CURVE25519_LIBS)
  1290. dnl Make sure to enable support for large off_t if available.
  1291. AC_SYS_LARGEFILE
  1292. AC_CHECK_HEADERS([errno.h \
  1293. fcntl.h \
  1294. signal.h \
  1295. string.h \
  1296. sys/capability.h \
  1297. sys/fcntl.h \
  1298. sys/stat.h \
  1299. sys/time.h \
  1300. sys/types.h \
  1301. time.h \
  1302. unistd.h \
  1303. arpa/inet.h \
  1304. crt_externs.h \
  1305. execinfo.h \
  1306. gnu/libc-version.h \
  1307. grp.h \
  1308. ifaddrs.h \
  1309. inttypes.h \
  1310. limits.h \
  1311. linux/types.h \
  1312. machine/limits.h \
  1313. malloc.h \
  1314. malloc/malloc.h \
  1315. malloc_np.h \
  1316. netdb.h \
  1317. netinet/in.h \
  1318. netinet/in6.h \
  1319. pwd.h \
  1320. readpassphrase.h \
  1321. stdatomic.h \
  1322. sys/eventfd.h \
  1323. sys/file.h \
  1324. sys/ioctl.h \
  1325. sys/limits.h \
  1326. sys/mman.h \
  1327. sys/param.h \
  1328. sys/prctl.h \
  1329. sys/random.h \
  1330. sys/resource.h \
  1331. sys/select.h \
  1332. sys/socket.h \
  1333. sys/statvfs.h \
  1334. sys/syscall.h \
  1335. sys/sysctl.h \
  1336. sys/syslimits.h \
  1337. sys/time.h \
  1338. sys/types.h \
  1339. sys/un.h \
  1340. sys/utime.h \
  1341. sys/wait.h \
  1342. syslog.h \
  1343. utime.h])
  1344. AC_CHECK_HEADERS(sys/param.h)
  1345. AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
  1346. [#ifdef HAVE_SYS_TYPES_H
  1347. #include <sys/types.h>
  1348. #endif
  1349. #ifdef HAVE_SYS_SOCKET_H
  1350. #include <sys/socket.h>
  1351. #endif])
  1352. AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
  1353. [#ifdef HAVE_SYS_TYPES_H
  1354. #include <sys/types.h>
  1355. #endif
  1356. #ifdef HAVE_SYS_SOCKET_H
  1357. #include <sys/socket.h>
  1358. #endif
  1359. #ifdef HAVE_NET_IF_H
  1360. #include <net/if.h>
  1361. #endif
  1362. #ifdef HAVE_NETINET_IN_H
  1363. #include <netinet/in.h>
  1364. #endif])
  1365. AC_CHECK_HEADERS(linux/if.h,[],[],
  1366. [
  1367. #ifdef HAVE_SYS_SOCKET_H
  1368. #include <sys/socket.h>
  1369. #endif
  1370. ])
  1371. AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
  1372. linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
  1373. [#ifdef HAVE_SYS_TYPES_H
  1374. #include <sys/types.h>
  1375. #endif
  1376. #ifdef HAVE_SYS_SOCKET_H
  1377. #include <sys/socket.h>
  1378. #endif
  1379. #ifdef HAVE_LIMITS_H
  1380. #include <limits.h>
  1381. #endif
  1382. #ifdef HAVE_LINUX_TYPES_H
  1383. #include <linux/types.h>
  1384. #endif
  1385. #ifdef HAVE_NETINET_IN6_H
  1386. #include <netinet/in6.h>
  1387. #endif
  1388. #ifdef HAVE_NETINET_IN_H
  1389. #include <netinet/in.h>
  1390. #endif])
  1391. AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
  1392. linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
  1393. [#ifdef HAVE_SYS_TYPES_H
  1394. #include <sys/types.h>
  1395. #endif
  1396. #ifdef HAVE_SYS_SOCKET_H
  1397. #include <sys/socket.h>
  1398. #endif
  1399. #ifdef HAVE_LIMITS_H
  1400. #include <limits.h>
  1401. #endif
  1402. #ifdef HAVE_LINUX_TYPES_H
  1403. #include <linux/types.h>
  1404. #endif
  1405. #ifdef HAVE_NETINET_IN6_H
  1406. #include <netinet/in6.h>
  1407. #endif
  1408. #ifdef HAVE_NETINET_IN_H
  1409. #include <netinet/in.h>
  1410. #endif
  1411. #ifdef HAVE_LINUX_IF_H
  1412. #include <linux/if.h>
  1413. #endif])
  1414. transparent_ok=0
  1415. if test "x$net_if_found" = "x1" && test "x$net_pfvar_found" = "x1"; then
  1416. transparent_ok=1
  1417. fi
  1418. if test "x$linux_netfilter_ipv4" = "x1"; then
  1419. transparent_ok=1
  1420. fi
  1421. if test "x$linux_netfilter_ipv6_ip6_tables" = "x1"; then
  1422. transparent_ok=1
  1423. fi
  1424. if test "x$transparent_ok" = "x1"; then
  1425. AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
  1426. else
  1427. AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
  1428. fi
  1429. AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
  1430. [#ifdef HAVE_SYS_TYPES_H
  1431. #include <sys/types.h>
  1432. #endif
  1433. #ifdef HAVE_SYS_TIME_H
  1434. #include <sys/time.h>
  1435. #endif])
  1436. AC_CHECK_SIZEOF(char)
  1437. AC_CHECK_SIZEOF(short)
  1438. AC_CHECK_SIZEOF(int)
  1439. AC_CHECK_SIZEOF(long)
  1440. AC_CHECK_SIZEOF(long long)
  1441. AC_CHECK_SIZEOF(__int64)
  1442. AC_CHECK_SIZEOF(void *)
  1443. AC_CHECK_SIZEOF(time_t)
  1444. AC_CHECK_SIZEOF(size_t)
  1445. AC_CHECK_SIZEOF(pid_t)
  1446. AC_CHECK_TYPES([uint, u_char, ssize_t])
  1447. AC_PC_FROM_UCONTEXT([:])
  1448. dnl used to include sockaddr_storage, but everybody has that.
  1449. AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
  1450. [#ifdef HAVE_SYS_TYPES_H
  1451. #include <sys/types.h>
  1452. #endif
  1453. #ifdef HAVE_NETINET_IN_H
  1454. #include <netinet/in.h>
  1455. #endif
  1456. #ifdef HAVE_NETINET_IN6_H
  1457. #include <netinet/in6.h>
  1458. #endif
  1459. #ifdef HAVE_SYS_SOCKET_H
  1460. #include <sys/socket.h>
  1461. #endif
  1462. #ifdef _WIN32
  1463. #define _WIN32_WINNT 0x0501
  1464. #define WIN32_LEAN_AND_MEAN
  1465. #include <winsock2.h>
  1466. #include <ws2tcpip.h>
  1467. #endif
  1468. ])
  1469. AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
  1470. [#ifdef HAVE_SYS_TYPES_H
  1471. #include <sys/types.h>
  1472. #endif
  1473. #ifdef HAVE_NETINET_IN_H
  1474. #include <netinet/in.h>
  1475. #endif
  1476. #ifdef HAVE_NETINET_IN6_H
  1477. #include <netinet/in6.h>
  1478. #endif
  1479. #ifdef HAVE_SYS_SOCKET_H
  1480. #include <sys/socket.h>
  1481. #endif
  1482. #ifdef _WIN32
  1483. #define _WIN32_WINNT 0x0501
  1484. #define WIN32_LEAN_AND_MEAN
  1485. #include <winsock2.h>
  1486. #include <ws2tcpip.h>
  1487. #endif
  1488. ])
  1489. AC_CHECK_TYPES([rlim_t], , ,
  1490. [#ifdef HAVE_SYS_TYPES_H
  1491. #include <sys/types.h>
  1492. #endif
  1493. #ifdef HAVE_SYS_TIME_H
  1494. #include <sys/time.h>
  1495. #endif
  1496. #ifdef HAVE_SYS_RESOURCE_H
  1497. #include <sys/resource.h>
  1498. #endif
  1499. ])
  1500. AX_CHECK_SIGN([time_t],
  1501. [ : ],
  1502. [ : ], [
  1503. #ifdef HAVE_SYS_TYPES_H
  1504. #include <sys/types.h>
  1505. #endif
  1506. #ifdef HAVE_SYS_TIME_H
  1507. #include <sys/time.h>
  1508. #endif
  1509. #ifdef HAVE_TIME_H
  1510. #include <time.h>
  1511. #endif
  1512. ])
  1513. if test "$ax_cv_decl_time_t_signed" = "no"; then
  1514. AC_MSG_ERROR([You have an unsigned time_t; Tor does not support that. Please tell the Tor developers about your interesting platform.])
  1515. fi
  1516. AX_CHECK_SIGN([size_t],
  1517. [ tor_cv_size_t_signed=yes ],
  1518. [ tor_cv_size_t_signed=no ], [
  1519. #ifdef HAVE_SYS_TYPES_H
  1520. #include <sys/types.h>
  1521. #endif
  1522. ])
  1523. if test "$ax_cv_decl_size_t_signed" = "yes"; then
  1524. AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
  1525. fi
  1526. AX_CHECK_SIGN([enum always],
  1527. [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
  1528. [ : ], [
  1529. enum always { AAA, BBB, CCC };
  1530. ])
  1531. AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
  1532. #ifdef HAVE_SYS_SOCKET_H
  1533. #include <sys/socket.h>
  1534. #endif
  1535. ])
  1536. # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
  1537. AC_CHECK_SIZEOF(cell_t)
  1538. # Let's see if stdatomic works. (There are some debian clangs that screw it
  1539. # up; see Tor bug #26779 and debian bug 903709.)
  1540. AC_CACHE_CHECK([whether C11 stdatomic.h actually works],
  1541. tor_cv_stdatomic_works,
  1542. [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  1543. #include <stdatomic.h>
  1544. struct x { atomic_size_t y; };
  1545. void try_atomic_init(struct x *xx)
  1546. {
  1547. atomic_init(&xx->y, 99);
  1548. atomic_fetch_add(&xx->y, 1);
  1549. }
  1550. ]])], [tor_cv_stdatomic_works=yes], [tor_cv_stdatomic_works=no])])
  1551. if test "$tor_cv_stdatomic_works" = "yes"; then
  1552. AC_DEFINE(STDATOMIC_WORKS, 1, [Set to 1 if we can compile a simple stdatomic example.])
  1553. elif test "$ac_cv_header_stdatomic_h" = "yes"; then
  1554. AC_MSG_WARN([Your compiler provides the stdatomic.h header, but it doesn't seem to work. I'll pretend it isn't there. If you are using Clang on Debian, maybe this is because of https://bugs.debian.org/903709 ])
  1555. fi
  1556. # Now make sure that NULL can be represented as zero bytes.
  1557. AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
  1558. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1559. [[#include <stdlib.h>
  1560. #include <string.h>
  1561. #include <stdio.h>
  1562. #ifdef HAVE_STDDEF_H
  1563. #include <stddef.h>
  1564. #endif
  1565. int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
  1566. return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
  1567. [tor_cv_null_is_zero=yes],
  1568. [tor_cv_null_is_zero=no],
  1569. [tor_cv_null_is_zero=cross])])
  1570. if test "$tor_cv_null_is_zero" = "cross"; then
  1571. # Cross-compiling; let's hope that the target isn't raving mad.
  1572. AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
  1573. fi
  1574. if test "$tor_cv_null_is_zero" != "no"; then
  1575. AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
  1576. [Define to 1 iff memset(0) sets pointers to NULL])
  1577. fi
  1578. AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
  1579. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1580. [[#include <stdlib.h>
  1581. #include <string.h>
  1582. #include <stdio.h>
  1583. #ifdef HAVE_STDDEF_H
  1584. #include <stddef.h>
  1585. #endif
  1586. int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
  1587. return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
  1588. [tor_cv_dbl0_is_zero=yes],
  1589. [tor_cv_dbl0_is_zero=no],
  1590. [tor_cv_dbl0_is_zero=cross])])
  1591. if test "$tor_cv_dbl0_is_zero" = "cross"; then
  1592. # Cross-compiling; let's hope that the target isn't raving mad.
  1593. AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
  1594. fi
  1595. if test "$tor_cv_dbl0_is_zero" != "no"; then
  1596. AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
  1597. [Define to 1 iff memset(0) sets doubles to 0.0])
  1598. fi
  1599. # And what happens when we malloc zero?
  1600. AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
  1601. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1602. [[#include <stdlib.h>
  1603. #include <string.h>
  1604. #include <stdio.h>
  1605. #ifdef HAVE_STDDEF_H
  1606. #include <stddef.h>
  1607. #endif
  1608. int main () { return malloc(0)?0:1; }]])],
  1609. [tor_cv_malloc_zero_works=yes],
  1610. [tor_cv_malloc_zero_works=no],
  1611. [tor_cv_malloc_zero_works=cross])])
  1612. if test "$tor_cv_malloc_zero_works" = "cross"; then
  1613. # Cross-compiling; let's hope that the target isn't raving mad.
  1614. AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
  1615. fi
  1616. if test "$tor_cv_malloc_zero_works" = "yes"; then
  1617. AC_DEFINE([MALLOC_ZERO_WORKS], 1,
  1618. [Define to 1 iff malloc(0) returns a pointer])
  1619. fi
  1620. # whether we seem to be in a 2s-complement world.
  1621. AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
  1622. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1623. [[int main () { int problem = ((-99) != (~99)+1);
  1624. return problem ? 1 : 0; }]])],
  1625. [tor_cv_twos_complement=yes],
  1626. [tor_cv_twos_complement=no],
  1627. [tor_cv_twos_complement=cross])])
  1628. if test "$tor_cv_twos_complement" = "cross"; then
  1629. # Cross-compiling; let's hope that the target isn't raving mad.
  1630. AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
  1631. fi
  1632. if test "$tor_cv_twos_complement" != "no"; then
  1633. AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
  1634. [Define to 1 iff we represent negative integers with
  1635. two's complement])
  1636. fi
  1637. # What does shifting a negative value do?
  1638. AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
  1639. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1640. [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
  1641. [tor_cv_sign_extend=yes],
  1642. [tor_cv_sign_extend=no],
  1643. [tor_cv_sign_extend=cross])])
  1644. if test "$tor_cv_sign_extend" = "cross"; then
  1645. # Cross-compiling; let's hope that the target isn't raving mad.
  1646. AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
  1647. fi
  1648. if test "$tor_cv_sign_extend" != "no"; then
  1649. AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
  1650. [Define to 1 iff right-shifting a negative value performs sign-extension])
  1651. fi
  1652. # Is uint8_t the same type as unsigned char?
  1653. AC_CACHE_CHECK([whether uint8_t is the same type as unsigned char], tor_cv_uint8_uchar,
  1654. [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  1655. #include <stdint.h>
  1656. extern uint8_t c;
  1657. unsigned char c;]])],
  1658. [tor_cv_uint8_uchar=yes],
  1659. [tor_cv_uint8_uchar=no],
  1660. [tor_cv_uint8_uchar=cross])])
  1661. if test "$tor_cv_uint8_uchar" = "cross"; then
  1662. AC_MSG_NOTICE([Cross-compiling: we'll assume that uint8_t is the same type as unsigned char])
  1663. fi
  1664. if test "$tor_cv_uint8_uchar" = "no"; then
  1665. AC_MSG_ERROR([We assume that uint8_t is the same type as unsigned char, but your compiler disagrees.])
  1666. fi
  1667. AC_ARG_WITH(tcmalloc,
  1668. AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library. Deprecated; see --with-malloc]),
  1669. [ tcmalloc=yes ], [ tcmalloc=no ])
  1670. default_malloc=system
  1671. if test "x$enable_openbsd_malloc" = "xyes" ; then
  1672. AC_MSG_NOTICE([The --enable-openbsd-malloc argument is deprecated; use --with-malloc=openbsd instead.])
  1673. default_malloc=openbsd
  1674. fi
  1675. if test "x$tcmalloc" = "xyes"; then
  1676. AC_MSG_NOTICE([The --with-tcmalloc argument is deprecated; use --with-malloc=tcmalloc instead.])
  1677. default_malloc=tcmalloc
  1678. fi
  1679. AC_ARG_WITH(malloc,
  1680. AS_HELP_STRING([--with-malloc=[system,jemalloc,tcmalloc,openbsd]],
  1681. [select special malloc implementation [system]]),
  1682. [ malloc="$with_malloc" ], [ malloc="$default_malloc" ])
  1683. AS_CASE([$malloc],
  1684. [tcmalloc], [
  1685. PKG_CHECK_MODULES([TCMALLOC],
  1686. [libtcmalloc],
  1687. have_tcmalloc=yes,
  1688. have_tcmalloc=no)
  1689. if test "x$have_tcmalloc" = "xno" ; then
  1690. AC_MSG_ERROR([Unable to find tcmalloc requested by --with-malloc.])
  1691. fi
  1692. CFLAGS="$CFLAGS $TCMALLOC_CFLAGS"
  1693. LIBS="$TCMALLOC_LIBS $LIBS"
  1694. ],
  1695. [jemalloc], [
  1696. PKG_CHECK_MODULES([JEMALLOC],
  1697. [jemalloc],
  1698. have_jemalloc=yes,
  1699. have_jemalloc=no)
  1700. if test "x$have_tcmalloc" = "xno" ; then
  1701. AC_MSG_ERROR([Unable to find jemalloc requested by --with-malloc.])
  1702. fi
  1703. CFLAGS="$CFLAGS $JEMALLOC_CFLAGS"
  1704. LIBS="$JEMALLOC_LIBS $LIBS"
  1705. using_custom_malloc=yes
  1706. ],
  1707. [openbsd], [
  1708. AC_MSG_WARN([The openbsd malloc port is deprecated in Tor 0.3.5 and will be removed in a future version.])
  1709. enable_openbsd_malloc=yes
  1710. ],
  1711. [system], [
  1712. # handle this later, including the jemalloc fallback
  1713. ],
  1714. [AC_MSG_ERROR([--with-malloc=`$with_malloc' not supported, see --help])
  1715. ])
  1716. AM_CONDITIONAL(USE_OPENBSD_MALLOC, test "x$enable_openbsd_malloc" = "xyes")
  1717. if test "$malloc" != "system"; then
  1718. # Tell the C compiler not to use the system allocator functions.
  1719. TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
  1720. fi
  1721. if test "$using_custom_malloc" = "yes"; then
  1722. # Tell the C compiler not to use the system allocator functions.
  1723. TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
  1724. fi
  1725. # By default, we're going to assume we don't have mlockall()
  1726. # bionic and other platforms have various broken mlockall subsystems.
  1727. # Some systems don't have a working mlockall, some aren't linkable,
  1728. # and some have it but don't declare it.
  1729. AC_CHECK_FUNCS(mlockall)
  1730. AC_CHECK_DECLS([mlockall], , , [
  1731. #ifdef HAVE_SYS_MMAN_H
  1732. #include <sys/mman.h>
  1733. #endif])
  1734. # Allow user to specify an alternate syslog facility
  1735. AC_ARG_WITH(syslog-facility,
  1736. AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
  1737. syslog_facility="$withval", syslog_facility="LOG_DAEMON")
  1738. AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
  1739. AC_SUBST(LOGFACILITY)
  1740. # Check if we have getresuid and getresgid
  1741. AC_CHECK_FUNCS(getresuid getresgid)
  1742. # Check for gethostbyname_r in all its glorious incompatible versions.
  1743. # (This logic is based on that in Python's configure.in)
  1744. AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
  1745. [Define this if you have any gethostbyname_r()])
  1746. AC_CHECK_FUNC(gethostbyname_r, [
  1747. AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
  1748. OLD_CFLAGS=$CFLAGS
  1749. CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
  1750. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1751. #include <netdb.h>
  1752. ]], [[
  1753. char *cp1, *cp2;
  1754. struct hostent *h1, *h2;
  1755. int i1, i2;
  1756. (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
  1757. ]])],[
  1758. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  1759. AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
  1760. [Define this if gethostbyname_r takes 6 arguments])
  1761. AC_MSG_RESULT(6)
  1762. ], [
  1763. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1764. #include <netdb.h>
  1765. ]], [[
  1766. char *cp1, *cp2;
  1767. struct hostent *h1;
  1768. int i1, i2;
  1769. (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
  1770. ]])], [
  1771. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  1772. AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
  1773. [Define this if gethostbyname_r takes 5 arguments])
  1774. AC_MSG_RESULT(5)
  1775. ], [
  1776. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1777. #include <netdb.h>
  1778. ]], [[
  1779. char *cp1;
  1780. struct hostent *h1;
  1781. struct hostent_data hd;
  1782. (void) gethostbyname_r(cp1,h1,&hd);
  1783. ]])], [
  1784. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  1785. AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
  1786. [Define this if gethostbyname_r takes 3 arguments])
  1787. AC_MSG_RESULT(3)
  1788. ], [
  1789. AC_MSG_RESULT(0)
  1790. ])
  1791. ])
  1792. ])
  1793. CFLAGS=$OLD_CFLAGS
  1794. ])
  1795. AC_CACHE_CHECK([whether the C compiler supports __func__],
  1796. tor_cv_have_func_macro,
  1797. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  1798. #include <stdio.h>
  1799. int main(int c, char **v) { puts(__func__); }])],
  1800. tor_cv_have_func_macro=yes,
  1801. tor_cv_have_func_macro=no))
  1802. AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
  1803. tor_cv_have_FUNC_macro,
  1804. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  1805. #include <stdio.h>
  1806. int main(int c, char **v) { puts(__FUNC__); }])],
  1807. tor_cv_have_FUNC_macro=yes,
  1808. tor_cv_have_FUNC_macro=no))
  1809. AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
  1810. tor_cv_have_FUNCTION_macro,
  1811. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  1812. #include <stdio.h>
  1813. int main(int c, char **v) { puts(__FUNCTION__); }])],
  1814. tor_cv_have_FUNCTION_macro=yes,
  1815. tor_cv_have_FUNCTION_macro=no))
  1816. AC_CACHE_CHECK([whether we have extern char **environ already declared],
  1817. tor_cv_have_environ_declared,
  1818. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  1819. #ifdef HAVE_UNISTD_H
  1820. #include <unistd.h>
  1821. #endif
  1822. #include <stdlib.h>
  1823. int main(int c, char **v) { char **t = environ; }])],
  1824. tor_cv_have_environ_declared=yes,
  1825. tor_cv_have_environ_declared=no))
  1826. if test "$tor_cv_have_func_macro" = "yes"; then
  1827. AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
  1828. fi
  1829. if test "$tor_cv_have_FUNC_macro" = "yes"; then
  1830. AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
  1831. fi
  1832. if test "$tor_cv_have_FUNCTION_macro" = "yes"; then
  1833. AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
  1834. [Defined if the compiler supports __FUNCTION__])
  1835. fi
  1836. if test "$tor_cv_have_environ_declared" = "yes"; then
  1837. AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
  1838. [Defined if we have extern char **environ already declared])
  1839. fi
  1840. # $prefix stores the value of the --prefix command line option, or
  1841. # NONE if the option wasn't set. In the case that it wasn't set, make
  1842. # it be the default, so that we can use it to expand directories now.
  1843. if test "x$prefix" = "xNONE"; then
  1844. prefix=$ac_default_prefix
  1845. fi
  1846. # and similarly for $exec_prefix
  1847. if test "x$exec_prefix" = "xNONE"; then
  1848. exec_prefix=$prefix
  1849. fi
  1850. if test "x$BUILDDIR" = "x"; then
  1851. BUILDDIR=`pwd`
  1852. fi
  1853. AC_SUBST(BUILDDIR)
  1854. AH_TEMPLATE([BUILDDIR],[tor's build directory])
  1855. AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
  1856. if test "x$SRCDIR" = "x"; then
  1857. SRCDIR=$(cd "$srcdir"; pwd)
  1858. fi
  1859. AH_TEMPLATE([SRCDIR],[tor's sourcedir directory])
  1860. AC_DEFINE_UNQUOTED(SRCDIR,"$SRCDIR")
  1861. if test "x$CONFDIR" = "x"; then
  1862. CONFDIR=`eval echo $sysconfdir/tor`
  1863. fi
  1864. AC_SUBST(CONFDIR)
  1865. AH_TEMPLATE([CONFDIR],[tor's configuration directory])
  1866. AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
  1867. BINDIR=`eval echo $bindir`
  1868. AC_SUBST(BINDIR)
  1869. LOCALSTATEDIR=`eval echo $localstatedir`
  1870. AC_SUBST(LOCALSTATEDIR)
  1871. if test "$bwin32" = "true"; then
  1872. # Test if the linker supports the --nxcompat and --dynamicbase options
  1873. # for Windows
  1874. save_LDFLAGS="$LDFLAGS"
  1875. LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
  1876. AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
  1877. AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
  1878. [AC_MSG_RESULT([yes])]
  1879. [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
  1880. [AC_MSG_RESULT([no])]
  1881. )
  1882. LDFLAGS="$save_LDFLAGS"
  1883. fi
  1884. # Set CFLAGS _after_ all the above checks, since our warnings are stricter
  1885. # than autoconf's macros like.
  1886. if test "$GCC" = "yes"; then
  1887. # Disable GCC's strict aliasing checks. They are an hours-to-debug
  1888. # accident waiting to happen.
  1889. CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
  1890. else
  1891. # Override optimization level for non-gcc compilers
  1892. CFLAGS="$CFLAGS -O"
  1893. enable_gcc_warnings=no
  1894. enable_gcc_warnings_advisory=no
  1895. fi
  1896. # Warnings implies advisory-warnings and -Werror.
  1897. if test "$enable_gcc_warnings" = "yes"; then
  1898. enable_gcc_warnings_advisory=yes
  1899. enable_fatal_warnings=yes
  1900. fi
  1901. # OS X Lion started deprecating the system openssl. Let's just disable
  1902. # all deprecation warnings on OS X. Also, to potentially make the binary
  1903. # a little smaller, let's enable dead_strip.
  1904. case "$host_os" in
  1905. darwin*)
  1906. CFLAGS="$CFLAGS -Wno-deprecated-declarations"
  1907. LDFLAGS="$LDFLAGS -dead_strip" ;;
  1908. esac
  1909. TOR_WARNING_FLAGS=""
  1910. # Add some more warnings which we use in development but not in the
  1911. # released versions. (Some relevant gcc versions can't handle these.)
  1912. #
  1913. # Note that we have to do this near the end of the autoconf process, or
  1914. # else we may run into problems when these warnings hit on the testing C
  1915. # programs that autoconf wants to build.
  1916. if test "x$enable_gcc_warnings_advisory" != "xno"; then
  1917. case "$host" in
  1918. *-*-openbsd* | *-*-bitrig*)
  1919. # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
  1920. # That's fine, except that the headers don't pass -Wredundant-decls.
  1921. # Therefore, let's disable -Wsystem-headers when we're building
  1922. # with maximal warnings on OpenBSD.
  1923. CFLAGS="$CFLAGS -Wno-system-headers" ;;
  1924. esac
  1925. CFLAGS_NOWARNINGS="$CFLAGS"
  1926. # GCC4.3 users once report trouble with -Wstrict-overflow=5. GCC5 users
  1927. # have it work better.
  1928. # CFLAGS="$CFLAGS -Wstrict-overflow=1"
  1929. # This warning was added in gcc 4.3, but it appears to generate
  1930. # spurious warnings in gcc 4.4. I don't know if it works in 4.5.
  1931. #CFLAGS="$CFLAGS -Wlogical-op"
  1932. m4_foreach_w([warning_flag], [
  1933. -Waddress
  1934. -Waddress-of-array-temporary
  1935. -Waddress-of-temporary
  1936. -Wambiguous-macro
  1937. -Wanonymous-pack-parens
  1938. -Warc
  1939. -Warc-abi
  1940. -Warc-bridge-casts-disallowed-in-nonarc
  1941. -Warc-maybe-repeated-use-of-weak
  1942. -Warc-performSelector-leaks
  1943. -Warc-repeated-use-of-weak
  1944. -Warray-bounds
  1945. -Warray-bounds-pointer-arithmetic
  1946. -Wasm
  1947. -Wasm-operand-widths
  1948. -Watomic-properties
  1949. -Watomic-property-with-user-defined-accessor
  1950. -Wauto-import
  1951. -Wauto-storage-class
  1952. -Wauto-var-id
  1953. -Wavailability
  1954. -Wbackslash-newline-escape
  1955. -Wbad-array-new-length
  1956. -Wbind-to-temporary-copy
  1957. -Wbitfield-constant-conversion
  1958. -Wbool-conversion
  1959. -Wbool-conversions
  1960. -Wbuiltin-requires-header
  1961. -Wchar-align
  1962. -Wcompare-distinct-pointer-types
  1963. -Wcomplex-component-init
  1964. -Wconditional-type-mismatch
  1965. -Wconfig-macros
  1966. -Wconstant-conversion
  1967. -Wconstant-logical-operand
  1968. -Wconstexpr-not-const
  1969. -Wcustom-atomic-properties
  1970. -Wdangling-field
  1971. -Wdangling-initializer-list
  1972. -Wdate-time
  1973. -Wdelegating-ctor-cycles
  1974. -Wdeprecated-implementations
  1975. -Wdeprecated-register
  1976. -Wdirect-ivar-access
  1977. -Wdiscard-qual
  1978. -Wdistributed-object-modifiers
  1979. -Wdivision-by-zero
  1980. -Wdollar-in-identifier-extension
  1981. -Wdouble-promotion
  1982. -Wduplicate-decl-specifier
  1983. -Wduplicate-enum
  1984. -Wduplicate-method-arg
  1985. -Wduplicate-method-match
  1986. -Wduplicated-cond
  1987. -Wdynamic-class-memaccess
  1988. -Wembedded-directive
  1989. -Wempty-translation-unit
  1990. -Wenum-conversion
  1991. -Wexit-time-destructors
  1992. -Wexplicit-ownership-type
  1993. -Wextern-initializer
  1994. -Wextra
  1995. -Wextra-semi
  1996. -Wextra-tokens
  1997. -Wflexible-array-extensions
  1998. -Wfloat-conversion
  1999. -Wformat-non-iso
  2000. -Wfour-char-constants
  2001. -Wgcc-compat
  2002. -Wglobal-constructors
  2003. -Wgnu-array-member-paren-init
  2004. -Wgnu-designator
  2005. -Wgnu-static-float-init
  2006. -Wheader-guard
  2007. -Wheader-hygiene
  2008. -Widiomatic-parentheses
  2009. -Wignored-attributes
  2010. -Wimplicit-atomic-properties
  2011. -Wimplicit-conversion-floating-point-to-bool
  2012. -Wimplicit-exception-spec-mismatch
  2013. -Wimplicit-fallthrough
  2014. -Wimplicit-fallthrough-per-function
  2015. -Wimplicit-retain-self
  2016. -Wimport-preprocessor-directive-pedantic
  2017. -Wincompatible-library-redeclaration
  2018. -Wincompatible-pointer-types-discards-qualifiers
  2019. -Wincomplete-implementation
  2020. -Wincomplete-module
  2021. -Wincomplete-umbrella
  2022. -Winit-self
  2023. -Wint-conversions
  2024. -Wint-to-void-pointer-cast
  2025. -Winteger-overflow
  2026. -Winvalid-constexpr
  2027. -Winvalid-iboutlet
  2028. -Winvalid-noreturn
  2029. -Winvalid-pp-token
  2030. -Winvalid-source-encoding
  2031. -Winvalid-token-paste
  2032. -Wknr-promoted-parameter
  2033. -Wlarge-by-value-copy
  2034. -Wliteral-conversion
  2035. -Wliteral-range
  2036. -Wlocal-type-template-args
  2037. -Wlogical-op
  2038. -Wloop-analysis
  2039. -Wmain-return-type
  2040. -Wmalformed-warning-check
  2041. -Wmethod-signatures
  2042. -Wmicrosoft
  2043. -Wmicrosoft-exists
  2044. -Wmismatched-parameter-types
  2045. -Wmismatched-return-types
  2046. -Wmissing-field-initializers
  2047. -Wmissing-format-attribute
  2048. -Wmissing-noreturn
  2049. -Wmissing-selector-name
  2050. -Wmissing-sysroot
  2051. -Wmissing-variable-declarations
  2052. -Wmodule-conflict
  2053. -Wnested-anon-types
  2054. -Wnewline-eof
  2055. -Wnon-literal-null-conversion
  2056. -Wnon-pod-varargs
  2057. -Wnonportable-cfstrings
  2058. -Wnormalized=nfkc
  2059. -Wnull-arithmetic
  2060. -Wnull-character
  2061. -Wnull-conversion
  2062. -Wnull-dereference
  2063. -Wout-of-line-declaration
  2064. -Wover-aligned
  2065. -Woverlength-strings
  2066. -Woverride-init
  2067. -Woverriding-method-mismatch
  2068. -Wpointer-type-mismatch
  2069. -Wpredefined-identifier-outside-function
  2070. -Wprotocol-property-synthesis-ambiguity
  2071. -Wreadonly-iboutlet-property
  2072. -Wreadonly-setter-attrs
  2073. -Wreceiver-expr
  2074. -Wreceiver-forward-class
  2075. -Wreceiver-is-weak
  2076. -Wreinterpret-base-class
  2077. -Wrequires-super-attribute
  2078. -Wreserved-user-defined-literal
  2079. -Wreturn-stack-address
  2080. -Wsection
  2081. -Wselector-type-mismatch
  2082. -Wsentinel
  2083. -Wserialized-diagnostics
  2084. -Wshadow
  2085. -Wshift-count-negative
  2086. -Wshift-count-overflow
  2087. -Wshift-negative-value
  2088. -Wshift-overflow=2
  2089. -Wshift-sign-overflow
  2090. -Wshorten-64-to-32
  2091. -Wsizeof-array-argument
  2092. -Wsource-uses-openmp
  2093. -Wstatic-float-init
  2094. -Wstatic-in-inline
  2095. -Wstatic-local-in-inline
  2096. -Wstrict-overflow=1
  2097. -Wstring-compare
  2098. -Wstring-conversion
  2099. -Wstrlcpy-strlcat-size
  2100. -Wstrncat-size
  2101. -Wsuggest-attribute=format
  2102. -Wsuggest-attribute=noreturn
  2103. -Wsuper-class-method-mismatch
  2104. -Wswitch-bool
  2105. -Wsync-nand
  2106. -Wtautological-constant-out-of-range-compare
  2107. -Wtentative-definition-incomplete-type
  2108. -Wtrampolines
  2109. -Wtype-safety
  2110. -Wtypedef-redefinition
  2111. -Wtypename-missing
  2112. -Wundefined-inline
  2113. -Wundefined-internal
  2114. -Wundefined-reinterpret-cast
  2115. -Wunicode
  2116. -Wunicode-whitespace
  2117. -Wunknown-warning-option
  2118. -Wunnamed-type-template-args
  2119. -Wunneeded-member-function
  2120. -Wunsequenced
  2121. -Wunsupported-visibility
  2122. -Wunused-but-set-parameter
  2123. -Wunused-but-set-variable
  2124. -Wunused-command-line-argument
  2125. -Wunused-const-variable=2
  2126. -Wunused-exception-parameter
  2127. -Wunused-local-typedefs
  2128. -Wunused-member-function
  2129. -Wunused-sanitize-argument
  2130. -Wunused-volatile-lvalue
  2131. -Wuser-defined-literals
  2132. -Wvariadic-macros
  2133. -Wvector-conversion
  2134. -Wvector-conversions
  2135. -Wvexing-parse
  2136. -Wvisibility
  2137. -Wvla-extension
  2138. -Wzero-length-array
  2139. ], [ TOR_TRY_COMPILE_WITH_CFLAGS(warning_flag, [],
  2140. [TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS warning_flag" CFLAGS="$CFLAGS warning_flag"], true)
  2141. ])
  2142. dnl We should re-enable this in some later version. Clang doesn't
  2143. dnl mind, but it causes trouble with GCC.
  2144. dnl -Wstrict-overflow=2
  2145. dnl These seem to require annotations that we don't currently use,
  2146. dnl and they give false positives in our pthreads wrappers. (Clang 4)
  2147. dnl -Wthread-safety
  2148. dnl -Wthread-safety-analysis
  2149. dnl -Wthread-safety-attributes
  2150. dnl -Wthread-safety-beta
  2151. dnl -Wthread-safety-precise
  2152. W_FLAGS="$W_FLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
  2153. W_FLAGS="$W_FLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
  2154. W_FLAGS="$W_FLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
  2155. W_FLAGS="$W_FLAGS -Wwrite-strings"
  2156. W_FLAGS="$W_FLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
  2157. W_FLAGS="$W_FLAGS -Waggregate-return -Wpacked -Wunused"
  2158. W_FLAGS="$W_FLAGS -Wunused-parameter "
  2159. # These interfere with building main() { return 0; }, which autoconf
  2160. # likes to use as its default program.
  2161. W_FLAGS="$W_FLAGS -Wold-style-definition -Wmissing-declarations"
  2162. TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS $W_FLAGS"
  2163. CFLAGS="$CFLAGS $W_FLAGS"
  2164. if test "$tor_cv_cflags__Wnull_dereference" = "yes"; then
  2165. AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference])
  2166. fi
  2167. if test "$tor_cv_cflags__Woverlength_strings" = "yes"; then
  2168. AC_DEFINE([HAVE_CFLAG_WOVERLENGTH_STRINGS], 1, [True if we have -Woverlength-strings])
  2169. fi
  2170. if test "$tor_cv_cflags__warn_unused_const_variable_2" = "yes"; then
  2171. AC_DEFINE([HAVE_CFLAG_WUNUSED_CONST_VARIABLE], 1, [True if we have -Wunused-const-variable])
  2172. fi
  2173. CFLAGS="$CFLAGS_NOWARNINGS"
  2174. if test "x$enable_fatal_warnings" = "xyes"; then
  2175. # I'd like to use TOR_CHECK_CFLAGS here, but I can't, since the
  2176. # default autoconf programs are full of errors.
  2177. CFLAGS="$CFLAGS -Werror"
  2178. fi
  2179. fi
  2180. AC_SUBST(TOR_WARNING_FLAGS)
  2181. echo "$TOR_WARNING_FLAGS">warning_flags
  2182. TOR_TRY_COMPILE_WITH_CFLAGS([@warning_flags], [],
  2183. CFLAGS="$CFLAGS @warning_flags",
  2184. CFLAGS="$CFLAGS $TOR_WARNING_FLAGS")
  2185. if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then
  2186. case "$host_os" in
  2187. darwin*)
  2188. 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.])
  2189. esac
  2190. fi
  2191. CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
  2192. AC_CONFIG_FILES([
  2193. Doxyfile
  2194. Makefile
  2195. config.rust
  2196. contrib/dist/suse/tor.sh
  2197. contrib/operator-tools/tor.logrotate
  2198. contrib/dist/tor.sh
  2199. contrib/dist/torctl
  2200. contrib/dist/tor.service
  2201. src/config/torrc.sample
  2202. src/config/torrc.minimal
  2203. src/rust/.cargo/config
  2204. scripts/maint/checkOptionDocs.pl
  2205. scripts/maint/updateVersions.pl
  2206. warning_flags
  2207. ])
  2208. if test "x$asciidoc" = "xtrue" && test "$ASCIIDOC" = "none"; then
  2209. regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
  2210. for file in $regular_mans ; do
  2211. if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
  2212. echo "==================================";
  2213. echo;
  2214. echo "Building Tor has failed since manpages cannot be built.";
  2215. echo;
  2216. echo "You need asciidoc installed to be able to build the manpages.";
  2217. echo "To build without manpages, use the --disable-asciidoc argument";
  2218. echo "when calling configure.";
  2219. echo;
  2220. echo "==================================";
  2221. exit 1;
  2222. fi
  2223. done
  2224. fi
  2225. if test "$fragile_hardening" = "yes"; then
  2226. AC_MSG_WARN([
  2227. ============
  2228. Warning! Building Tor with --enable-fragile-hardening (also known as
  2229. --enable-expensive-hardening) makes some kinds of attacks harder, but makes
  2230. other kinds of attacks easier. A Tor instance build with this option will be
  2231. somewhat less vulnerable to remote code execution, arithmetic overflow, or
  2232. out-of-bounds read/writes... but at the cost of becoming more vulnerable to
  2233. denial of service attacks. For more information, see
  2234. https://trac.torproject.org/projects/tor/wiki/doc/TorFragileHardening
  2235. ============
  2236. ])
  2237. fi
  2238. AC_OUTPUT