configure.ac 92 KB

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