minor patches from Christian Brueffer
[tor.git] / acinclude.m4
blob7f27afd5a36b895409cf8d16d4abf5f51bb83e4b
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 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 $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 $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:optionname, 8:searchextra)
75 AC_DEFUN([TOR_SEARCH_LIBRARY], [
76 try$1dir=""
77 AC_ARG_WITH($1-dir,
78   [  --with-$1-dir=PATH    Specify path to $1 installation ],
79   [
80      if test x$withval != xno ; then
81         try$1dir="$withval"
82      fi
83   ])
84 tor_saved_LIBS="$LIBS"
85 tor_saved_LDFLAGS="$LDFLAGS"
86 tor_saved_CPPFLAGS="$CPPFLAGS"
87 AC_CACHE_CHECK([for $1 directory], tor_cv_library_$1_dir, [
88   tor_$1_dir_found=no
89   tor_$1_any_linkable=no
91   for tor_trydir in "$try$1dir" "(system)" "$prefix" /usr/local /usr/pkg $8; do
92     LDFLAGS="$tor_saved_LDFLAGS"
93     LIBS="$tor_saved_LIBS $3"
94     CPPFLAGS="$tor_saved_CPPFLAGS"
96     if test -z "$tor_trydir" ; then
97       continue;
98     fi
100     # Skip the directory if it isn't there.
101     if test ! -d "$tor_trydir" && test "$tor_trydir" != "(system)"; then
102       continue;
103     fi
105     # If this isn't blank, try adding the directory (or appropriate
106     # include/libs subdirectories) to the command line.
107     if test "$tor_trydir" != "(system)"; then
108       TOR_EXTEND_CODEPATH($tor_trydir)
109     fi
111     # Can we link against (but not necessarily run, or find the headers for)
112     # the binary?
113     AC_LINK_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
114                    [linkable=yes], [linkable=no])
116     if test "$linkable" = yes; then
117       tor_$1_any_linkable=yes
118       # Okay, we can link against it.  Can we find the headers?
119       AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$4], [$6]),
120                         [buildable=yes], [buildable=no])
121       if test "$buildable" = yes; then
122          tor_cv_library_$1_dir=$tor_trydir
123          tor_$1_dir_found=yes
124          break
125       fi
126     fi
127   done
129   if test "$tor_$1_dir_found" = no; then
130     if test "$tor_$1_any_linkable" = no ; then
131       AC_MSG_WARN([Could not find a linkable $1.  If you have it installed somewhere unusal, you can specify an explicit path using $7])
132       TOR_WARN_MISSING_LIB($1, pkg)
133       AC_MSG_ERROR([Missing libraries; unable to proceed.])
134     else
135       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.])
136       TOR_WARN_MISSING_LIB($1, devpkg)
137       AC_MSG_ERROR([Missing headers; unable to proceed.])
138     fi
139   fi
141   LDFLAGS="$tor_saved_LDFLAGS"
142   LIBS="$tor_saved_LIBS"
143   CPPFLAGS="$tor_saved_CPPFLAGS"
144 ]) dnl end cache check
146 LIBS="$LIBS $3"
147 if test "$tor_cv_library_$1_dir" != "(system)"; then
148    TOR_EXTEND_CODEPATH($tor_cv_library_$1_dir)
151 TOR_DEFINE_CODEPATH($tor_cv_library_$1_dir, $1)
153 if test "$cross_compiling" != yes; then
154   AC_CACHE_CHECK([whether we need extra options to link $1],
155                  tor_cv_library_$1_linker_option, [
156    orig_LDFLAGS="$LDFLAGS"
157    runs=no
158    linked_with=nothing
159    if test -d "$tor_cv_library_$1_dir/lib"; then
160      tor_trydir="$tor_cv_library_$1_dir/lib"
161    else
162      tor_trydir="$tor_cv_library_$1_dir"
163    fi
164    for tor_tryextra in "(none)" "-Wl,-R$tor_trydir" "-R$tor_trydir" \
165                        "-Wl,-rpath,$tor_trydir" ; do
166      if test "$tor_tryextra" = "(none)"; then
167        LDFLAGS="$orig_LDFLAGS"
168      else
169        LDFLAGS="$tor_tryextra $orig_LDFLAGS"
170      fi
171      AC_RUN_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
172                    [runnable=yes], [runnable=no])
173      if test "$runnable" = yes; then
174         tor_cv_library_$1_linker_option=$tor_tryextra
175         break
176      fi
177    done
179    if test "$runnable" = no; then
180      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}])
181    fi
182    LDFLAGS="$orig_LDFLAGS"
183   ]) dnl end cache check check for extra options.
185   if test "$tor_cv_library_$1_linker_option" != "(none)" ; then
186     TOR_LDFLAGS_$1="$TOR_LDFLAGS_$1 $tor_cv_library_$1_linker_option"
187   fi
188 fi # cross-compile
190 LIBS="$tor_saved_LIBS"
191 LDFLAGS="$tor_saved_LDFLAGS"
192 CPPFLAGS="$tor_saved_CPPFLAGS"
194 ]) dnl end defun