configure.in 17 KB

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