configure.in 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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.2-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. [ --enable-debug compiles with debugging info],
  14. [if test x$enableval = xyes; then
  15. CFLAGS="$CFLAGS -g"
  16. fi])
  17. AC_PROG_CC
  18. AC_PROG_MAKE_SET
  19. AC_PROG_RANLIB
  20. # The big search for OpenSSL
  21. # copied from openssh's configure.ac
  22. AC_ARG_WITH(ssl-dir,
  23. [ --with-ssl-dir=PATH Specify path to OpenSSL installation ],
  24. [
  25. if test "x$withval" != "xno" ; then
  26. tryssldir=$withval
  27. fi
  28. ]
  29. )
  30. AC_SEARCH_LIBS(socket, [socket])
  31. AC_SEARCH_LIBS(gethostbyname, [nsl])
  32. AC_SEARCH_LIBS(pthread_create, [pthread])
  33. AC_SEARCH_LIBS(pthread_detach, [pthread])
  34. AC_SEARCH_LIBS(event_loop, [event], , AC_MSG_ERROR(Libevent library not found. Tor requires libevent to build. You can get the latest version of libevent at http://www.monkey.org/~provos/libevent/ ))
  35. saved_LIBS="$LIBS"
  36. saved_LDFLAGS="$LDFLAGS"
  37. saved_CPPFLAGS="$CPPFLAGS"
  38. if test "x$prefix" != "xNONE" ; then
  39. tryssldir="$tryssldir $prefix"
  40. fi
  41. AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssldir, [
  42. 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
  43. CPPFLAGS="$saved_CPPFLAGS"
  44. LDFLAGS="$saved_LDFLAGS"
  45. LIBS="$saved_LIBS -lssl -lcrypto"
  46. # Skip directories if they don't exist
  47. if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
  48. continue;
  49. fi
  50. if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
  51. # Try to use $ssldir/lib if it exists, otherwise
  52. # $ssldir
  53. if test -d "$ssldir/lib" ; then
  54. LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
  55. if test ! -z "$need_dash_r" ; then
  56. LDFLAGS="-R$ssldir/lib $LDFLAGS"
  57. fi
  58. else
  59. LDFLAGS="-L$ssldir $saved_LDFLAGS"
  60. if test ! -z "$need_dash_r" ; then
  61. LDFLAGS="-R$ssldir $LDFLAGS"
  62. fi
  63. fi
  64. # Try to use $ssldir/include if it exists, otherwise
  65. # $ssldir
  66. if test -d "$ssldir/include" ; then
  67. CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
  68. else
  69. CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
  70. fi
  71. fi
  72. # Basic test to check for compatible version and correct linking
  73. # *does not* test for RSA - that comes later.
  74. AC_TRY_RUN(
  75. [
  76. #include <string.h>
  77. #include <openssl/rand.h>
  78. int main(void)
  79. {
  80. char a[2048];
  81. memset(a, 0, sizeof(a));
  82. RAND_add(a, sizeof(a), sizeof(a));
  83. return(RAND_status() <= 0);
  84. }
  85. ],
  86. [
  87. found_crypto=1
  88. break;
  89. ], []
  90. )
  91. if test ! -z "$found_crypto" ; then
  92. break;
  93. fi
  94. done
  95. if test -z "$found_crypto" ; then
  96. AC_MSG_ERROR([Could not find working OpenSSL library, please install or check config.log])
  97. fi
  98. if test -z "$ssldir" ; then
  99. ssldir="(system)"
  100. fi
  101. ac_cv_openssldir=$ssldir
  102. ])
  103. if (test ! -z "$ac_cv_openssldir" && test "x$ac_cv_openssldir" != "x(system)") ;
  104. then
  105. dnl Need to recover ssldir - test above runs in subshell
  106. ssldir=$ac_cv_openssldir
  107. if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
  108. # Try to use $ssldir/lib if it exists, otherwise
  109. # $ssldir
  110. if test -d "$ssldir/lib" ; then
  111. LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
  112. if test ! -z "$need_dash_r" ; then
  113. LDFLAGS="-R$ssldir/lib $LDFLAGS"
  114. fi
  115. else
  116. LDFLAGS="-L$ssldir $saved_LDFLAGS"
  117. if test ! -z "$need_dash_r" ; then
  118. LDFLAGS="-R$ssldir $LDFLAGS"
  119. fi
  120. fi
  121. # Try to use $ssldir/include if it exists, otherwise
  122. # $ssldir
  123. if test -d "$ssldir/include" ; then
  124. CPPFLAGS="-I$ssldir/include $saved_CPPFLAGS"
  125. else
  126. CPPFLAGS="-I$ssldir $saved_CPPFLAGS"
  127. fi
  128. fi
  129. fi
  130. LIBS="$saved_LIBS"
  131. AC_SYS_LARGEFILE
  132. dnl The warning message here is no longer strictly accurate.
  133. 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))
  134. AC_CHECK_HEADERS(event.h, , AC_MSG_ERROR(Libevent header (event.h) not found. Tor requires libevent to build.))
  135. 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.))
  136. dnl These headers are not essential
  137. 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)
  138. 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)
  139. AC_FUNC_FSEEKO
  140. AC_CHECK_MEMBERS([struct timeval.tv_sec])
  141. dnl In case we aren't given a working stdint.h, we'll need to grow our own.
  142. dnl Watch out.
  143. AC_CHECK_SIZEOF(int8_t)
  144. AC_CHECK_SIZEOF(int16_t)
  145. AC_CHECK_SIZEOF(int32_t)
  146. AC_CHECK_SIZEOF(int64_t)
  147. AC_CHECK_SIZEOF(uint8_t)
  148. AC_CHECK_SIZEOF(uint16_t)
  149. AC_CHECK_SIZEOF(uint32_t)
  150. AC_CHECK_SIZEOF(uint64_t)
  151. AC_CHECK_SIZEOF(intptr_t)
  152. AC_CHECK_SIZEOF(uintptr_t)
  153. dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
  154. AC_CHECK_SIZEOF(char)
  155. AC_CHECK_SIZEOF(short)
  156. AC_CHECK_SIZEOF(int)
  157. AC_CHECK_SIZEOF(long)
  158. AC_CHECK_SIZEOF(long long)
  159. AC_CHECK_SIZEOF(__int64)
  160. AC_CHECK_SIZEOF(void *)
  161. AC_CHECK_SIZEOF(time_t)
  162. # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
  163. AC_CHECK_SIZEOF(cell_t)
  164. # Now, let's see about alignment requirements. On some platforms, we override
  165. # the default.
  166. case $host in
  167. ia64-*-* | arm-*-* )
  168. tor_cv_unaligned_ok=no
  169. ;;
  170. *)
  171. AC_CACHE_CHECK([whether unaligned int access is allowed], tor_cv_unaligned_ok,
  172. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  173. [[int main () { char s[] = "A\x00\x00\x00\x00\x00\x00\x00";
  174. return *(int*)(&s[1]); }]])],
  175. [tor_cv_unaligned_ok=yes],
  176. [tor_cv_unaligned_ok=no],
  177. [tor_cv_unaligned_ok=cross])])
  178. esac
  179. if test $tor_cv_unaligned_ok = yes; then
  180. AC_DEFINE([UNALIGNED_INT_ACCESS_OK], 1,
  181. [Define to 1 iff unaligned int access is allowed])
  182. fi
  183. # Now make sure that NULL can be represented as zero bytes.
  184. AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
  185. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  186. [[#include <stdlib.h>
  187. #include <string.h>
  188. #include <stdio.h>
  189. #ifdef HAVE_STDDEF_H
  190. #include <stddef.h>
  191. #endif
  192. int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
  193. return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
  194. [tor_cv_null_is_zero=yes],
  195. [tor_cv_null_is_zero=no],
  196. [tor_cv_null_is_zero=cross])])
  197. if test $tor_cv_null_is_zero = yes; then
  198. AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
  199. [Define to 1 iff memset(0) sets pointers to NULL])
  200. fi
  201. # Whether we should use the dmalloc memory allocation debugging library.
  202. AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
  203. AC_ARG_WITH(dmalloc,
  204. [ --with-dmalloc Use debug memory allocation library. ],
  205. [if [[ "$withval" = "yes" ]]; then
  206. dmalloc=1
  207. AC_MSG_RESULT(yes)
  208. else
  209. dmalloc=1
  210. AC_MSG_RESULT(no)
  211. fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
  212. )
  213. if [[ $dmalloc -eq 1 ]]; then
  214. AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
  215. AC_SEARCH_LIBS(dmalloc_malloc, [dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
  216. AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
  217. AC_DEFINE(DMALLOC_FUNC_CHECK, 1, [Enable dmalloc's malloc function check])
  218. fi
  219. # Check for gethostbyname_r in all its glorious incompatible versions.
  220. # (This logic is based on that in Python's configure.in)
  221. AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
  222. [Define this if you have any gethostbyname_r()])
  223. AC_CHECK_FUNC(gethostbyname_r, [
  224. AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
  225. OLD_CFLAGS=$CFLAGS
  226. CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
  227. AC_TRY_COMPILE([
  228. #include <netdb.h>
  229. ], [
  230. char *cp1, *cp2;
  231. struct hostent *h1, *h2;
  232. int i1, i2;
  233. (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
  234. ], [
  235. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  236. AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
  237. [Define this if gethostbyname_r takes 6 arguments])
  238. AC_MSG_RESULT(6)
  239. ], [
  240. AC_TRY_COMPILE([
  241. #include <netdb.h>
  242. ], [
  243. char *cp1, *cp2;
  244. struct hostent *h1;
  245. int i1, i2;
  246. (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
  247. ], [
  248. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  249. AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
  250. [Define this if gethostbyname_r takes 5 arguments])
  251. AC_MSG_RESULT(5)
  252. ], [
  253. AC_TRY_COMPILE([
  254. #include <netdb.h>
  255. ], [
  256. char *cp1;
  257. struct hostent *h1;
  258. struct hostent_data hd;
  259. (void) gethostbyname_r(cp1,h1,&hd);
  260. ], [
  261. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  262. AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
  263. [Define this if gethostbyname_r takes 3 arguments])
  264. AC_MSG_RESULT(3)
  265. ], [
  266. AC_MSG_RESULT(0)
  267. ])
  268. ])
  269. ])
  270. CFLAGS=$OLD_CFLAGS
  271. ])
  272. # $prefix stores the value of the --prefix command line option, or
  273. # NONE if the option wasn't set. In the case that it wasn't set, make
  274. # it be the default, so that we can use it to expand directories now.
  275. if test "x$prefix" = "xNONE"; then
  276. prefix=$ac_default_prefix
  277. fi
  278. # and similarly for $exec_prefix
  279. if test "x$exec_prefix" = "xNONE"; then
  280. exec_prefix=$prefix
  281. fi
  282. CONFDIR=`eval echo $sysconfdir/tor`
  283. AC_SUBST(CONFDIR)
  284. AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
  285. AC_DEFINE([CONFDIR], [], [tor's configuration directory])
  286. BINDIR=`eval echo $bindir`
  287. AC_SUBST(BINDIR)
  288. LOCALSTATEDIR=`eval echo $localstatedir`
  289. AC_SUBST(LOCALSTATEDIR)
  290. # Set CFLAGS _after_ all the above checks, since our warnings are stricter
  291. # than autoconf's macros like.
  292. CFLAGS="$CFLAGS -Wall -g -O2"
  293. # Add some more warnings which we use in the cvs version but not in the
  294. # released versions. (Some relevant gcc versions can't handle these.)
  295. #CFLAGS="$CFLAGS -W -Wno-unused-parameter -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls"
  296. # Add these in when you feel like fun.
  297. #CFLAGS="$CFLAGS -Wbad-function-cast -Werror -Wdeclaration-after-statement"
  298. echo "confdir: $CONFDIR"
  299. 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)
  300. if test -x /usr/bin/perl && test -x ./contrib/updateVersions.pl ; then
  301. ./contrib/updateVersions.pl
  302. fi