simplify connection_watch_events()
[tor.git] / acinclude.m4
blob3299c20a13aa524feb7ffa3bc0a712b7536b1d35
1 dnl $Id$
2 dnl Helper macros for Tor configure.in
3 dnl Copyright (c) 2001-2004, Roger Dingledine
4 dnl Copyright (c) 2004-2007, 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 dnl 1:libname
22 AC_DEFUN([TOR_WARN_MISSING_LIB], [
23 h=""
24 if test x$2 = xdevpkg; then
25   h=" headers for"
27 if test -f /etc/debian_version -a x"$tor_$1_$2_debian" != x; then
28   AC_WARN([On Debian, you can install$h $1 using "apt-get install $tor_$1_$2_debian"])
30 if test -f /etc/fedora-release -a x"$tor_$1_$2_redhat" != x; then
31   AC_WARN([On Fedora Core, you can install$h $1 using "yum install $tor_$1_$2_redhat"])
32 else
33   if test -f /etc/redhat-release -a x"$tor_$1_$2_redhat" != x; then
34     AC_WARN([On most Redhat-based systems, you can get$h $1 by installing the $tor_$1_$2_redhat" RPM package])
35   fi
39 dnl Look for a library, and its associated includes, and how to link
40 dnl against it.
41 dnl
42 dnl TOR_SEARCH_LIBRARY(1:libname, 2:IGNORED, 3:linkargs, 4:headers,
43 dnl                    5:prototype,
44 dnl                    6:code, 7:optionname, 8:searchextra)
45 AC_DEFUN([TOR_SEARCH_LIBRARY], [
46 try$1dir=""
47 AC_ARG_WITH($1-dir,
48   [  --with-$1-dir=PATH    Specify path to $1 installation ],
49   [
50      if test x$withval != xno ; then
51         try$1dir="$withval"
52      fi
53   ])
54 tor_saved_LIBS="$LIBS"
55 tor_saved_LDFLAGS="$LDFLAGS"
56 tor_saved_CPPFLAGS="$CPPFLAGS"
57 AC_CACHE_CHECK([for $1 directory], tor_cv_library_$1_dir, [
58   tor_$1_dir_found=no
59   tor_$1_any_linkable=no
61   for tor_trydir in "$try$1dir" "(system)" "$prefix" /usr/local /usr/pkg $8; do
62     LDFLAGS="$tor_saved_LDFLAGS"
63     LIBS="$tor_saved_LIBS $3"
64     CPPFLAGS="$tor_saved_CPPFLAGS"
66     if test -z "$tor_trydir" ; then
67       continue;
68     fi
70     # Skip the directory if it isn't there.
71     if test ! -d "$tor_trydir" -a "$tor_trydir" != "(system)"; then
72       continue;
73     fi
75     # If this isn't blank, try adding the directory (or appropriate
76     # include/libs subdirectories) to the command line.
77     if test "$tor_trydir" != "(system)"; then
78       TOR_EXTEND_CODEPATH($tor_trydir)
79     fi
81     # Can we link against (but not necessarily run, or find the headers for)
82     # the binary?
83     AC_LINK_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
84                    [linkable=yes], [linkable=no])
86     if test $linkable = yes; then
87       tor_$1_any_linkable=yes
88       # Okay, we can link against it.  Can we find the headers?
89       AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$4], [$6]),
90                         [buildable=yes], [buildable=no])
91       if test $buildable = yes; then
92          tor_cv_library_$1_dir=$tor_trydir
93          tor_$1_dir_found=yes
94          break
95       fi
96     fi
97   done
99   if test $tor_$1_dir_found = no; then
100     if test $tor_$1_any_linkable = no ; then
101       AC_MSG_WARN([Could not find a linkable $1.  If you have it installed somewhere unusal, you can specify an explicit path using $7])
102       TOR_WARN_MISSING_LIB($1, pkg)
103       AC_MSG_ERROR([Missing libraries; unable to proceed.])
104     else
105       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.])
106       TOR_WARN_MISSING_LIB($1, devpkg)
107       AC_MSG_ERROR([Missing headers; unable to proceed.])
108     fi
109   fi
111   LDFLAGS="$tor_saved_LDFLAGS"
112   LIBS="$tor_saved_LIBS"
113   CPPFLAGS="$tor_saved_CPPFLAGS"
114 ]) dnl end cache check
116 LIBS="$LIBS $3"
117 if test $tor_cv_library_$1_dir != "(system)"; then
118    TOR_EXTEND_CODEPATH($tor_cv_library_$1_dir)
121 if test -z "$CROSS_COMPILE"; then
122   AC_CACHE_CHECK([whether we need extra options to link $1],
123                  tor_cv_library_$1_linker_option, [
124    tor_saved_LDFLAGS="$LDFLAGS"
125    runs=no
126    linked_with=nothing
127    if test -d "$tor_cv_library_$1_dir/lib"; then
128      tor_trydir="$tor_cv_library_$1_dir/lib"
129    else
130      tor_trydir="$tor_cv_library_$1_dir"
131    fi
132    for tor_tryextra in "(none)" "-Wl,-R$tor_trydir" "-R$tor_trydir" \
133                        "-Wl,-rpath,$tor_trydir" ; do
134      if test "$tor_tryextra" = "(none)"; then
135        LDFLAGS="$tor_saved_LDFLAGS"
136      else
137        LDFLAGS="$tor_tryextra $tor_saved_LDFLAGS"
138      fi
139      AC_RUN_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
140                    [runnable=yes], [runnable=no])
141      if test "$runnable" = yes; then
142         tor_cv_library_$1_linker_option=$tor_tryextra
143         break
144      fi
145    done
147    if test "$runnable" = no; then
148      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 $7}])
149    fi
150    LDFLAGS="$tor_saved_LDFLAGS"
151   ]) dnl end cache check check for extra options.
153   if test "$tor_cv_library_$1_linker_option" != "(none)" ; then
154    LDFLAGS="$tor_cv_library_$1_linker_option $LDFLAGS"
155   fi
156 fi # cross-compile
158 ]) dnl end defun