configure.in 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. dnl $Id$
  2. dnl Copyright 2001-2004 Roger Dingledine
  3. dnl Copyright 2004-2005 Roger Dingledine, Nick Mathewson
  4. dnl See LICENSE for licensing information
  5. AC_INIT
  6. AM_INIT_AUTOMAKE(tor, 0.1.0.7-rc)
  7. AM_CONFIG_HEADER(orconfig.h)
  8. AC_CANONICAL_HOST
  9. if test -f /etc/redhat-release; then
  10. CFLAGS="$CFLAGS -I/usr/kerberos/include"
  11. fi
  12. AC_ARG_ENABLE(debug,
  13. AC_HELP_STRING(--enable-debug, compile with debugging info),
  14. [if test x$enableval = xyes; then
  15. CFLAGS="$CFLAGS -g"
  16. fi])
  17. AC_ARG_ENABLE(threads,
  18. AC_HELP_STRING(--disable-threads, disable multi-threading support))
  19. if test x$enable_threads = x; then
  20. case $host in
  21. *-*-netbsd*)
  22. # Don't try multithreading on netbsd -- there is no threadsafe DNS
  23. # lookup function there.
  24. enable_threads="no";;
  25. *)
  26. enable_threads="yes";;
  27. esac
  28. fi
  29. if test $enable_threads = "yes"; then
  30. AC_DEFINE(ENABLE_THREADS, 1, [Defined if we will try to use multithreading])
  31. fi
  32. AC_PROG_CC
  33. AC_PROG_MAKE_SET
  34. AC_PROG_RANLIB
  35. # The big search for OpenSSL
  36. # copied from openssh's configure.ac
  37. AC_ARG_WITH(ssl-dir,
  38. [ --with-ssl-dir=PATH Specify path to OpenSSL installation ],
  39. [
  40. if test "x$withval" != "xno" ; then
  41. tryssldir=$withval
  42. fi
  43. ]
  44. )
  45. AC_SEARCH_LIBS(socket, [socket])
  46. AC_SEARCH_LIBS(gethostbyname, [nsl])
  47. AC_SEARCH_LIBS(pthread_create, [pthread])
  48. AC_SEARCH_LIBS(pthread_detach, [pthread])
  49. dnl ------------------------------------------------------
  50. dnl Where do you live, libevent?
  51. AC_CACHE_CHECK([for a normal libevent], ac_cv_libevent_normal, [
  52. saved_LIBS="$LIBS"
  53. LIBS="$LIBS -levent"
  54. AC_TRY_RUN([
  55. void *event_init(void);
  56. int main(void)
  57. {
  58. if (!event_init())
  59. return -1;
  60. return 0;
  61. }], ac_cv_libevent_normal=yes, ac_cv_libevent_normal=no)
  62. LIBS="$saved_LIBS"
  63. ])
  64. if test "$ac_cv_libevent_normal" = yes; then
  65. LIBS="$LIBS -levent"
  66. else
  67. AC_CACHE_CHECK([for libevent in /usr/local/lib], ac_cv_libevent_local, [
  68. saved_LIBS="$LIBS"
  69. saved_LDFLAGS="$LDFLAGS"
  70. LIBS="$LIBS -levent"
  71. LDFLAGS="$LDFLAGS -L/usr/local/lib"
  72. AC_TRY_LINK([], [ void *event_init(void); event_init(); ],
  73. [ libevent_is_in_local=yes ], [ libevent_is_in_local=no ])
  74. if test $libevent_is_in_local = yes; then
  75. AC_TRY_RUN([
  76. void *event_init(void);
  77. int main(void)
  78. {
  79. if (!event_init())
  80. return -1;
  81. return 0;
  82. }], [ ac_cv_libevent_local=yes ], [ ac_cv_libevent_local=unlinked ])
  83. else
  84. ac_cv_libevent_local=no
  85. fi
  86. if test "$GCC" = yes -a $ac_cv_libevent_local = unlinked ; then
  87. LDFLAGS="$LDFLAGS -Wl,-R/usr/local/lib"
  88. AC_TRY_RUN([
  89. void *event_init(void);
  90. int main(void)
  91. {
  92. if (!event_init())
  93. return -1;
  94. return 0;
  95. }], [ ac_cv_libevent_local=unlinked_gcc_elf ])
  96. fi
  97. LIBS="$saved_LIBS"
  98. CFLAGS="$saved_CFLAGS"
  99. LDFLAGS="$saved_LDFLAGS" ])
  100. if test $ac_cv_libevent_local != no; then
  101. LIBS="$LIBS -levent"
  102. LDFLAGS="$LDFLAGS -L/usr/local/lib"
  103. CPPFLAGS="$CPPFLAGS -I/usr/local/include"
  104. fi
  105. if test $ac_cv_libevent_local = unlinked_gcc_elf; then
  106. LDFLAGS="$LDFLAGS -Wl,-R/usr/local/lib"
  107. if test -f /etc/ld.so.conf ; then
  108. AC_MSG_NOTICE([
  109. Apparently, you don't have /usr/local/lib in your /etc/ld.so.conf.
  110. Tor is smart enought to deal this now, but other applications aren't.
  111. You might want to add it in.])
  112. fi
  113. fi
  114. if test $ac_cv_libevent_local = unlinked ; then
  115. if test -f /etc/ld.so.conf ; then
  116. AC_MSG_NOTICE([
  117. =================================================
  118. Your libevent library is installed in /usr/local/lib,
  119. but your dynamic linker isn't configured to look for
  120. it there.
  121. Maybe you need to add /usr/local/lib to /etc/ld.so.conf,
  122. and then run ldconfig -v ?
  123. =================================================])
  124. else
  125. AC_MSG_NOTICE([
  126. =================================================
  127. Your libevent library is installed in /usr/local/lib,
  128. but your dynamic linker isn't configured to look for
  129. it there.
  130. =================================================])
  131. fi
  132. fi
  133. if test $ac_cv_libevent_local = no ; then
  134. AC_MSG_ERROR([
  135. Tor requires libevent to build. You can download the latest
  136. version of libevent from http://monkey.org/~provos/libevent/])
  137. fi
  138. fi
  139. dnl ------------------------------------------------------
  140. dnl Where do you live, OpenSSL?
  141. saved_LIBS="$LIBS"
  142. saved_LDFLAGS="$LDFLAGS"
  143. saved_CPPFLAGS="$CPPFLAGS"
  144. if test "x$prefix" != "xNONE" ; then
  145. tryssldir="$tryssldir $prefix"
  146. fi
  147. AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssldir, [
  148. for ssldir in $tryssldir "" /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /usr/pkg /opt /opt/openssl ; do
  149. CPPFLAGS="$saved_CPPFLAGS"
  150. LDFLAGS="$saved_LDFLAGS"
  151. LIBS="$saved_LIBS -lssl -lcrypto"
  152. # Skip directories if they don't exist
  153. if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
  154. continue;
  155. fi
  156. if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
  157. # Try to use $ssldir/lib if it exists, otherwise
  158. # $ssldir
  159. if test -d "$ssldir/lib" ; then
  160. LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
  161. if test ! -z "$need_dash_r" ; then
  162. LDFLAGS="-R$ssldir/lib $LDFLAGS"
  163. fi
  164. else
  165. LDFLAGS="-L$ssldir $saved_LDFLAGS"
  166. if test ! -z "$need_dash_r" ; then
  167. LDFLAGS="-R$ssldir $LDFLAGS"
  168. fi
  169. fi
  170. # Try to use $ssldir/include if it exists, otherwise
  171. # $ssldir
  172. if test -d "$ssldir/include" ; then
  173. CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
  174. else
  175. CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
  176. fi
  177. fi
  178. # Basic test to check for compatible version and correct linking
  179. # *does not* test for RSA - that comes later.
  180. AC_TRY_RUN(
  181. [
  182. #include <string.h>
  183. #include <openssl/rand.h>
  184. int main(void)
  185. {
  186. char a[2048];
  187. memset(a, 0, sizeof(a));
  188. RAND_add(a, sizeof(a), sizeof(a));
  189. return(RAND_status() <= 0);
  190. }
  191. ],
  192. [
  193. found_crypto=1
  194. break;
  195. ], []
  196. )
  197. if test ! -z "$found_crypto" ; then
  198. break;
  199. fi
  200. done
  201. if test -z "$found_crypto" ; then
  202. AC_MSG_ERROR([Could not find working OpenSSL library, please install or check config.log])
  203. fi
  204. if test -z "$ssldir" ; then
  205. ssldir="(system)"
  206. fi
  207. ac_cv_openssldir=$ssldir
  208. ])
  209. if (test ! -z "$ac_cv_openssldir" && test "x$ac_cv_openssldir" != "x(system)") ;
  210. then
  211. dnl Need to recover ssldir - test above runs in subshell
  212. ssldir=$ac_cv_openssldir
  213. if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
  214. # Try to use $ssldir/lib if it exists, otherwise
  215. # $ssldir
  216. if test -d "$ssldir/lib" ; then
  217. LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
  218. if test ! -z "$need_dash_r" ; then
  219. LDFLAGS="-R$ssldir/lib $LDFLAGS"
  220. fi
  221. else
  222. LDFLAGS="-L$ssldir $saved_LDFLAGS"
  223. if test ! -z "$need_dash_r" ; then
  224. LDFLAGS="-R$ssldir $LDFLAGS"
  225. fi
  226. fi
  227. # Try to use $ssldir/include if it exists, otherwise
  228. # $ssldir
  229. if test -d "$ssldir/include" ; then
  230. CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
  231. else
  232. CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
  233. fi
  234. fi
  235. fi
  236. LIBS="$saved_LIBS"
  237. AC_SYS_LARGEFILE
  238. dnl The warning message here is no longer strictly accurate.
  239. AC_CHECK_HEADERS(unistd.h string.h signal.h netdb.h ctype.h sys/stat.h sys/types.h fcntl.h sys/fcntl.h sys/ioctl.h sys/socket.h sys/time.h netinet/in.h arpa/inet.h errno.h assert.h time.h pwd.h grp.h, , AC_MSG_WARN(some headers were not found, compilation may fail))
  240. AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.))
  241. AC_CHECK_HEADERS(zlib.h, , AC_MSG_ERROR(Zlib header (zlib.h) not found. Tor requires zlib to build. You may need to install a zlib development package.))
  242. dnl These headers are not essential
  243. AC_CHECK_HEADERS(stdint.h sys/types.h inttypes.h sys/param.h sys/wait.h sys/limits.h netinet/in.h arpa/inet.h machine/limits.h syslog.h sys/time.h sys/resource.h pthread.h stddef.h inttypes.h)
  244. AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit setrlimit strlcat strlcpy strtoull getpwnam ftello pthread_create getaddrinfo localtime_r gmtime_r event_get_version event_get_method event_set_log_callback)
  245. AC_FUNC_FSEEKO
  246. AC_CHECK_MEMBERS([struct timeval.tv_sec])
  247. dnl In case we aren't given a working stdint.h, we'll need to grow our own.
  248. dnl Watch out.
  249. AC_CHECK_SIZEOF(int8_t)
  250. AC_CHECK_SIZEOF(int16_t)
  251. AC_CHECK_SIZEOF(int32_t)
  252. AC_CHECK_SIZEOF(int64_t)
  253. AC_CHECK_SIZEOF(uint8_t)
  254. AC_CHECK_SIZEOF(uint16_t)
  255. AC_CHECK_SIZEOF(uint32_t)
  256. AC_CHECK_SIZEOF(uint64_t)
  257. AC_CHECK_SIZEOF(intptr_t)
  258. AC_CHECK_SIZEOF(uintptr_t)
  259. dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
  260. AC_CHECK_SIZEOF(char)
  261. AC_CHECK_SIZEOF(short)
  262. AC_CHECK_SIZEOF(int)
  263. AC_CHECK_SIZEOF(long)
  264. AC_CHECK_SIZEOF(long long)
  265. AC_CHECK_SIZEOF(__int64)
  266. AC_CHECK_SIZEOF(void *)
  267. AC_CHECK_SIZEOF(time_t)
  268. AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
  269. #ifdef HAVE_SYS_SOCKET_H
  270. #include <sys/socket.h>
  271. #endif
  272. ])
  273. # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
  274. AC_CHECK_SIZEOF(cell_t)
  275. # Now, let's see about alignment requirements. On some platforms, we override
  276. # the default.
  277. case $host in
  278. ia64-*-* | arm-*-* )
  279. tor_cv_unaligned_ok=no
  280. ;;
  281. *)
  282. AC_CACHE_CHECK([whether unaligned int access is allowed], tor_cv_unaligned_ok,
  283. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  284. [[int main () { char s[] = "A\x00\x00\x00\x00\x00\x00\x00";
  285. return *(int*)(&s[1]); }]])],
  286. [tor_cv_unaligned_ok=yes],
  287. [tor_cv_unaligned_ok=no],
  288. [tor_cv_unaligned_ok=cross])])
  289. esac
  290. if test $tor_cv_unaligned_ok = yes; then
  291. AC_DEFINE([UNALIGNED_INT_ACCESS_OK], 1,
  292. [Define to 1 iff unaligned int access is allowed])
  293. fi
  294. # Now make sure that NULL can be represented as zero bytes.
  295. AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
  296. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  297. [[#include <stdlib.h>
  298. #include <string.h>
  299. #include <stdio.h>
  300. #ifdef HAVE_STDDEF_H
  301. #include <stddef.h>
  302. #endif
  303. int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
  304. return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
  305. [tor_cv_null_is_zero=yes],
  306. [tor_cv_null_is_zero=no],
  307. [tor_cv_null_is_zero=cross])])
  308. if test $tor_cv_null_is_zero = yes; then
  309. AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
  310. [Define to 1 iff memset(0) sets pointers to NULL])
  311. fi
  312. # Whether we should use the dmalloc memory allocation debugging library.
  313. AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
  314. AC_ARG_WITH(dmalloc,
  315. [ --with-dmalloc Use debug memory allocation library. ],
  316. [if [[ "$withval" = "yes" ]]; then
  317. dmalloc=1
  318. AC_MSG_RESULT(yes)
  319. else
  320. dmalloc=1
  321. AC_MSG_RESULT(no)
  322. fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
  323. )
  324. if [[ $dmalloc -eq 1 ]]; then
  325. AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
  326. AC_SEARCH_LIBS(dmalloc_malloc, [dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
  327. AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
  328. AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
  329. fi
  330. # Check for gethostbyname_r in all its glorious incompatible versions.
  331. # (This logic is based on that in Python's configure.in)
  332. AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
  333. [Define this if you have any gethostbyname_r()])
  334. AC_CHECK_FUNC(gethostbyname_r, [
  335. AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
  336. OLD_CFLAGS=$CFLAGS
  337. CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
  338. AC_TRY_COMPILE([
  339. #include <netdb.h>
  340. ], [
  341. char *cp1, *cp2;
  342. struct hostent *h1, *h2;
  343. int i1, i2;
  344. (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
  345. ], [
  346. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  347. AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
  348. [Define this if gethostbyname_r takes 6 arguments])
  349. AC_MSG_RESULT(6)
  350. ], [
  351. AC_TRY_COMPILE([
  352. #include <netdb.h>
  353. ], [
  354. char *cp1, *cp2;
  355. struct hostent *h1;
  356. int i1, i2;
  357. (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
  358. ], [
  359. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  360. AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
  361. [Define this if gethostbyname_r takes 5 arguments])
  362. AC_MSG_RESULT(5)
  363. ], [
  364. AC_TRY_COMPILE([
  365. #include <netdb.h>
  366. ], [
  367. char *cp1;
  368. struct hostent *h1;
  369. struct hostent_data hd;
  370. (void) gethostbyname_r(cp1,h1,&hd);
  371. ], [
  372. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  373. AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
  374. [Define this if gethostbyname_r takes 3 arguments])
  375. AC_MSG_RESULT(3)
  376. ], [
  377. AC_MSG_RESULT(0)
  378. ])
  379. ])
  380. ])
  381. CFLAGS=$OLD_CFLAGS
  382. ])
  383. # $prefix stores the value of the --prefix command line option, or
  384. # NONE if the option wasn't set. In the case that it wasn't set, make
  385. # it be the default, so that we can use it to expand directories now.
  386. if test "x$prefix" = "xNONE"; then
  387. prefix=$ac_default_prefix
  388. fi
  389. # and similarly for $exec_prefix
  390. if test "x$exec_prefix" = "xNONE"; then
  391. exec_prefix=$prefix
  392. fi
  393. CONFDIR=`eval echo $sysconfdir/tor`
  394. AC_SUBST(CONFDIR)
  395. AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
  396. AC_DEFINE([CONFDIR], [], [tor's configuration directory])
  397. BINDIR=`eval echo $bindir`
  398. AC_SUBST(BINDIR)
  399. LOCALSTATEDIR=`eval echo $localstatedir`
  400. AC_SUBST(LOCALSTATEDIR)
  401. AC_DEFINE_UNQUOTED(LOCALSTATEDIR,"$LOCALSTATEDIR")
  402. AC_DEFINE([LOCALSTATEDIR], [], [Default location to store state files.])
  403. # Set CFLAGS _after_ all the above checks, since our warnings are stricter
  404. # than autoconf's macros like.
  405. CFLAGS="$CFLAGS -Wall -g -O2"
  406. # Add some more warnings which we use in the cvs version but not in the
  407. # released versions. (Some relevant gcc versions can't handle these.)
  408. #CFLAGS="$CFLAGS -W -Wno-unused-parameter -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls"
  409. # Add these in when you feel like fun.
  410. #CFLAGS="$CFLAGS -Wbad-function-cast -Werror -Wdeclaration-after-statement"
  411. echo "confdir: $CONFDIR"
  412. AC_OUTPUT(Makefile tor.spec contrib/tor.sh contrib/torctl contrib/torify contrib/Makefile contrib/osx/Makefile contrib/osx/TorBundleDesc.plist contrib/osx/TorBundleInfo.plist contrib/osx/TorDesc.plist contrib/osx/TorInfo.plist src/config/torrc.sample doc/tor.1 src/Makefile doc/Makefile doc/design-paper/Makefile src/config/Makefile src/common/Makefile src/or/Makefile src/win32/Makefile src/tools/Makefile)
  413. if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
  414. ./contrib/updateVersions.pl
  415. fi