r11596@catbus: nickm | 2007-01-30 01:43:40 -0500

Macro-ize our "search for a library and find out how to link against it" code.  This will help make our handling of libevent and openssl more similar, and with any luck better.  Not pushing to main branch until after 0.1.2.


svn:r9726
This commit is contained in:
Nick Mathewson 2007-03-04 19:47:34 +00:00
parent 70e5a83a77
commit 0e44371a33
2 changed files with 128 additions and 105 deletions

124
acinclude.m4 Normal file
View File

@ -0,0 +1,124 @@
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.
dnl
dnl TOR_SEARCH_LIBRARY(libname, withlocation, linkargs, headers, prototype,
dnl code, optionname)
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
for tor_trydir in "$2" "(system)" "$prefix" /usr/local /usr/pkg; do
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
# Can we link against (but not necessarily compile) the binary?
AC_LINK_IFELSE(AC_LANG_PROGRAM([$5], [$6]),
[linkable=yes], [linkable=no])
if test $linkable = yes; then
tor_$1_any_linkable=yes
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"
LIBS="$tor_saved_LIBS $3"
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"
tor_trydir="$tor_cv_library_$1_dir"
runs=no
linked_with=nothing
for tor_tryextra in "(none)" "-Wl,-R$tor_trydir" "-R$tor_trydir" \
"-Wl,-rpath,$le_libdir" ; do
if test "$tor_tryextra" = "(none)"; then
LDFLAGS="$saved_LDFLAGS"
else
LDFLAGS="$tor_tryextra $saved_LDFLAGS"
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
]) dnl check for extra options.
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
#XXXX Check for right version
#XXXX accept list of search paths as options

View File

@ -202,112 +202,11 @@ AC_CHECK_TYPE(u_int32_t, unsigned long)
AC_CHECK_TYPE(u_int16_t, unsigned short)
AC_CHECK_TYPE(u_int8_t, unsigned char)
AC_CACHE_CHECK([for libevent directory], tor_cv_libevent_dir, [
saved_LIBS="$LIBS"
saved_LDFLAGS="$LDFLAGS"
saved_CPPFLAGS="$CPPFLAGS"
le_found=no
for ledir in $trylibeventdir "" $prefix /usr/local /usr/pkg ; do
LDFLAGS="$saved_LDFLAGS"
if test $bwin32 = true; then
LIBS="$saved_LIBS -levent -lws2_32"
else
LIBS="$saved_LIBS -levent"
fi
# Skip the directory if it isn't there.
if test ! -z "$ledir" -a ! -d "$ledir" ; then
continue;
fi
if test ! -z "$ledir" ; then
if test -d "$ledir/lib" ; then
LDFLAGS="-L$ledir/lib $LDFLAGS"
else
LDFLAGS="-L$ledir $LDFLAGS"
fi
if test -d "$ledir/include" ; then
CPPFLAGS="-I$ledir/include $CPPFLAGS"
else
CPPFLAGS="-I$ledir $CPPFLAGS"
fi
fi
# Can I compile and link it?
AC_TRY_LINK([#include <sys/time.h>
TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $WS32lib], [
#include <sys/time.h>
#include <sys/types.h>
#include <event.h>], [ event_init(); ],
[ libevent_linked=yes ], [ libevent_linked=no ])
if test $libevent_linked = yes; then
if test ! -z "$ledir" ; then
tor_cv_libevent_dir=$ledir
else
tor_cv_libevent_dir="(system)"
fi
le_found=yes
break
fi
done
LIBS="$saved_LIBS"
LDFLAGS="$saved_LDFLAGS"
CPPFLAGS="$saved_CPPFLAGS"
if test $le_found = no ; then
AC_MSG_ERROR([Could not find a linkable libevent. You can specify an explicit path using --with-libevent-dir])
fi
])
if test $bwin32 = true; then
LIBS="$LIBS -levent -lws2_32"
else
LIBS="$LIBS -levent"
fi
if test $tor_cv_libevent_dir != "(system)"; then
if test -d "$tor_cv_libevent_dir/lib" ; then
LDFLAGS="-L$tor_cv_libevent_dir/lib $LDFLAGS"
le_libdir="$tor_cv_libevent_dir/lib"
else
LDFLAGS="-L$tor_cv_libevent_dir $LDFLAGS"
le_libdir="$tor_cv_libevent_dir"
fi
if test -d "$tor_cv_libevent_dir/include" ; then
CPPFLAGS="-I$tor_cv_libevent_dir/include $CPPFLAGS"
else
CPPFLAGS="-I$tor_cv_libevent_dir $CPPFLAGS"
fi
fi
if test -z "$CROSS_COMPILE"; then
AC_CACHE_CHECK([whether we need extra options to link libevent],
tor_cv_libevent_linker_option, [
saved_LDFLAGS="$LDFLAGS"
le_runs=no
linked_with=nothing
for le_extra in "" "-Wl,-R$le_libdir" "-R$le_libdir" "-Wl,-rpath,$le_libdir" ; do
LDFLAGS="$le_extra $saved_LDFLAGS"
AC_TRY_RUN([void *event_init(void);
int main(int c, char **v) {
event_init(); return 0;
}],
libevent_runs=yes, libevent_runs=no, libevent_runs=cross)
if test $libevent_runs != no ; then
if test -z "$le_extra" ; then
tor_cv_libevent_linker_option='(none)'
else
tor_cv_libevent_linker_option=$le_extra
fi
le_runs=yes
break
fi
done
if test $le_runs = no ; then
AC_MSG_ERROR([Found linkable libevent in $tor_cv_libevent_dir, but it doesn't run, even with -R. Maybe specify another using --with-libevent-dir?])
fi
LDFLAGS="$saved_LDFLAGS"
])
if test $tor_cv_libevent_linker_option != '(none)' ; then
LDFLAGS="$tor_cv_libevent_linker_option $LDFLAGS"
fi
fi
#include <event.h>], [void *event_init(void);],
[event_init(); exit(0);], [--with-libevent-dir])
dnl Now check for particular libevent functions.
AC_CHECK_FUNCS(event_get_version event_get_method event_set_log_callback)