acinclude.m4 8.2 KB

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