acinclude.m4 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 1:libname
  20. AC_DEFUN([TOR_WARN_MISSING_LIB], [
  21. h=""
  22. if test x$2 = xdevpkg; then
  23. h=" headers for"
  24. fi
  25. if test -f /etc/debian_version -a x"$tor_$1_$2_debian" != x; then
  26. AC_WARN([On Debian, you can install$h $1 using "apt-get install $tor_$1_$2_debian"])
  27. fi
  28. if test -f /etc/fedora-release -a x"$tor_$1_$2_redhat" != x; then
  29. AC_WARN([On Fedora Core, you can install$h $1 using "yum install $tor_$1_$2_redhat"])
  30. else
  31. if test -f /etc/redhat-release -a x"$tor_$1_$2_redhat" != x; then
  32. AC_WARN([On most Redhat-based systems, you can get$h $1 by installing the $tor_$1_$2_redhat" RPM package])
  33. fi
  34. fi
  35. ])
  36. dnl Look for a library, and its associated includes, and how to link
  37. dnl against it.
  38. dnl
  39. dnl TOR_SEARCH_LIBRARY(1:libname, 2:IGNORED, 3:linkargs, 4:headers,
  40. dnl 5:prototype,
  41. dnl 6:code, 7:optionname, 8:searchextra)
  42. AC_DEFUN([TOR_SEARCH_LIBRARY], [
  43. try$1dir=""
  44. AC_ARG_WITH($1-dir,
  45. [ --with-$1-dir=PATH Specify path to $1 installation ],
  46. [
  47. if test x$withval != xno ; then
  48. try$1dir="$withval"
  49. fi
  50. ])
  51. tor_saved_LIBS="$LIBS"
  52. tor_saved_LDFLAGS="$LDFLAGS"
  53. tor_saved_CPPFLAGS="$CPPFLAGS"
  54. AC_CACHE_CHECK([for $1 directory], tor_cv_library_$1_dir, [
  55. tor_$1_dir_found=no
  56. tor_$1_any_linkable=no
  57. for tor_trydir in "$try$1dir" "(system)" "$prefix" /usr/local /usr/pkg $8; do
  58. LDFLAGS="$tor_saved_LDFLAGS"
  59. LIBS="$tor_saved_LIBS $3"
  60. CPPFLAGS="$tor_saved_CPPFLAGS"
  61. if test -z "$tor_trydir" ; then
  62. continue;
  63. fi
  64. # Skip the directory if it isn't there.
  65. if test ! -d "$tor_trydir" -a "$tor_trydir" != "(system)"; then
  66. continue;
  67. fi
  68. # If this isn't blank, try adding the directory (or appropriate
  69. # include/libs subdirectories) to the command line.
  70. if test "$tor_trydir" != "(system)"; then
  71. TOR_EXTEND_CODEPATH($tor_trydir)
  72. fi
  73. # Can we link against (but not necessarily run, or find the headers for)
  74. # the binary?
  75. AC_LINK_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
  76. [linkable=yes], [linkable=no])
  77. if test $linkable = yes; then
  78. tor_$1_any_linkable=yes
  79. # Okay, we can link against it. Can we find the headers?
  80. AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$4], [$6]),
  81. [buildable=yes], [buildable=no])
  82. if test $buildable = yes; then
  83. tor_cv_library_$1_dir=$tor_trydir
  84. tor_$1_dir_found=yes
  85. break
  86. fi
  87. fi
  88. done
  89. if test $tor_$1_dir_found = no; then
  90. if test $tor_$1_any_linkable = no ; then
  91. AC_MSG_WARN([Could not find a linkable $1. If you have it installed somewhere unusal, you can specify an explicit path using $7])
  92. TOR_WARN_MISSING_LIB($1, pkg)
  93. AC_MSG_ERROR([Missing libraries; unable to proceed.])
  94. else
  95. AC_MSG_WARN([We found the libraries for $1, but we could not find the C header files. You may need to install a devel package.])
  96. TOR_WARN_MISSING_LIB($1, devpkg)
  97. AC_MSG_ERROR([Missing headers; unable to proceed.])
  98. fi
  99. fi
  100. LDFLAGS="$tor_saved_LDFLAGS"
  101. LIBS="$tor_saved_LIBS"
  102. CPPFLAGS="$tor_saved_CPPFLAGS"
  103. ]) dnl end cache check
  104. LIBS="$LIBS $3"
  105. if test $tor_cv_library_$1_dir != "(system)"; then
  106. TOR_EXTEND_CODEPATH($tor_cv_library_$1_dir)
  107. fi
  108. if test -z "$CROSS_COMPILE"; then
  109. AC_CACHE_CHECK([whether we need extra options to link $1],
  110. tor_cv_library_$1_linker_option, [
  111. tor_saved_LDFLAGS="$LDFLAGS"
  112. runs=no
  113. linked_with=nothing
  114. if test -d "$tor_cv_library_$1_dir/lib"; then
  115. tor_trydir="$tor_cv_library_$1_dir/lib"
  116. else
  117. tor_trydir="$tor_cv_library_$1_dir"
  118. fi
  119. for tor_tryextra in "(none)" "-Wl,-R$tor_trydir" "-R$tor_trydir" \
  120. "-Wl,-rpath,$tor_trydir" ; do
  121. if test "$tor_tryextra" = "(none)"; then
  122. LDFLAGS="$tor_saved_LDFLAGS"
  123. else
  124. LDFLAGS="$tor_tryextra $tor_saved_LDFLAGS"
  125. fi
  126. AC_RUN_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
  127. [runnable=yes], [runnable=no])
  128. if test "$runnable" = yes; then
  129. tor_cv_library_$1_linker_option=$tor_tryextra
  130. break
  131. fi
  132. done
  133. if test "$runnable" = no; then
  134. 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}])
  135. fi
  136. LDFLAGS="$tor_saved_LDFLAGS"
  137. ]) dnl end cache check check for extra options.
  138. if test "$tor_cv_library_$1_linker_option" != "(none)" ; then
  139. LDFLAGS="$tor_cv_library_$1_linker_option $LDFLAGS"
  140. fi
  141. fi # cross-compile
  142. ]) dnl end defun