Fix a couple of non-cleared key issues in hidden services
[tor/rransom.git] / acinclude.m4
blob76e992572c7b0b5aea17bb33ee442a4b33de8448
1 dnl $Id$
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"
12   else
13     LDFLAGS="-L$1 $LDFLAGS"
14   fi
15   if test -d "$1/include"; then
16     CPPFLAGS="-I$1/include $CPPFLAGS"
17   else
18     CPPFLAGS="-I$1 $CPPFLAGS"
19   fi
22 AC_DEFUN([TOR_DEFINE_CODEPATH],
24   if test x$1 = "x(system)"; then
25     TOR_LDFLAGS_$2=""
26     TOR_CPPFLAGS_$2=""
27   else
28    if test -d "$1/lib"; then
29      TOR_LDFLAGS_$2="-L$1/lib"
30      TOR_LIBDIR_$2="$1/lib"
31    else
32      TOR_LDFLAGS_$2="-L$1"
33      TOR_LIBDIR_$2="$1"
34    fi
35    if test -d "$1/include"; then
36      TOR_CPPFLAGS_$2="-I$1/include"
37    else
38      TOR_CPPFLAGS_$2="-I$1"
39    fi
40   fi
41   AC_SUBST(TOR_CPPFLAGS_$2)
42   AC_SUBST(TOR_LDFLAGS_$2)
45 dnl 1:libname
46 AC_DEFUN([TOR_WARN_MISSING_LIB], [
47 h=""
48 if test x$2 = xdevpkg; then
49   h=" headers for"
51 if test -f /etc/debian_version && test x"$tor_$1_$2_debian" != x; then
52   AC_WARN([On Debian, you can install$h $1 using "apt-get install $tor_$1_$2_debian"])
53   if test x"$tor_$1_$2_debian" != x"$tor_$1_devpkg_debian"; then 
54     AC_WARN([   You will probably need $tor_$1_devpkg_debian too.])
55   fi 
57 if test -f /etc/fedora-release && test x"$tor_$1_$2_redhat" != x; then
58   AC_WARN([On Fedora Core, you can install$h $1 using "yum install $tor_$1_$2_redhat"])
59   if test x"$tor_$1_$2_redhat" != x"$tor_$1_devpkg_redhat"; then 
60     AC_WARN([   You will probably need to install $tor_$1_devpkg_redhat too.])
61   fi 
62 else
63   if test -f /etc/redhat-release && test x"$tor_$1_$2_redhat" != x; then
64     AC_WARN([On most Redhat-based systems, you can get$h $1 by installing the $tor_$1_$2_redhat" RPM package])
65     if test x"$tor_$1_$2_redhat" != x"$tor_$1_devpkg_redhat"; then 
66       AC_WARN([   You will probably need to install $tor_$1_devpkg_redhat too.])
67     fi 
68   fi
72 dnl Look for a library, and its associated includes, and how to link
73 dnl against it.
74 dnl
75 dnl TOR_SEARCH_LIBRARY(1:libname, 2:IGNORED, 3:linkargs, 4:headers,
76 dnl                    5:prototype,
77 dnl                    6:code, 7:IGNORED, 8:searchextra)
78 dnl
79 dnl Special variables:
80 dnl   ALT_{libname}_WITHVAL -- another possible value for --with-$1-dir.
81 dnl       Used to support renaming --with-ssl-dir to --with-openssl-dir
82 dnl
83 AC_DEFUN([TOR_SEARCH_LIBRARY], [
84 try$1dir=""
85 AC_ARG_WITH($1-dir,
86   [  --with-$1-dir=PATH    Specify path to $1 installation ],
87   [
88      if test x$withval != xno ; then
89         try$1dir="$withval"
90      fi
91   ])
92 if test "x$try$1dir" = x && test "x$ALT_$1_WITHVAL" != x ; then
93   try$1dir="$ALT_$1_WITHVAL"
96 tor_saved_LIBS="$LIBS"
97 tor_saved_LDFLAGS="$LDFLAGS"
98 tor_saved_CPPFLAGS="$CPPFLAGS"
99 AC_CACHE_CHECK([for $1 directory], tor_cv_library_$1_dir, [
100   tor_$1_dir_found=no
101   tor_$1_any_linkable=no
103   for tor_trydir in "$try$1dir" "(system)" "$prefix" /usr/local /usr/pkg $8; do
104     LDFLAGS="$tor_saved_LDFLAGS"
105     LIBS="$tor_saved_LIBS $3"
106     CPPFLAGS="$tor_saved_CPPFLAGS"
108     if test -z "$tor_trydir" ; then
109       continue;
110     fi
112     # Skip the directory if it isn't there.
113     if test ! -d "$tor_trydir" && test "$tor_trydir" != "(system)"; then
114       continue;
115     fi
117     # If this isn't blank, try adding the directory (or appropriate
118     # include/libs subdirectories) to the command line.
119     if test "$tor_trydir" != "(system)"; then
120       TOR_EXTEND_CODEPATH($tor_trydir)
121     fi
123     # Can we link against (but not necessarily run, or find the headers for)
124     # the binary?
125     AC_LINK_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
126                    [linkable=yes], [linkable=no])
128     if test "$linkable" = yes; then
129       tor_$1_any_linkable=yes
130       # Okay, we can link against it.  Can we find the headers?
131       AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$4], [$6]),
132                         [buildable=yes], [buildable=no])
133       if test "$buildable" = yes; then
134          tor_cv_library_$1_dir=$tor_trydir
135          tor_$1_dir_found=yes
136          break
137       fi
138     fi
139   done
141   if test "$tor_$1_dir_found" = no; then
142     if test "$tor_$1_any_linkable" = no ; then
143       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])
144       TOR_WARN_MISSING_LIB($1, pkg)
145       AC_MSG_ERROR([Missing libraries; unable to proceed.])
146     else
147       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.])
148       TOR_WARN_MISSING_LIB($1, devpkg)
149       AC_MSG_ERROR([Missing headers; unable to proceed.])
150     fi
151   fi
153   LDFLAGS="$tor_saved_LDFLAGS"
154   LIBS="$tor_saved_LIBS"
155   CPPFLAGS="$tor_saved_CPPFLAGS"
156 ]) dnl end cache check
158 LIBS="$LIBS $3"
159 if test "$tor_cv_library_$1_dir" != "(system)"; then
160    TOR_EXTEND_CODEPATH($tor_cv_library_$1_dir)
163 TOR_DEFINE_CODEPATH($tor_cv_library_$1_dir, $1)
165 if test "$cross_compiling" != yes; then
166   AC_CACHE_CHECK([whether we need extra options to link $1],
167                  tor_cv_library_$1_linker_option, [
168    orig_LDFLAGS="$LDFLAGS"
169    runs=no
170    linked_with=nothing
171    if test -d "$tor_cv_library_$1_dir/lib"; then
172      tor_trydir="$tor_cv_library_$1_dir/lib"
173    else
174      tor_trydir="$tor_cv_library_$1_dir"
175    fi
176    for tor_tryextra in "(none)" "-Wl,-R$tor_trydir" "-R$tor_trydir" \
177                        "-Wl,-rpath,$tor_trydir" ; do
178      if test "$tor_tryextra" = "(none)"; then
179        LDFLAGS="$orig_LDFLAGS"
180      else
181        LDFLAGS="$tor_tryextra $orig_LDFLAGS"
182      fi
183      AC_RUN_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
184                    [runnable=yes], [runnable=no])
185      if test "$runnable" = yes; then
186         tor_cv_library_$1_linker_option=$tor_tryextra
187         break
188      fi
189    done
191    if test "$runnable" = no; then
192      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}])
193    fi
194    LDFLAGS="$orig_LDFLAGS"
195   ]) dnl end cache check check for extra options.
197   if test "$tor_cv_library_$1_linker_option" != "(none)" ; then
198     TOR_LDFLAGS_$1="$TOR_LDFLAGS_$1 $tor_cv_library_$1_linker_option"
199   fi
200 fi # cross-compile
202 LIBS="$tor_saved_LIBS"
203 LDFLAGS="$tor_saved_LDFLAGS"
204 CPPFLAGS="$tor_saved_CPPFLAGS"
206 ]) dnl end defun
208 dnl Check whether the prototype for a function is present or missing.
209 dnl Apple has a nasty habit of putting functions in their libraries (so that
210 dnl AC_CHECK_FUNCS passes) but not actually declaring them in the headers.
212 dnl TOR_CHECK_PROTYPE(1:functionname, 2:macroname, 2: includes)
213 AC_DEFUN([TOR_CHECK_PROTOTYPE], [
214  AC_CACHE_CHECK([for declaration of $1], tor_cv_$1_declared, [
215    AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$3],[void *ptr= $1 ;]),
216                      tor_cv_$1_declared=yes,tor_cv_$1_declared=no)])
217 if test x$tor_cv_$1_declared != xno ; then
218   AC_DEFINE($2, 1,
219        [Defined if the prototype for $1 seems to be present.])