acinclude.m4 8.0 KB

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