backport candidate: when we have k non-v2 authorities in our
[tor.git] / acinclude.m4
blobe97915d67d3a5321241665378757910c41f70122
1 dnl $Id$
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"
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
21 AC_DEFUN([TOR_DEFINE_CODEPATH],
23   if test x$1 = "x(system)"; then
24     TOR_LDFLAGS_$2=""
25     TOR_CPPFLAGS_$2=""
26   else
27    if test -d "$1/lib"; then
28      TOR_LDFLAGS_$2="-L$1/lib"
29    else
30      TOR_LDFLAGS_$2="-L$1"
31    fi
32    if test -d "$1/include"; then
33      TOR_CPPFLAGS_$2="-I$1/include"
34    else
35      TOR_CPPFLAGS_$2="-I$1"
36    fi
37   fi
38   AC_SUBST(TOR_CPPFLAGS_$2)
39   AC_SUBST(TOR_LDFLAGS_$2)
42 dnl 1:libname
43 AC_DEFUN([TOR_WARN_MISSING_LIB], [
44 h=""
45 if test x$2 = xdevpkg; then
46   h=" headers for"
48 if test -f /etc/debian_version -a 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"])
51 if test -f /etc/fedora-release -a x"$tor_$1_$2_redhat" != x; then
52   AC_WARN([On Fedora Core, you can install$h $1 using "yum install $tor_$1_$2_redhat"])
53 else
54   if test -f /etc/redhat-release -a x"$tor_$1_$2_redhat" != x; then
55     AC_WARN([On most Redhat-based systems, you can get$h $1 by installing the $tor_$1_$2_redhat" RPM package])
56   fi
60 dnl Look for a library, and its associated includes, and how to link
61 dnl against it.
62 dnl
63 dnl TOR_SEARCH_LIBRARY(1:libname, 2:IGNORED, 3:linkargs, 4:headers,
64 dnl                    5:prototype,
65 dnl                    6:code, 7:optionname, 8:searchextra)
66 AC_DEFUN([TOR_SEARCH_LIBRARY], [
67 try$1dir=""
68 AC_ARG_WITH($1-dir,
69   [  --with-$1-dir=PATH    Specify path to $1 installation ],
70   [
71      if test x$withval != xno ; then
72         try$1dir="$withval"
73      fi
74   ])
75 tor_saved_LIBS="$LIBS"
76 tor_saved_LDFLAGS="$LDFLAGS"
77 tor_saved_CPPFLAGS="$CPPFLAGS"
78 AC_CACHE_CHECK([for $1 directory], tor_cv_library_$1_dir, [
79   tor_$1_dir_found=no
80   tor_$1_any_linkable=no
82   for tor_trydir in "$try$1dir" "(system)" "$prefix" /usr/local /usr/pkg $8; do
83     LDFLAGS="$tor_saved_LDFLAGS"
84     LIBS="$tor_saved_LIBS $3"
85     CPPFLAGS="$tor_saved_CPPFLAGS"
87     if test -z "$tor_trydir" ; then
88       continue;
89     fi
91     # Skip the directory if it isn't there.
92     if test ! -d "$tor_trydir" -a "$tor_trydir" != "(system)"; then
93       continue;
94     fi
96     # If this isn't blank, try adding the directory (or appropriate
97     # include/libs subdirectories) to the command line.
98     if test "$tor_trydir" != "(system)"; then
99       TOR_EXTEND_CODEPATH($tor_trydir)
100     fi
102     # Can we link against (but not necessarily run, or find the headers for)
103     # the binary?
104     AC_LINK_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
105                    [linkable=yes], [linkable=no])
107     if test $linkable = yes; then
108       tor_$1_any_linkable=yes
109       # Okay, we can link against it.  Can we find the headers?
110       AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$4], [$6]),
111                         [buildable=yes], [buildable=no])
112       if test $buildable = yes; then
113          tor_cv_library_$1_dir=$tor_trydir
114          tor_$1_dir_found=yes
115          break
116       fi
117     fi
118   done
120   if test $tor_$1_dir_found = no; then
121     if test $tor_$1_any_linkable = no ; then
122       AC_MSG_WARN([Could not find a linkable $1.  If you have it installed somewhere unusal, you can specify an explicit path using $7])
123       TOR_WARN_MISSING_LIB($1, pkg)
124       AC_MSG_ERROR([Missing libraries; unable to proceed.])
125     else
126       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.])
127       TOR_WARN_MISSING_LIB($1, devpkg)
128       AC_MSG_ERROR([Missing headers; unable to proceed.])
129     fi
130   fi
132   LDFLAGS="$tor_saved_LDFLAGS"
133   LIBS="$tor_saved_LIBS"
134   CPPFLAGS="$tor_saved_CPPFLAGS"
135 ]) dnl end cache check
137 LIBS="$LIBS $3"
138 if test $tor_cv_library_$1_dir != "(system)"; then
139    TOR_EXTEND_CODEPATH($tor_cv_library_$1_dir)
142 TOR_DEFINE_CODEPATH($tor_cv_library_$1_dir, $1)
144 if test -z "$CROSS_COMPILE"; then
145   AC_CACHE_CHECK([whether we need extra options to link $1],
146                  tor_cv_library_$1_linker_option, [
147    tor_saved_LDFLAGS="$LDFLAGS"
148    runs=no
149    linked_with=nothing
150    if test -d "$tor_cv_library_$1_dir/lib"; then
151      tor_trydir="$tor_cv_library_$1_dir/lib"
152    else
153      tor_trydir="$tor_cv_library_$1_dir"
154    fi
155    for tor_tryextra in "(none)" "-Wl,-R$tor_trydir" "-R$tor_trydir" \
156                        "-Wl,-rpath,$tor_trydir" ; do
157      if test "$tor_tryextra" = "(none)"; then
158        LDFLAGS="$tor_saved_LDFLAGS"
159      else
160        LDFLAGS="$tor_tryextra $tor_saved_LDFLAGS"
161      fi
162      AC_RUN_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
163                    [runnable=yes], [runnable=no])
164      if test "$runnable" = yes; then
165         tor_cv_library_$1_linker_option=$tor_tryextra
166         break
167      fi
168    done
170    if test "$runnable" = no; then
171      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}])
172    fi
173    LDFLAGS="$tor_saved_LDFLAGS"
174   ]) dnl end cache check check for extra options.
176   if test "$tor_cv_library_$1_linker_option" != "(none)" ; then
177     TOR_LDFLAGS_$1="$tor_cv_library_$1_linker_option"
178   fi
179 fi # cross-compile
181 LIBS="$tor_saved_LIBS"
182 LDFLAGS="$tor_saved_LDFLAGS"
183 CPPFLAGS="$TOR_CPPFLAGS_$1 $tor_saved_CPPFLAGS"
185 ]) dnl end defun