fix typos from 783f705d
[tor.git] / acinclude.m4
blob43280597a409f972ce96e0edc3413d05eeea225d
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 Copyright (c) 2007-2012, The Tor Project, Inc.
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:flags
46 AC_DEFUN([TOR_CHECK_CFLAGS], [
47   AS_VAR_PUSHDEF([VAR],[tor_cv_cflags_$1])
48   AC_CACHE_CHECK([whether the compiler accepts $1], VAR, [
49     tor_saved_CFLAGS="$CFLAGS"
50     CFLAGS="$CFLAGS -pedantic -Werror $1"
51     AC_TRY_COMPILE([], [return 0;],
52                    [AS_VAR_SET(VAR,yes)],
53                    [AS_VAR_SET(VAR,no)])
54     CFLAGS="$tor_saved_CFLAGS"
55   ])
56   if test x$VAR = xyes; then
57     CFLAGS="$CFLAGS $1"
58   fi
59   AS_VAR_POPDEF([VAR])
62 dnl 1:flags
63 dnl 2:extra ldflags
64 dnl 3:extra libraries
65 AC_DEFUN([TOR_CHECK_LDFLAGS], [
66   AS_VAR_PUSHDEF([VAR],[tor_cv_ldflags_$1])
67   AC_CACHE_CHECK([whether the linker accepts $1], VAR, [
68     tor_saved_CFLAGS="$CFLAGS"
69     tor_saved_LDFLAGS="$LDFLAGS"
70     tor_saved_LIBS="$LIBS"
71     CFLAGS="$CFLAGS -pedantic -Werror"
72     LDFLAGS="$LDFLAGS $2 $1"
73     LIBS="$LIBS $3"
74     AC_TRY_LINK([], [return 0;],
75                    [AS_VAR_SET(VAR,yes)],
76                    [AS_VAR_SET(VAR,no)])
77     CFLAGS="$tor_saved_CFLAGS"
78     LDFLAGS="$tor_saved_LDFLAGS"
79     LIBS="$tor_saved_LIBS"
80   ])
81   if test x$VAR = xyes; then
82     LDFLAGS="$LDFLAGS $1"
83   fi
84   AS_VAR_POPDEF([VAR])
87 dnl 1:libname
88 AC_DEFUN([TOR_WARN_MISSING_LIB], [
89 h=""
90 if test x$2 = xdevpkg; then
91   h=" headers for"
93 if test -f /etc/debian_version && test x"$tor_$1_$2_debian" != x; then
94   AC_WARN([On Debian, you can install$h $1 using "apt-get install $tor_$1_$2_debian"])
95   if test x"$tor_$1_$2_debian" != x"$tor_$1_devpkg_debian"; then 
96     AC_WARN([   You will probably need $tor_$1_devpkg_debian too.])
97   fi 
99 if test -f /etc/fedora-release && test x"$tor_$1_$2_redhat" != x; then
100   AC_WARN([On Fedora Core, you can install$h $1 using "yum install $tor_$1_$2_redhat"])
101   if test x"$tor_$1_$2_redhat" != x"$tor_$1_devpkg_redhat"; then 
102     AC_WARN([   You will probably need to install $tor_$1_devpkg_redhat too.])
103   fi 
104 else
105   if test -f /etc/redhat-release && test x"$tor_$1_$2_redhat" != x; then
106     AC_WARN([On most Redhat-based systems, you can get$h $1 by installing the $tor_$1_$2_redhat" RPM package])
107     if test x"$tor_$1_$2_redhat" != x"$tor_$1_devpkg_redhat"; then 
108       AC_WARN([   You will probably need to install $tor_$1_devpkg_redhat too.])
109     fi 
110   fi
114 dnl Look for a library, and its associated includes, and how to link
115 dnl against it.
117 dnl TOR_SEARCH_LIBRARY(1:libname, 2:IGNORED, 3:linkargs, 4:headers,
118 dnl                    5:prototype,
119 dnl                    6:code, 7:IGNORED, 8:searchextra)
121 dnl Special variables:
122 dnl   ALT_{libname}_WITHVAL -- another possible value for --with-$1-dir.
123 dnl       Used to support renaming --with-ssl-dir to --with-openssl-dir
125 AC_DEFUN([TOR_SEARCH_LIBRARY], [
126 try$1dir=""
127 AC_ARG_WITH($1-dir,
128   [  --with-$1-dir=PATH    Specify path to $1 installation ],
129   [
130      if test x$withval != xno ; then
131         try$1dir="$withval"
132      fi
133   ])
134 if test "x$try$1dir" = x && test "x$ALT_$1_WITHVAL" != x ; then
135   try$1dir="$ALT_$1_WITHVAL"
138 tor_saved_LIBS="$LIBS"
139 tor_saved_LDFLAGS="$LDFLAGS"
140 tor_saved_CPPFLAGS="$CPPFLAGS"
141 AC_CACHE_CHECK([for $1 directory], tor_cv_library_$1_dir, [
142   tor_$1_dir_found=no
143   tor_$1_any_linkable=no
145   for tor_trydir in "$try$1dir" "(system)" "$prefix" /usr/local /usr/pkg $8; do
146     LDFLAGS="$tor_saved_LDFLAGS"
147     LIBS="$tor_saved_LIBS $3"
148     CPPFLAGS="$tor_saved_CPPFLAGS"
150     if test -z "$tor_trydir" ; then
151       continue;
152     fi
154     # Skip the directory if it isn't there.
155     if test ! -d "$tor_trydir" && test "$tor_trydir" != "(system)"; then
156       continue;
157     fi
159     # If this isn't blank, try adding the directory (or appropriate
160     # include/libs subdirectories) to the command line.
161     if test "$tor_trydir" != "(system)"; then
162       TOR_EXTEND_CODEPATH($tor_trydir)
163     fi
165     # Can we link against (but not necessarily run, or find the headers for)
166     # the binary?
167     AC_LINK_IFELSE([AC_LANG_PROGRAM([$5], [$6])],
168                    [linkable=yes], [linkable=no])
170     if test "$linkable" = yes; then
171       tor_$1_any_linkable=yes
172       # Okay, we can link against it.  Can we find the headers?
173       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$4], [$6])],
174                         [buildable=yes], [buildable=no])
175       if test "$buildable" = yes; then
176          tor_cv_library_$1_dir=$tor_trydir
177          tor_$1_dir_found=yes
178          break
179       fi
180     fi
181   done
183   if test "$tor_$1_dir_found" = no; then
184     if test "$tor_$1_any_linkable" = no ; then
185       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])
186       TOR_WARN_MISSING_LIB($1, pkg)
187       AC_MSG_ERROR([Missing libraries; unable to proceed.])
188     else
189       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.])
190       TOR_WARN_MISSING_LIB($1, devpkg)
191       AC_MSG_ERROR([Missing headers; unable to proceed.])
192     fi
193   fi
195   LDFLAGS="$tor_saved_LDFLAGS"
196   LIBS="$tor_saved_LIBS"
197   CPPFLAGS="$tor_saved_CPPFLAGS"
198 ]) dnl end cache check
200 LIBS="$LIBS $3"
201 if test "$tor_cv_library_$1_dir" != "(system)"; then
202    TOR_EXTEND_CODEPATH($tor_cv_library_$1_dir)
205 TOR_DEFINE_CODEPATH($tor_cv_library_$1_dir, $1)
207 if test "$cross_compiling" != yes; then
208   AC_CACHE_CHECK([whether we need extra options to link $1],
209                  tor_cv_library_$1_linker_option, [
210    orig_LDFLAGS="$LDFLAGS"
211    runs=no
212    linked_with=nothing
213    if test -d "$tor_cv_library_$1_dir/lib"; then
214      tor_trydir="$tor_cv_library_$1_dir/lib"
215    else
216      tor_trydir="$tor_cv_library_$1_dir"
217    fi
218    for tor_tryextra in "(none)" "-Wl,-R$tor_trydir" "-R$tor_trydir" \
219                        "-Wl,-rpath,$tor_trydir" ; do
220      if test "$tor_tryextra" = "(none)"; then
221        LDFLAGS="$orig_LDFLAGS"
222      else
223        LDFLAGS="$tor_tryextra $orig_LDFLAGS"
224      fi
225      AC_RUN_IFELSE([AC_LANG_PROGRAM([$5], [$6])],
226                    [runnable=yes], [runnable=no])
227      if test "$runnable" = yes; then
228         tor_cv_library_$1_linker_option=$tor_tryextra
229         break
230      fi
231    done
233    if test "$runnable" = no; then
234      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}])
235    fi
236    LDFLAGS="$orig_LDFLAGS"
237   ]) dnl end cache check check for extra options.
239   if test "$tor_cv_library_$1_linker_option" != "(none)" ; then
240     TOR_LDFLAGS_$1="$TOR_LDFLAGS_$1 $tor_cv_library_$1_linker_option"
241   fi
242 fi # cross-compile
244 LIBS="$tor_saved_LIBS"
245 LDFLAGS="$tor_saved_LDFLAGS"
246 CPPFLAGS="$tor_saved_CPPFLAGS"
248 ]) dnl end defun
250 dnl Check whether the prototype for a function is present or missing.
251 dnl Apple has a nasty habit of putting functions in their libraries (so that
252 dnl AC_CHECK_FUNCS passes) but not actually declaring them in the headers.
254 dnl TOR_CHECK_PROTYPE(1:functionname, 2:macroname, 2: includes)
255 AC_DEFUN([TOR_CHECK_PROTOTYPE], [
256  AC_CACHE_CHECK([for declaration of $1], tor_cv_$1_declared, [
257    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$3],[void *ptr= $1 ;])],
258                      tor_cv_$1_declared=yes,tor_cv_$1_declared=no)])
259 if test x$tor_cv_$1_declared != xno ; then
260   AC_DEFINE($2, 1,
261        [Defined if the prototype for $1 seems to be present.])