acinclude.m4 9.1 KB

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