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
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"
33 if test -d "$1/include"; then
34 TOR_CPPFLAGS_$2="-I$1/include"
36 TOR_CPPFLAGS_$2="-I$1"
39 AC_SUBST(TOR_CPPFLAGS_$2)
40 AC_SUBST(TOR_LDFLAGS_$2)
44 AC_DEFUN([TOR_WARN_MISSING_LIB], [
46 if test x$2 = xdevpkg; then
49 if test -f /etc/debian_version && test x"$tor_$1_$2_debian" != x; then
50 AC_WARN([On Debian, you can install$h $1 using "apt-get install $tor_$1_$2_debian"])
51 if test x"$tor_$1_$2_debian" != x"$tor_$1_devpkg_debian"; then
52 AC_WARN([ You will probably need $tor_$1_devpkg_debian too.])
55 if test -f /etc/fedora-release && test x"$tor_$1_$2_redhat" != x; then
56 AC_WARN([On Fedora Core, you can install$h $1 using "yum install $tor_$1_$2_redhat"])
57 if test x"$tor_$1_$2_redhat" != x"$tor_$1_devpkg_redhat"; then
58 AC_WARN([ You will probably need to install $tor_$1_devpkg_redhat too.])
61 if test -f /etc/redhat-release && test x"$tor_$1_$2_redhat" != x; then
62 AC_WARN([On most Redhat-based systems, you can get$h $1 by installing the $tor_$1_$2_redhat" RPM package])
63 if test x"$tor_$1_$2_redhat" != x"$tor_$1_devpkg_redhat"; then
64 AC_WARN([ You will probably need to install $tor_$1_devpkg_redhat too.])
70 dnl Look for a library, and its associated includes, and how to link
73 dnl TOR_SEARCH_LIBRARY(1:libname, 2:IGNORED, 3:linkargs, 4:headers,
75 dnl 6:code, 7:optionname, 8:searchextra)
76 AC_DEFUN([TOR_SEARCH_LIBRARY], [
79 [ --with-$1-dir=PATH Specify path to $1 installation ],
81 if test x$withval != xno ; then
85 tor_saved_LIBS="$LIBS"
86 tor_saved_LDFLAGS="$LDFLAGS"
87 tor_saved_CPPFLAGS="$CPPFLAGS"
88 AC_CACHE_CHECK([for $1 directory], tor_cv_library_$1_dir, [
90 tor_$1_any_linkable=no
92 for tor_trydir in "$try$1dir" "(system)" "$prefix" /usr/local /usr/pkg $8; do
93 LDFLAGS="$tor_saved_LDFLAGS"
94 LIBS="$tor_saved_LIBS $3"
95 CPPFLAGS="$tor_saved_CPPFLAGS"
97 if test -z "$tor_trydir" ; then
101 # Skip the directory if it isn't there.
102 if test ! -d "$tor_trydir" && test "$tor_trydir" != "(system)"; then
106 # If this isn't blank, try adding the directory (or appropriate
107 # include/libs subdirectories) to the command line.
108 if test "$tor_trydir" != "(system)"; then
109 TOR_EXTEND_CODEPATH($tor_trydir)
112 # Can we link against (but not necessarily run, or find the headers for)
114 AC_LINK_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
115 [linkable=yes], [linkable=no])
117 if test "$linkable" = yes; then
118 tor_$1_any_linkable=yes
119 # Okay, we can link against it. Can we find the headers?
120 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$4], [$6]),
121 [buildable=yes], [buildable=no])
122 if test "$buildable" = yes; then
123 tor_cv_library_$1_dir=$tor_trydir
130 if test "$tor_$1_dir_found" = no; then
131 if test "$tor_$1_any_linkable" = no ; then
132 AC_MSG_WARN([Could not find a linkable $1. If you have it installed somewhere unusal, you can specify an explicit path using $7])
133 TOR_WARN_MISSING_LIB($1, pkg)
134 AC_MSG_ERROR([Missing libraries; unable to proceed.])
136 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.])
137 TOR_WARN_MISSING_LIB($1, devpkg)
138 AC_MSG_ERROR([Missing headers; unable to proceed.])
142 LDFLAGS="$tor_saved_LDFLAGS"
143 LIBS="$tor_saved_LIBS"
144 CPPFLAGS="$tor_saved_CPPFLAGS"
145 ]) dnl end cache check
148 if test "$tor_cv_library_$1_dir" != "(system)"; then
149 TOR_EXTEND_CODEPATH($tor_cv_library_$1_dir)
152 TOR_DEFINE_CODEPATH($tor_cv_library_$1_dir, $1)
154 if test "$cross_compiling" != yes; then
155 AC_CACHE_CHECK([whether we need extra options to link $1],
156 tor_cv_library_$1_linker_option, [
157 orig_LDFLAGS="$LDFLAGS"
160 if test -d "$tor_cv_library_$1_dir/lib"; then
161 tor_trydir="$tor_cv_library_$1_dir/lib"
163 tor_trydir="$tor_cv_library_$1_dir"
165 for tor_tryextra in "(none)" "-Wl,-R$tor_trydir" "-R$tor_trydir" \
166 "-Wl,-rpath,$tor_trydir" ; do
167 if test "$tor_tryextra" = "(none)"; then
168 LDFLAGS="$orig_LDFLAGS"
170 LDFLAGS="$tor_tryextra $orig_LDFLAGS"
172 AC_RUN_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
173 [runnable=yes], [runnable=no])
174 if test "$runnable" = yes; then
175 tor_cv_library_$1_linker_option=$tor_tryextra
180 if test "$runnable" = no; then
181 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}])
183 LDFLAGS="$orig_LDFLAGS"
184 ]) dnl end cache check check for extra options.
186 if test "$tor_cv_library_$1_linker_option" != "(none)" ; then
187 TOR_LDFLAGS_$1="$TOR_LDFLAGS_$1 $tor_cv_library_$1_linker_option"
191 LIBS="$tor_saved_LIBS"
192 LDFLAGS="$tor_saved_LDFLAGS"
193 CPPFLAGS="$tor_saved_CPPFLAGS"
197 dnl Check whether the prototype for a function is present or missing.
198 dnl Apple has a nasty habit of putting functions in their libraries (so that
199 dnl AC_CHECK_FUNCS passes) but not actually declaring them in the headers.
201 dnl TOR_CHECK_PROTYPE(1:functionname, 2:macroname, 2: includes)
202 AC_DEFUN([TOR_CHECK_PROTOTYPE], [
203 AC_CACHE_CHECK([for declaration of $1], tor_cv_$1_declared, [
204 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$3],[void *ptr= $1 ;]),
205 tor_cv_$1_declared=yes,tor_cv_$1_declared=no)])
206 if test x$tor_cv_$1_declared != xno ; then
208 [Defined if the prototype for $1 seems to be present.])