acinclude.m4 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. dnl $Id$
  2. dnl Helper macros for Tor configure.in
  3. dnl Copyright (c) 2001-2004, Roger Dingledine
  4. dnl Copyright (c) 2004-2007, Roger Dingledine, Nick Mathewson
  5. dnl See LICENSE for licensing information
  6. dnl TODO
  7. dnl - Stop requiring gethostbyname_r entirely when we're building with
  8. dnl eventdns?
  9. dnl - Remove redundant event.h check.
  10. dnl - Make the "no longe strictly accurate" message accurate.
  11. dnl - Tell the user what -dev package to install based on OS.
  12. dnl - Detect correct version of library.
  13. dnl - After merge:
  14. dnl Run autoupdate
  15. AC_DEFUN([TOR_EXTEND_CODEPATH],
  16. [
  17. if test -d "$1/lib"; then
  18. LDFLAGS="-L$1/lib $LDFLAGS"
  19. else
  20. LDFLAGS="-L$1 $LDFLAGS"
  21. fi
  22. if test -d "$1/include"; then
  23. CPPFLAGS="-I$1/include $CPPFLAGS"
  24. else
  25. CPPFLAGS="-I$1 $CPPFLAGS"
  26. fi
  27. ])
  28. dnl Look for a library, and its associated includes, and how to link
  29. dnl against it.
  30. dnl
  31. dnl TOR_SEARCH_LIBRARY(libname, withlocation, linkargs, headers, prototype,
  32. dnl code, optionname, searchextra)
  33. AC_DEFUN([TOR_SEARCH_LIBRARY], [
  34. tor_saved_LIBS="$LIBS"
  35. tor_saved_LDFLAGS="$LDFLAGS"
  36. tor_saved_CPPFLAGS="$CPPFLAGS"
  37. AC_CACHE_CHECK([for $1 directory], tor_cv_library_$1_dir, [
  38. tor_$1_dir_found=no
  39. tor_$1_any_linkable=no
  40. for tor_trydir in "$2" "(system)" "$prefix" /usr/local /usr/pkg $8; do
  41. LDFLAGS="$tor_saved_LDFLAGS"
  42. LIBS="$tor_saved_LIBS $3"
  43. CPPFLAGS="$tor_saved_CPPFLAGS"
  44. if test -z "$tor_trydir" ; then
  45. continue;
  46. fi
  47. # Skip the directory if it isn't there.
  48. if test ! -d "$tor_trydir" -a "$tor_trydir" != "(system)"; then
  49. continue;
  50. fi
  51. # If this isn't blank, try adding the directory (or appropriate
  52. # include/libs subdirectories) to the command line.
  53. if test "$tor_trydir" != "(system)"; then
  54. TOR_EXTEND_CODEPATH($tor_trydir)
  55. fi
  56. # Can we link against (but not necessarily compile) the binary?
  57. AC_LINK_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
  58. [linkable=yes], [linkable=no])
  59. if test $linkable = yes; then
  60. tor_$1_any_linkable=yes
  61. AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$4], [$6]),
  62. [buildable=yes], [buildable=no])
  63. if test $buildable = yes; then
  64. tor_cv_library_$1_dir=$tor_trydir
  65. tor_$1_dir_found=yes
  66. break
  67. fi
  68. fi
  69. done
  70. if test $tor_$1_dir_found = no; then
  71. if test $tor_$1_any_linkable = no ; then
  72. AC_MSG_ERROR([Could not find a linkable $1. You can specify an explicit path using $7])
  73. else
  74. AC_MSG_ERROR([We found the libraries for $1, but we could not find the C header files. You may need to install a devel package.])
  75. fi
  76. fi
  77. LDFLAGS="$tor_saved_LDFLAGS"
  78. LIBS="$tor_saved_LIBS $3"
  79. CPPFLAGS="$tor_saved_CPPFLAGS"
  80. ]) dnl end cache check
  81. LIBS="$LIBS $3"
  82. if test $tor_cv_library_$1_dir != "(system)"; then
  83. TOR_EXTEND_CODEPATH($tor_cv_library_$1_dir)
  84. fi
  85. if test -z "$CROSS_COMPILE"; then
  86. AC_CACHE_CHECK([whether we need extra options to link $1],
  87. tor_cv_library_$1_linker_option, [
  88. tor_saved_LDFLAGS="$LDFLAGS"
  89. tor_trydir="$tor_cv_library_$1_dir"
  90. runs=no
  91. linked_with=nothing
  92. for tor_tryextra in "(none)" "-Wl,-R$tor_trydir" "-R$tor_trydir" \
  93. "-Wl,-rpath,$le_libdir" ; do
  94. if test "$tor_tryextra" = "(none)"; then
  95. LDFLAGS="$saved_LDFLAGS"
  96. else
  97. LDFLAGS="$tor_tryextra $saved_LDFLAGS"
  98. fi
  99. AC_RUN_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
  100. [runnable=yes], [runnable=no])
  101. if test "$runnable" = yes; then
  102. tor_cv_library_$1_linker_option=$tor_tryextra
  103. break
  104. fi
  105. done
  106. if test "$runnable" = no; then
  107. AC_MSG_ERROR([Found linkable $1 in $tor_cv_library_$1_dir, but it does not seem to run, even with -R. Maybe specify another using $7}])
  108. fi
  109. ]) dnl check for extra options.
  110. if test "$tor_cv_library_$1_linker_option" != "(none)" ; then
  111. LDFLAGS="$tor_cv_library_$1_linker_option $LDFLAGS"
  112. fi
  113. fi # cross-compile
  114. ]) dnl end defun
  115. #XXXX Check for right version
  116. #XXXX accept list of search paths as options