configure.in 16 KB

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