2007-03-04 20:47:34 +01:00
|
|
|
dnl $Id$
|
|
|
|
dnl Helper macros for Tor configure.in
|
|
|
|
dnl Copyright (c) 2001-2004, Roger Dingledine
|
|
|
|
dnl Copyright (c) 2004-2007, Roger Dingledine, Nick Mathewson
|
|
|
|
dnl See LICENSE for licensing information
|
|
|
|
|
|
|
|
AC_DEFUN([TOR_EXTEND_CODEPATH],
|
|
|
|
[
|
|
|
|
if test -d "$1/lib"; then
|
|
|
|
LDFLAGS="-L$1/lib $LDFLAGS"
|
|
|
|
else
|
|
|
|
LDFLAGS="-L$1 $LDFLAGS"
|
|
|
|
fi
|
|
|
|
if test -d "$1/include"; then
|
|
|
|
CPPFLAGS="-I$1/include $CPPFLAGS"
|
|
|
|
else
|
|
|
|
CPPFLAGS="-I$1 $CPPFLAGS"
|
|
|
|
fi
|
|
|
|
])
|
|
|
|
|
|
|
|
dnl Look for a library, and its associated includes, and how to link
|
|
|
|
dnl against it.
|
2007-03-10 08:38:42 +01:00
|
|
|
dnl
|
|
|
|
dnl TOR_SEARCH_LIBRARY(1:libname, 2:withlocation, 3:linkargs, 4:headers,
|
2007-03-06 21:25:32 +01:00
|
|
|
dnl 5:prototype,
|
|
|
|
dnl 6:code, 7:optionname, 8:searchextra)
|
2007-03-04 20:47:34 +01:00
|
|
|
|
|
|
|
AC_DEFUN([TOR_SEARCH_LIBRARY], [
|
|
|
|
tor_saved_LIBS="$LIBS"
|
|
|
|
tor_saved_LDFLAGS="$LDFLAGS"
|
|
|
|
tor_saved_CPPFLAGS="$CPPFLAGS"
|
|
|
|
AC_CACHE_CHECK([for $1 directory], tor_cv_library_$1_dir, [
|
|
|
|
tor_$1_dir_found=no
|
|
|
|
tor_$1_any_linkable=no
|
2007-03-10 08:38:42 +01:00
|
|
|
|
2007-03-04 20:47:53 +01:00
|
|
|
for tor_trydir in "$2" "(system)" "$prefix" /usr/local /usr/pkg $8; do
|
2007-03-04 20:47:34 +01:00
|
|
|
LDFLAGS="$tor_saved_LDFLAGS"
|
|
|
|
LIBS="$tor_saved_LIBS $3"
|
|
|
|
CPPFLAGS="$tor_saved_CPPFLAGS"
|
|
|
|
|
|
|
|
if test -z "$tor_trydir" ; then
|
|
|
|
continue;
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Skip the directory if it isn't there.
|
|
|
|
if test ! -d "$tor_trydir" -a "$tor_trydir" != "(system)"; then
|
|
|
|
continue;
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If this isn't blank, try adding the directory (or appropriate
|
|
|
|
# include/libs subdirectories) to the command line.
|
|
|
|
if test "$tor_trydir" != "(system)"; then
|
|
|
|
TOR_EXTEND_CODEPATH($tor_trydir)
|
|
|
|
fi
|
|
|
|
|
2007-03-10 08:38:42 +01:00
|
|
|
# Can we link against (but not necessarily run, or find the headers for)
|
|
|
|
# the binary?
|
2007-03-04 20:47:34 +01:00
|
|
|
AC_LINK_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
|
|
|
|
[linkable=yes], [linkable=no])
|
|
|
|
|
|
|
|
if test $linkable = yes; then
|
|
|
|
tor_$1_any_linkable=yes
|
2007-03-10 08:38:42 +01:00
|
|
|
# Okay, we can link against it. Can we find the headers?
|
2007-03-04 20:47:34 +01:00
|
|
|
AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$4], [$6]),
|
|
|
|
[buildable=yes], [buildable=no])
|
|
|
|
if test $buildable = yes; then
|
|
|
|
tor_cv_library_$1_dir=$tor_trydir
|
|
|
|
tor_$1_dir_found=yes
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if test $tor_$1_dir_found = no; then
|
|
|
|
if test $tor_$1_any_linkable = no ; then
|
|
|
|
AC_MSG_ERROR([Could not find a linkable $1. You can specify an explicit path using $7])
|
|
|
|
else
|
|
|
|
AC_MSG_ERROR([We found the libraries for $1, but we could not find the C header files. You may need to install a devel package.])
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
LDFLAGS="$tor_saved_LDFLAGS"
|
2007-03-06 21:25:32 +01:00
|
|
|
LIBS="$tor_saved_LIBS"
|
2007-03-04 20:47:34 +01:00
|
|
|
CPPFLAGS="$tor_saved_CPPFLAGS"
|
|
|
|
]) dnl end cache check
|
|
|
|
|
|
|
|
LIBS="$LIBS $3"
|
|
|
|
if test $tor_cv_library_$1_dir != "(system)"; then
|
|
|
|
TOR_EXTEND_CODEPATH($tor_cv_library_$1_dir)
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test -z "$CROSS_COMPILE"; then
|
|
|
|
AC_CACHE_CHECK([whether we need extra options to link $1],
|
|
|
|
tor_cv_library_$1_linker_option, [
|
|
|
|
tor_saved_LDFLAGS="$LDFLAGS"
|
|
|
|
runs=no
|
|
|
|
linked_with=nothing
|
2007-03-15 15:18:24 +01:00
|
|
|
if test -d "$tor_cv_library_$1_dir/lib"; then
|
|
|
|
tor_trydir="$tor_cv_library_$1_dir/lib"
|
|
|
|
else
|
|
|
|
tor_trydir="$tor_cv_library_$1_dir"
|
|
|
|
fi
|
2007-03-04 20:47:34 +01:00
|
|
|
for tor_tryextra in "(none)" "-Wl,-R$tor_trydir" "-R$tor_trydir" \
|
2007-03-06 21:25:32 +01:00
|
|
|
"-Wl,-rpath,$tor_trydir" ; do
|
2007-03-04 20:47:34 +01:00
|
|
|
if test "$tor_tryextra" = "(none)"; then
|
2007-03-06 21:25:32 +01:00
|
|
|
LDFLAGS="$tor_saved_LDFLAGS"
|
2007-03-04 20:47:34 +01:00
|
|
|
else
|
2007-03-06 21:25:32 +01:00
|
|
|
LDFLAGS="$tor_tryextra $tor_saved_LDFLAGS"
|
2007-03-04 20:47:34 +01:00
|
|
|
fi
|
|
|
|
AC_RUN_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
|
|
|
|
[runnable=yes], [runnable=no])
|
|
|
|
if test "$runnable" = yes; then
|
|
|
|
tor_cv_library_$1_linker_option=$tor_tryextra
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if test "$runnable" = no; then
|
|
|
|
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}])
|
|
|
|
fi
|
2007-03-06 21:25:32 +01:00
|
|
|
LDFLAGS="$tor_saved_LDFLAGS"
|
|
|
|
]) dnl end cache check check for extra options.
|
2007-03-04 20:47:34 +01:00
|
|
|
|
|
|
|
if test "$tor_cv_library_$1_linker_option" != "(none)" ; then
|
|
|
|
LDFLAGS="$tor_cv_library_$1_linker_option $LDFLAGS"
|
|
|
|
fi
|
|
|
|
fi # cross-compile
|
|
|
|
|
|
|
|
]) dnl end defun
|
|
|
|
|