Implement queue with O(1) operations, and correct some math.
[tor/rransom.git] / acinclude.m4
blob766ca1e62e3135521ad38cc194063de0d74b7ba4
1 dnl Helper macros for Tor configure.in
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 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 && 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.])
52   fi 
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 to install $tor_$1_devpkg_redhat too.])
58   fi 
59 else
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 to install $tor_$1_devpkg_redhat too.])
64     fi 
65   fi
69 dnl Look for a library, and its associated includes, and how to link
70 dnl against it.
71 dnl
72 dnl TOR_SEARCH_LIBRARY(1:libname, 2:IGNORED, 3:linkargs, 4:headers,
73 dnl                    5:prototype,
74 dnl                    6:code, 7:IGNORED, 8:searchextra)
75 dnl
76 dnl Special variables:
77 dnl   ALT_{libname}_WITHVAL -- another possible value for --with-$1-dir.
78 dnl       Used to support renaming --with-ssl-dir to --with-openssl-dir
79 dnl
80 AC_DEFUN([TOR_SEARCH_LIBRARY], [
81 try$1dir=""
82 AC_ARG_WITH($1-dir,
83   [  --with-$1-dir=PATH    Specify path to $1 installation ],
84   [
85      if test x$withval != xno ; then
86         try$1dir="$withval"
87      fi
88   ])
89 if test "x$try$1dir" = x && test "x$ALT_$1_WITHVAL" != x ; then
90   try$1dir="$ALT_$1_WITHVAL"
93 tor_saved_LIBS="$LIBS"
94 tor_saved_LDFLAGS="$LDFLAGS"
95 tor_saved_CPPFLAGS="$CPPFLAGS"
96 AC_CACHE_CHECK([for $1 directory], tor_cv_library_$1_dir, [
97   tor_$1_dir_found=no
98   tor_$1_any_linkable=no
100   for tor_trydir in "$try$1dir" "(system)" "$prefix" /usr/local /usr/pkg $8; do
101     LDFLAGS="$tor_saved_LDFLAGS"
102     LIBS="$tor_saved_LIBS $3"
103     CPPFLAGS="$tor_saved_CPPFLAGS"
105     if test -z "$tor_trydir" ; then
106       continue;
107     fi
109     # Skip the directory if it isn't there.
110     if test ! -d "$tor_trydir" && test "$tor_trydir" != "(system)"; then
111       continue;
112     fi
114     # If this isn't blank, try adding the directory (or appropriate
115     # include/libs subdirectories) to the command line.
116     if test "$tor_trydir" != "(system)"; then
117       TOR_EXTEND_CODEPATH($tor_trydir)
118     fi
120     # Can we link against (but not necessarily run, or find the headers for)
121     # the binary?
122     AC_LINK_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
123                    [linkable=yes], [linkable=no])
125     if test "$linkable" = yes; then
126       tor_$1_any_linkable=yes
127       # Okay, we can link against it.  Can we find the headers?
128       AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$4], [$6]),
129                         [buildable=yes], [buildable=no])
130       if test "$buildable" = yes; then
131          tor_cv_library_$1_dir=$tor_trydir
132          tor_$1_dir_found=yes
133          break
134       fi
135     fi
136   done
138   if test "$tor_$1_dir_found" = no; then
139     if test "$tor_$1_any_linkable" = no ; then
140       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])
141       TOR_WARN_MISSING_LIB($1, pkg)
142       AC_MSG_ERROR([Missing libraries; unable to proceed.])
143     else
144       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.])
145       TOR_WARN_MISSING_LIB($1, devpkg)
146       AC_MSG_ERROR([Missing headers; unable to proceed.])
147     fi
148   fi
150   LDFLAGS="$tor_saved_LDFLAGS"
151   LIBS="$tor_saved_LIBS"
152   CPPFLAGS="$tor_saved_CPPFLAGS"
153 ]) dnl end cache check
155 LIBS="$LIBS $3"
156 if test "$tor_cv_library_$1_dir" != "(system)"; then
157    TOR_EXTEND_CODEPATH($tor_cv_library_$1_dir)
160 TOR_DEFINE_CODEPATH($tor_cv_library_$1_dir, $1)
162 if test "$cross_compiling" != yes; then
163   AC_CACHE_CHECK([whether we need extra options to link $1],
164                  tor_cv_library_$1_linker_option, [
165    orig_LDFLAGS="$LDFLAGS"
166    runs=no
167    linked_with=nothing
168    if test -d "$tor_cv_library_$1_dir/lib"; then
169      tor_trydir="$tor_cv_library_$1_dir/lib"
170    else
171      tor_trydir="$tor_cv_library_$1_dir"
172    fi
173    for tor_tryextra in "(none)" "-Wl,-R$tor_trydir" "-R$tor_trydir" \
174                        "-Wl,-rpath,$tor_trydir" ; do
175      if test "$tor_tryextra" = "(none)"; then
176        LDFLAGS="$orig_LDFLAGS"
177      else
178        LDFLAGS="$tor_tryextra $orig_LDFLAGS"
179      fi
180      AC_RUN_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
181                    [runnable=yes], [runnable=no])
182      if test "$runnable" = yes; then
183         tor_cv_library_$1_linker_option=$tor_tryextra
184         break
185      fi
186    done
188    if test "$runnable" = no; then
189      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}])
190    fi
191    LDFLAGS="$orig_LDFLAGS"
192   ]) dnl end cache check check for extra options.
194   if test "$tor_cv_library_$1_linker_option" != "(none)" ; then
195     TOR_LDFLAGS_$1="$TOR_LDFLAGS_$1 $tor_cv_library_$1_linker_option"
196   fi
197 fi # cross-compile
199 LIBS="$tor_saved_LIBS"
200 LDFLAGS="$tor_saved_LDFLAGS"
201 CPPFLAGS="$tor_saved_CPPFLAGS"
203 ]) dnl end defun
205 dnl Check whether the prototype for a function is present or missing.
206 dnl Apple has a nasty habit of putting functions in their libraries (so that
207 dnl AC_CHECK_FUNCS passes) but not actually declaring them in the headers.
209 dnl TOR_CHECK_PROTYPE(1:functionname, 2:macroname, 2: includes)
210 AC_DEFUN([TOR_CHECK_PROTOTYPE], [
211  AC_CACHE_CHECK([for declaration of $1], tor_cv_$1_declared, [
212    AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$3],[void *ptr= $1 ;]),
213                      tor_cv_$1_declared=yes,tor_cv_$1_declared=no)])
214 if test x$tor_cv_$1_declared != xno ; then
215   AC_DEFINE($2, 1,
216        [Defined if the prototype for $1 seems to be present.])