acinclude.m4 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. dnl $Id$
  2. dnl Helper macros for Tor configure.in
  3. dnl Copyright (c) 2001-2004, Roger Dingledine
  4. dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
  5. dnl Copyright (c) 2007-2008, Roger Dingledine, Nick Mathewson
  6. dnl See LICENSE for licensing information
  7. AC_DEFUN([TOR_EXTEND_CODEPATH],
  8. [
  9. if test -d "$1/lib"; then
  10. LDFLAGS="-L$1/lib $LDFLAGS"
  11. else
  12. LDFLAGS="-L$1 $LDFLAGS"
  13. fi
  14. if test -d "$1/include"; then
  15. CPPFLAGS="-I$1/include $CPPFLAGS"
  16. else
  17. CPPFLAGS="-I$1 $CPPFLAGS"
  18. fi
  19. ])
  20. AC_DEFUN([TOR_DEFINE_CODEPATH],
  21. [
  22. if test x$1 = "x(system)"; then
  23. TOR_LDFLAGS_$2=""
  24. TOR_CPPFLAGS_$2=""
  25. else
  26. if test -d "$1/lib"; then
  27. TOR_LDFLAGS_$2="-L$1/lib"
  28. TOR_LIBDIR_$2="$1/lib"
  29. else
  30. TOR_LDFLAGS_$2="-L$1"
  31. TOR_LIBDIR_$2="$1"
  32. fi
  33. if test -d "$1/include"; then
  34. TOR_CPPFLAGS_$2="-I$1/include"
  35. else
  36. TOR_CPPFLAGS_$2="-I$1"
  37. fi
  38. fi
  39. AC_SUBST(TOR_CPPFLAGS_$2)
  40. AC_SUBST(TOR_LDFLAGS_$2)
  41. ])
  42. dnl 1:libname
  43. AC_DEFUN([TOR_WARN_MISSING_LIB], [
  44. h=""
  45. if test x$2 = xdevpkg; then
  46. h=" headers for"
  47. fi
  48. if test -f /etc/debian_version && test x"$tor_$1_$2_debian" != x; then
  49. AC_WARN([On Debian, you can install$h $1 using "apt-get install $tor_$1_$2_debian"])
  50. if test x"$tor_$1_$2_debian" != x"$tor_$1_devpkg_debian"; then
  51. AC_WARN([ You will probably need $tor_$1_devpkg_debian too.])
  52. fi
  53. fi
  54. if test -f /etc/fedora-release && test x"$tor_$1_$2_redhat" != x; then
  55. AC_WARN([On Fedora Core, you can install$h $1 using "yum install $tor_$1_$2_redhat"])
  56. if test x"$tor_$1_$2_redhat" != x"$tor_$1_devpkg_redhat"; then
  57. AC_WARN([ You will probably need to install $tor_$1_devpkg_redhat too.])
  58. fi
  59. else
  60. if test -f /etc/redhat-release && test x"$tor_$1_$2_redhat" != x; then
  61. AC_WARN([On most Redhat-based systems, you can get$h $1 by installing the $tor_$1_$2_redhat" RPM package])
  62. if test x"$tor_$1_$2_redhat" != x"$tor_$1_devpkg_redhat"; then
  63. AC_WARN([ You will probably need to install $tor_$1_devpkg_redhat too.])
  64. fi
  65. fi
  66. fi
  67. ])
  68. dnl Look for a library, and its associated includes, and how to link
  69. dnl against it.
  70. dnl
  71. dnl TOR_SEARCH_LIBRARY(1:libname, 2:IGNORED, 3:linkargs, 4:headers,
  72. dnl 5:prototype,
  73. dnl 6:code, 7:IGNORED, 8:searchextra)
  74. dnl
  75. dnl Special variables:
  76. dnl ALT_{libname}_WITHVAL -- another possible value for --with-$1-dir.
  77. dnl Used to support renaming --with-ssl-dir to --with-openssl-dir
  78. dnl
  79. AC_DEFUN([TOR_SEARCH_LIBRARY], [
  80. try$1dir=""
  81. AC_ARG_WITH($1-dir,
  82. [ --with-$1-dir=PATH Specify path to $1 installation ],
  83. [
  84. if test x$withval != xno ; then
  85. try$1dir="$withval"
  86. fi
  87. ])
  88. if test "x$try$1dir" = x && test "x$ALT_$1_WITHVAL" != x ; then
  89. try$1dir="$ALT_$1_WITHVAL"
  90. fi
  91. tor_saved_LIBS="$LIBS"
  92. tor_saved_LDFLAGS="$LDFLAGS"
  93. tor_saved_CPPFLAGS="$CPPFLAGS"
  94. AC_CACHE_CHECK([for $1 directory], tor_cv_library_$1_dir, [
  95. tor_$1_dir_found=no
  96. tor_$1_any_linkable=no
  97. for tor_trydir in "$try$1dir" "(system)" "$prefix" /usr/local /usr/pkg $8; do
  98. LDFLAGS="$tor_saved_LDFLAGS"
  99. LIBS="$tor_saved_LIBS $3"
  100. CPPFLAGS="$tor_saved_CPPFLAGS"
  101. if test -z "$tor_trydir" ; then
  102. continue;
  103. fi
  104. # Skip the directory if it isn't there.
  105. if test ! -d "$tor_trydir" && test "$tor_trydir" != "(system)"; then
  106. continue;
  107. fi
  108. # If this isn't blank, try adding the directory (or appropriate
  109. # include/libs subdirectories) to the command line.
  110. if test "$tor_trydir" != "(system)"; then
  111. TOR_EXTEND_CODEPATH($tor_trydir)
  112. fi
  113. # Can we link against (but not necessarily run, or find the headers for)
  114. # the binary?
  115. AC_LINK_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
  116. [linkable=yes], [linkable=no])
  117. if test "$linkable" = yes; then
  118. tor_$1_any_linkable=yes
  119. # Okay, we can link against it. Can we find the headers?
  120. AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$4], [$6]),
  121. [buildable=yes], [buildable=no])
  122. if test "$buildable" = yes; then
  123. tor_cv_library_$1_dir=$tor_trydir
  124. tor_$1_dir_found=yes
  125. break
  126. fi
  127. fi
  128. done
  129. if test "$tor_$1_dir_found" = no; then
  130. if test "$tor_$1_any_linkable" = no ; then
  131. AC_MSG_WARN([Could not find a linkable $1. If you have it installed somewhere unusual, you can specify an explicit path using --with-$1-dir])
  132. TOR_WARN_MISSING_LIB($1, pkg)
  133. AC_MSG_ERROR([Missing libraries; unable to proceed.])
  134. else
  135. 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.])
  136. TOR_WARN_MISSING_LIB($1, devpkg)
  137. AC_MSG_ERROR([Missing headers; unable to proceed.])
  138. fi
  139. fi
  140. LDFLAGS="$tor_saved_LDFLAGS"
  141. LIBS="$tor_saved_LIBS"
  142. CPPFLAGS="$tor_saved_CPPFLAGS"
  143. ]) dnl end cache check
  144. LIBS="$LIBS $3"
  145. if test "$tor_cv_library_$1_dir" != "(system)"; then
  146. TOR_EXTEND_CODEPATH($tor_cv_library_$1_dir)
  147. fi
  148. TOR_DEFINE_CODEPATH($tor_cv_library_$1_dir, $1)
  149. if test "$cross_compiling" != yes; then
  150. AC_CACHE_CHECK([whether we need extra options to link $1],
  151. tor_cv_library_$1_linker_option, [
  152. orig_LDFLAGS="$LDFLAGS"
  153. runs=no
  154. linked_with=nothing
  155. if test -d "$tor_cv_library_$1_dir/lib"; then
  156. tor_trydir="$tor_cv_library_$1_dir/lib"
  157. else
  158. tor_trydir="$tor_cv_library_$1_dir"
  159. fi
  160. for tor_tryextra in "(none)" "-Wl,-R$tor_trydir" "-R$tor_trydir" \
  161. "-Wl,-rpath,$tor_trydir" ; do
  162. if test "$tor_tryextra" = "(none)"; then
  163. LDFLAGS="$orig_LDFLAGS"
  164. else
  165. LDFLAGS="$tor_tryextra $orig_LDFLAGS"
  166. fi
  167. AC_RUN_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
  168. [runnable=yes], [runnable=no])
  169. if test "$runnable" = yes; then
  170. tor_cv_library_$1_linker_option=$tor_tryextra
  171. break
  172. fi
  173. done
  174. if test "$runnable" = no; then
  175. 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 --with-$1-dir}])
  176. fi
  177. LDFLAGS="$orig_LDFLAGS"
  178. ]) dnl end cache check check for extra options.
  179. if test "$tor_cv_library_$1_linker_option" != "(none)" ; then
  180. TOR_LDFLAGS_$1="$TOR_LDFLAGS_$1 $tor_cv_library_$1_linker_option"
  181. fi
  182. fi # cross-compile
  183. LIBS="$tor_saved_LIBS"
  184. LDFLAGS="$tor_saved_LDFLAGS"
  185. CPPFLAGS="$tor_saved_CPPFLAGS"
  186. ]) dnl end defun
  187. dnl Check whether the prototype for a function is present or missing.
  188. dnl Apple has a nasty habit of putting functions in their libraries (so that
  189. dnl AC_CHECK_FUNCS passes) but not actually declaring them in the headers.
  190. dnl
  191. dnl TOR_CHECK_PROTYPE(1:functionname, 2:macroname, 2: includes)
  192. AC_DEFUN([TOR_CHECK_PROTOTYPE], [
  193. AC_CACHE_CHECK([for declaration of $1], tor_cv_$1_declared, [
  194. AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$3],[void *ptr= $1 ;]),
  195. tor_cv_$1_declared=yes,tor_cv_$1_declared=no)])
  196. if test x$tor_cv_$1_declared != xno ; then
  197. AC_DEFINE($2, 1,
  198. [Defined if the prototype for $1 seems to be present.])
  199. fi
  200. ])