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