configure.in 13 KB

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