acinclude.m4 3.6 KB

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