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