acinclude.m4 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. AC_DEFUN([TOR_EXTEND_CODEPATH],
  7. [
  8. if test -d "$1/lib"; then
  9. LDFLAGS="-L$1/lib $LDFLAGS"
  10. else
  11. LDFLAGS="-L$1 $LDFLAGS"
  12. fi
  13. if test -d "$1/include"; then
  14. CPPFLAGS="-I$1/include $CPPFLAGS"
  15. else
  16. CPPFLAGS="-I$1 $CPPFLAGS"
  17. fi
  18. ])
  19. dnl Look for a library, and its associated includes, and how to link
  20. dnl against it.
  21. dnl
  22. dnl TOR_SEARCH_LIBRARY(1:libname, 2:withlocation, 3:linkargs, 4:headers,
  23. dnl 5:prototype,
  24. dnl 6:code, 7:optionname, 8:searchextra)
  25. AC_DEFUN([TOR_SEARCH_LIBRARY], [
  26. tor_saved_LIBS="$LIBS"
  27. tor_saved_LDFLAGS="$LDFLAGS"
  28. tor_saved_CPPFLAGS="$CPPFLAGS"
  29. AC_CACHE_CHECK([for $1 directory], tor_cv_library_$1_dir, [
  30. tor_$1_dir_found=no
  31. tor_$1_any_linkable=no
  32. for tor_trydir in "$2" "(system)" "$prefix" /usr/local /usr/pkg $8; do
  33. LDFLAGS="$tor_saved_LDFLAGS"
  34. LIBS="$tor_saved_LIBS $3"
  35. CPPFLAGS="$tor_saved_CPPFLAGS"
  36. if test -z "$tor_trydir" ; then
  37. continue;
  38. fi
  39. # Skip the directory if it isn't there.
  40. if test ! -d "$tor_trydir" -a "$tor_trydir" != "(system)"; then
  41. continue;
  42. fi
  43. # If this isn't blank, try adding the directory (or appropriate
  44. # include/libs subdirectories) to the command line.
  45. if test "$tor_trydir" != "(system)"; then
  46. TOR_EXTEND_CODEPATH($tor_trydir)
  47. fi
  48. # Can we link against (but not necessarily run, or find the headers for)
  49. # the binary?
  50. AC_LINK_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
  51. [linkable=yes], [linkable=no])
  52. if test $linkable = yes; then
  53. tor_$1_any_linkable=yes
  54. # Okay, we can link against it. Can we find the headers?
  55. AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$4], [$6]),
  56. [buildable=yes], [buildable=no])
  57. if test $buildable = yes; then
  58. tor_cv_library_$1_dir=$tor_trydir
  59. tor_$1_dir_found=yes
  60. break
  61. fi
  62. fi
  63. done
  64. if test $tor_$1_dir_found = no; then
  65. if test $tor_$1_any_linkable = no ; then
  66. AC_MSG_ERROR([Could not find a linkable $1. You can specify an explicit path using $7])
  67. else
  68. 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.])
  69. fi
  70. fi
  71. LDFLAGS="$tor_saved_LDFLAGS"
  72. LIBS="$tor_saved_LIBS"
  73. CPPFLAGS="$tor_saved_CPPFLAGS"
  74. ]) dnl end cache check
  75. LIBS="$LIBS $3"
  76. if test $tor_cv_library_$1_dir != "(system)"; then
  77. TOR_EXTEND_CODEPATH($tor_cv_library_$1_dir)
  78. fi
  79. if test -z "$CROSS_COMPILE"; then
  80. AC_CACHE_CHECK([whether we need extra options to link $1],
  81. tor_cv_library_$1_linker_option, [
  82. tor_saved_LDFLAGS="$LDFLAGS"
  83. runs=no
  84. linked_with=nothing
  85. if test -d "$tor_cv_library_$1_dir/lib"; then
  86. tor_trydir="$tor_cv_library_$1_dir/lib"
  87. else
  88. tor_trydir="$tor_cv_library_$1_dir"
  89. fi
  90. for tor_tryextra in "(none)" "-Wl,-R$tor_trydir" "-R$tor_trydir" \
  91. "-Wl,-rpath,$tor_trydir" ; do
  92. if test "$tor_tryextra" = "(none)"; then
  93. LDFLAGS="$tor_saved_LDFLAGS"
  94. else
  95. LDFLAGS="$tor_tryextra $tor_saved_LDFLAGS"
  96. fi
  97. AC_RUN_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
  98. [runnable=yes], [runnable=no])
  99. if test "$runnable" = yes; then
  100. tor_cv_library_$1_linker_option=$tor_tryextra
  101. break
  102. fi
  103. done
  104. if test "$runnable" = no; then
  105. 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}])
  106. fi
  107. LDFLAGS="$tor_saved_LDFLAGS"
  108. ]) dnl end cache check check for extra options.
  109. if test "$tor_cv_library_$1_linker_option" != "(none)" ; then
  110. LDFLAGS="$tor_cv_library_$1_linker_option $LDFLAGS"
  111. fi
  112. fi # cross-compile
  113. ]) dnl end defun