configure.in 12 KB

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