acinclude.m4 6.5 KB

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