2 dnl Helper macros for Tor configure.in
3 dnl Copyright (c) 2001-2004, Roger Dingledine
4 dnl Copyright (c) 2004-2007, Roger Dingledine, Nick Mathewson
5 dnl See LICENSE for licensing information
7 AC_DEFUN([TOR_EXTEND_CODEPATH],
9 if test -d "$1/lib"; then
10 LDFLAGS="-L$1/lib $LDFLAGS"
12 LDFLAGS="-L$1 $LDFLAGS"
14 if test -d "$1/include"; then
15 CPPFLAGS="-I$1/include $CPPFLAGS"
17 CPPFLAGS="-I$1 $CPPFLAGS"
21 AC_DEFUN([TOR_DEFINE_CODEPATH],
23 if test x$1 = "x(system)"; then
27 if test -d "$1/lib"; then
28 TOR_LDFLAGS_$2="-L$1/lib"
32 if test -d "$1/include"; then
33 TOR_CPPFLAGS_$2="-I$1/include"
35 TOR_CPPFLAGS_$2="-I$1"
38 AC_SUBST(TOR_CPPFLAGS_$2)
39 AC_SUBST(TOR_LDFLAGS_$2)
43 AC_DEFUN([TOR_WARN_MISSING_LIB], [
45 if test x$2 = xdevpkg; then
48 if test -f /etc/debian_version && test x"$tor_$1_$2_debian" != x; then
49 AC_WARN([On Debian, you can install$h $1 using "apt-get install $tor_$1_$2_debian"])
50 if test x"$tor_$1_$2_debian" != x"$tor_$1_devpkg_debian"; then
51 AC_WARN([ You will probably need $tor_$1_devpkg_debian too.])
54 if test -f /etc/fedora-release && test x"$tor_$1_$2_redhat" != x; then
55 AC_WARN([On Fedora Core, you can install$h $1 using "yum install $tor_$1_$2_redhat"])
56 if test x"$tor_$1_$2_redhat != x"$tor_$1_devpkg_redhat"; then
57 AC_WARN([ You will probably need $tor_$1_devpkg_redhat too.])
60 if test -f /etc/redhat-release && test x"$tor_$1_$2_redhat" != x; then
61 AC_WARN([On most Redhat-based systems, you can get$h $1 by installing the $tor_$1_$2_redhat" RPM package])
62 if test x"$tor_$1_$2_redhat" != x"$tor_$1_devpkg_redhat"; then
63 AC_WARN([ You will probably need $tor_$1_devpkg_redhat too.])
69 dnl Look for a library, and its associated includes, and how to link
72 dnl TOR_SEARCH_LIBRARY(1:libname, 2:IGNORED, 3:linkargs, 4:headers,
74 dnl 6:code, 7:optionname, 8:searchextra)
75 AC_DEFUN([TOR_SEARCH_LIBRARY], [
78 [ --with-$1-dir=PATH Specify path to $1 installation ],
80 if test x$withval != xno ; then
84 tor_saved_LIBS="$LIBS"
85 tor_saved_LDFLAGS="$LDFLAGS"
86 tor_saved_CPPFLAGS="$CPPFLAGS"
87 AC_CACHE_CHECK([for $1 directory], tor_cv_library_$1_dir, [
89 tor_$1_any_linkable=no
91 for tor_trydir in "$try$1dir" "(system)" "$prefix" /usr/local /usr/pkg $8; do
92 LDFLAGS="$tor_saved_LDFLAGS"
93 LIBS="$tor_saved_LIBS $3"
94 CPPFLAGS="$tor_saved_CPPFLAGS"
96 if test -z "$tor_trydir" ; then
100 # Skip the directory if it isn't there.
101 if test ! -d "$tor_trydir" && test "$tor_trydir" != "(system)"; then
105 # If this isn't blank, try adding the directory (or appropriate
106 # include/libs subdirectories) to the command line.
107 if test "$tor_trydir" != "(system)"; then
108 TOR_EXTEND_CODEPATH($tor_trydir)
111 # Can we link against (but not necessarily run, or find the headers for)
113 AC_LINK_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
114 [linkable=yes], [linkable=no])
116 if test "$linkable" = yes; then
117 tor_$1_any_linkable=yes
118 # Okay, we can link against it. Can we find the headers?
119 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$4], [$6]),
120 [buildable=yes], [buildable=no])
121 if test "$buildable" = yes; then
122 tor_cv_library_$1_dir=$tor_trydir
129 if test "$tor_$1_dir_found" = no; then
130 if test "$tor_$1_any_linkable" = no ; then
131 AC_MSG_WARN([Could not find a linkable $1. If you have it installed somewhere unusal, you can specify an explicit path using $7])
132 TOR_WARN_MISSING_LIB($1, pkg)
133 AC_MSG_ERROR([Missing libraries; unable to proceed.])
135 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.])
136 TOR_WARN_MISSING_LIB($1, devpkg)
137 AC_MSG_ERROR([Missing headers; unable to proceed.])
141 LDFLAGS="$tor_saved_LDFLAGS"
142 LIBS="$tor_saved_LIBS"
143 CPPFLAGS="$tor_saved_CPPFLAGS"
144 ]) dnl end cache check
147 if test "$tor_cv_library_$1_dir" != "(system)"; then
148 TOR_EXTEND_CODEPATH($tor_cv_library_$1_dir)
151 TOR_DEFINE_CODEPATH($tor_cv_library_$1_dir, $1)
153 if test "$cross_compiling" != yes; then
154 AC_CACHE_CHECK([whether we need extra options to link $1],
155 tor_cv_library_$1_linker_option, [
156 orig_LDFLAGS="$LDFLAGS"
159 if test -d "$tor_cv_library_$1_dir/lib"; then
160 tor_trydir="$tor_cv_library_$1_dir/lib"
162 tor_trydir="$tor_cv_library_$1_dir"
164 for tor_tryextra in "(none)" "-Wl,-R$tor_trydir" "-R$tor_trydir" \
165 "-Wl,-rpath,$tor_trydir" ; do
166 if test "$tor_tryextra" = "(none)"; then
167 LDFLAGS="$orig_LDFLAGS"
169 LDFLAGS="$tor_tryextra $orig_LDFLAGS"
171 AC_RUN_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
172 [runnable=yes], [runnable=no])
173 if test "$runnable" = yes; then
174 tor_cv_library_$1_linker_option=$tor_tryextra
179 if test "$runnable" = no; then
180 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}])
182 LDFLAGS="$orig_LDFLAGS"
183 ]) dnl end cache check check for extra options.
185 if test "$tor_cv_library_$1_linker_option" != "(none)" ; then
186 TOR_LDFLAGS_$1="$TOR_LDFLAGS_$1 $tor_cv_library_$1_linker_option"
190 LIBS="$tor_saved_LIBS"
191 LDFLAGS="$tor_saved_LDFLAGS"
192 CPPFLAGS="$tor_saved_CPPFLAGS"