acinclude.m4 5.8 KB

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