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-2013, The Tor Project, Inc.
6 dnl See LICENSE for licensing information
8 AC_DEFUN([TOR_EXTEND_CODEPATH],
10 if test -d "$1/lib"; then
11 LDFLAGS="-L$1/lib $LDFLAGS"
13 LDFLAGS="-L$1 $LDFLAGS"
15 if test -d "$1/include"; then
16 CPPFLAGS="-I$1/include $CPPFLAGS"
18 CPPFLAGS="-I$1 $CPPFLAGS"
22 AC_DEFUN([TOR_DEFINE_CODEPATH],
24 if test x$1 = "x(system)"; then
28 if test -d "$1/lib"; then
29 TOR_LDFLAGS_$2="-L$1/lib"
30 TOR_LIBDIR_$2="$1/lib"
35 if test -d "$1/include"; then
36 TOR_CPPFLAGS_$2="-I$1/include"
38 TOR_CPPFLAGS_$2="-I$1"
41 AC_SUBST(TOR_CPPFLAGS_$2)
42 AC_SUBST(TOR_LDFLAGS_$2)
46 AC_DEFUN([TOR_CHECK_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_TRY_COMPILE([], [return 0;],
52 [AS_VAR_SET(VAR,yes)],
54 CFLAGS="$tor_saved_CFLAGS"
56 if test x$VAR = xyes; then
65 AC_DEFUN([TOR_CHECK_LDFLAGS], [
66 AS_VAR_PUSHDEF([VAR],[tor_cv_ldflags_$1])
67 AC_CACHE_CHECK([whether the linker accepts $1], VAR, [
68 tor_saved_CFLAGS="$CFLAGS"
69 tor_saved_LDFLAGS="$LDFLAGS"
70 tor_saved_LIBS="$LIBS"
71 CFLAGS="$CFLAGS -pedantic -Werror"
72 LDFLAGS="$LDFLAGS $2 $1"
74 AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>], [fputs("", stdout)])],
75 [AS_VAR_SET(VAR,yes)],
77 [AC_TRY_LINK([], [return 0;],
78 [AS_VAR_SET(VAR,yes)],
79 [AS_VAR_SET(VAR,no)])])
80 CFLAGS="$tor_saved_CFLAGS"
81 LDFLAGS="$tor_saved_LDFLAGS"
82 LIBS="$tor_saved_LIBS"
84 if test x$VAR = xyes; then
91 AC_DEFUN([TOR_WARN_MISSING_LIB], [
93 if test x$2 = xdevpkg; then
96 if test -f /etc/debian_version && test x"$tor_$1_$2_debian" != x; then
97 AC_WARN([On Debian, you can install$h $1 using "apt-get install $tor_$1_$2_debian"])
98 if test x"$tor_$1_$2_debian" != x"$tor_$1_devpkg_debian"; then
99 AC_WARN([ You will probably need $tor_$1_devpkg_debian too.])
102 if test -f /etc/fedora-release && test x"$tor_$1_$2_redhat" != x; then
103 AC_WARN([On Fedora Core, you can install$h $1 using "yum install $tor_$1_$2_redhat"])
104 if test x"$tor_$1_$2_redhat" != x"$tor_$1_devpkg_redhat"; then
105 AC_WARN([ You will probably need to install $tor_$1_devpkg_redhat too.])
108 if test -f /etc/redhat-release && test x"$tor_$1_$2_redhat" != x; then
109 AC_WARN([On most Redhat-based systems, you can get$h $1 by installing the $tor_$1_$2_redhat" RPM package])
110 if test x"$tor_$1_$2_redhat" != x"$tor_$1_devpkg_redhat"; then
111 AC_WARN([ You will probably need to install $tor_$1_devpkg_redhat too.])
117 dnl Look for a library, and its associated includes, and how to link
120 dnl TOR_SEARCH_LIBRARY(1:libname, 2:IGNORED, 3:linkargs, 4:headers,
122 dnl 6:code, 7:IGNORED, 8:searchextra)
124 dnl Special variables:
125 dnl ALT_{libname}_WITHVAL -- another possible value for --with-$1-dir.
126 dnl Used to support renaming --with-ssl-dir to --with-openssl-dir
128 AC_DEFUN([TOR_SEARCH_LIBRARY], [
131 [ --with-$1-dir=PATH Specify path to $1 installation ],
133 if test x$withval != xno ; then
137 if test "x$try$1dir" = x && test "x$ALT_$1_WITHVAL" != x ; then
138 try$1dir="$ALT_$1_WITHVAL"
141 tor_saved_LIBS="$LIBS"
142 tor_saved_LDFLAGS="$LDFLAGS"
143 tor_saved_CPPFLAGS="$CPPFLAGS"
144 AC_CACHE_CHECK([for $1 directory], tor_cv_library_$1_dir, [
146 tor_$1_any_linkable=no
148 for tor_trydir in "$try$1dir" "(system)" "$prefix" /usr/local /usr/pkg $8; do
149 LDFLAGS="$tor_saved_LDFLAGS"
150 LIBS="$tor_saved_LIBS $3"
151 CPPFLAGS="$tor_saved_CPPFLAGS"
153 if test -z "$tor_trydir" ; then
157 # Skip the directory if it isn't there.
158 if test ! -d "$tor_trydir" && test "$tor_trydir" != "(system)"; then
162 # If this isn't blank, try adding the directory (or appropriate
163 # include/libs subdirectories) to the command line.
164 if test "$tor_trydir" != "(system)"; then
165 TOR_EXTEND_CODEPATH($tor_trydir)
168 # Can we link against (but not necessarily run, or find the headers for)
170 AC_LINK_IFELSE([AC_LANG_PROGRAM([$5], [$6])],
171 [linkable=yes], [linkable=no])
173 if test "$linkable" = yes; then
174 tor_$1_any_linkable=yes
175 # Okay, we can link against it. Can we find the headers?
176 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$4], [$6])],
177 [buildable=yes], [buildable=no])
178 if test "$buildable" = yes; then
179 tor_cv_library_$1_dir=$tor_trydir
186 if test "$tor_$1_dir_found" = no; then
187 if test "$tor_$1_any_linkable" = no ; then
188 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])
189 TOR_WARN_MISSING_LIB($1, pkg)
190 AC_MSG_ERROR([Missing libraries; unable to proceed.])
192 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.])
193 TOR_WARN_MISSING_LIB($1, devpkg)
194 AC_MSG_ERROR([Missing headers; unable to proceed.])
198 LDFLAGS="$tor_saved_LDFLAGS"
199 LIBS="$tor_saved_LIBS"
200 CPPFLAGS="$tor_saved_CPPFLAGS"
201 ]) dnl end cache check
204 if test "$tor_cv_library_$1_dir" != "(system)"; then
205 TOR_EXTEND_CODEPATH($tor_cv_library_$1_dir)
208 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"
216 if test -d "$tor_cv_library_$1_dir/lib"; then
217 tor_trydir="$tor_cv_library_$1_dir/lib"
219 tor_trydir="$tor_cv_library_$1_dir"
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"
226 LDFLAGS="$tor_tryextra $orig_LDFLAGS"
228 AC_RUN_IFELSE([AC_LANG_PROGRAM([$5], [$6])],
229 [runnable=yes], [runnable=no])
230 if test "$runnable" = yes; then
231 tor_cv_library_$1_linker_option=$tor_tryextra
236 if test "$runnable" = no; then
237 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}])
239 LDFLAGS="$orig_LDFLAGS"
240 ]) dnl end cache check check for extra options.
242 if test "$tor_cv_library_$1_linker_option" != "(none)" ; then
243 TOR_LDFLAGS_$1="$TOR_LDFLAGS_$1 $tor_cv_library_$1_linker_option"
247 LIBS="$tor_saved_LIBS"
248 LDFLAGS="$tor_saved_LDFLAGS"
249 CPPFLAGS="$tor_saved_CPPFLAGS"
253 dnl Check whether the prototype for a function is present or missing.
254 dnl Apple has a nasty habit of putting functions in their libraries (so that
255 dnl AC_CHECK_FUNCS passes) but not actually declaring them in the headers.
257 dnl TOR_CHECK_PROTYPE(1:functionname, 2:macroname, 2: includes)
258 AC_DEFUN([TOR_CHECK_PROTOTYPE], [
259 AC_CACHE_CHECK([for declaration of $1], tor_cv_$1_declared, [
260 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$3],[void *ptr= $1 ;])],
261 tor_cv_$1_declared=yes,tor_cv_$1_declared=no)])
262 if test x$tor_cv_$1_declared != xno ; then
264 [Defined if the prototype for $1 seems to be present.])