From 1daca82702fbe97078698b9979384853e5020326 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Fri, 27 Jan 2012 12:30:41 +0100 Subject: [PATCH] configure: upgrade to libevent 2.x Also, when linking with a static version of libevent, we enforce the use of libtool ".la" file instead of ".a" to get appropriate dependencies automatically and avoid a warning when linking inside a ".la". --- README.md | 22 +++++++++------------- m4/libevent.m4 | 49 ++++++++++++++++++++++++++++++------------------- src/Makefile.am | 2 +- 3 files changed, 40 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 92c11c48..2805f052 100644 --- a/README.md +++ b/README.md @@ -28,28 +28,24 @@ To compile lldpd, use the following: make sudo make install -You need libevent that you can grab from -http://www.monkey.org/~provos/libevent/ or install from your package -system (libevent-dev for Debian/Ubuntu and libevent-devel for -Redhat/Fedora/CentOS/SuSE). - -You can also compile libevent statically: - - ./configure --with-libevent=/usr/lib/libevent.a +You need libevent that you can grab from http://libevent.org or +install from your package system (libevent-dev for Debian/Ubuntu and +libevent-devel for Redhat/Fedora/CentOS/SuSE). If your system does not have libevent, here is a quick howto to download it and compile it statically into lldpd: # Grab and compile libevent - wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz - tar zxvf libevent-1.4.13-stable.tar.gz - cd libevent-1.4.13-stable - ./configure + wget https://github.com/downloads/libevent/libevent/libevent-2.0.16-stable.tar.gz + tar zxvf libevent-2.0.16-stable.tar.gz + cd libevent-2.0.16-stable + ./configure --prefix=$PWD/usr/local --enable-static --disable-shared make + make install # Compile lldpd with static linking cd .. - ./configure --with-libevent=libevent-1.4.13-stable/usr/local/lib/libevent.a + ./configure --with-libevent=libevent-2.0.16-stable/usr/local/lib/libevent.la make sudo make install diff --git a/m4/libevent.m4 b/m4/libevent.m4 index 9e691db6..acfe1eb8 100644 --- a/m4/libevent.m4 +++ b/m4/libevent.m4 @@ -3,34 +3,39 @@ # AC_DEFUN([lldp_CHECK_LIBEVENT], [ - LIBEVENT_URL=http://www.monkey.org/~provos/libevent/ - - AC_MSG_CHECKING([how to compile with libevent]) + LIBEVENT_URL=http://libevent.org/ _save_LIBS="$LIBS" _save_CFLAGS="$CFLAGS" + _save_CC="$CC" + + # First, try with pkg-config + PKG_CHECK_MODULES([LIBEVENT], [libevent >= 2.0.5], [], [:]) + + AC_MSG_CHECKING([how to compile with libevent]) if test x"$1" = x -o x"$1" = x"yes"; then - # Nothing specified, use default location - LIBEVENT_LIBS="-levent" + # Nothing specified, use default location from pkg-config + : else + # Black magic.... if test -d "$1"; then + libevent_dir=`readlink -f "$1"` # Directory, dynamic linking - if test -d "$1/lib"; then - LIBEVENT_LIBS="-L$1/lib -levent" + if test -d "${libevent_dir}/lib"; then + LIBEVENT_LIBS="-L${libevent_dir}/lib -levent" else - LIBEVENT_LIBS="-L$1 -levent" + LIBEVENT_LIBS="-L${libevent_dir} -levent" fi - if test -d "$1/include"; then - LIBEVENT_CFLAGS="-I$1/include" + if test -d "${libevent_dir}/include"; then + LIBEVENT_CFLAGS="-I${libevent_dir}/include" else - LIBEVENT_CFLAGS="-I$1" + LIBEVENT_CFLAGS="-I${libevent_dir}" fi else if test -f "$1"; then - # Static linking is a bit difficult, we need to "guess dependencies" - LIBEVENT_LIBS="$1 -lrt" + LIBEVENT_LIBS=`readlink -f "$1"` dir=`AS_DIRNAME(["$1"])` for includedir in "$dir/include" "$dir/../include" "$dir"; do if test -d "$includedir"; then - LIBEVENT_CFLAGS="-I$includedir" + LIBEVENT_CFLAGS=-I`readlink -f "$includedir"` break fi done @@ -41,26 +46,32 @@ AC_DEFUN([lldp_CHECK_LIBEVENT], [ fi fi - # Can I compile and link it? + # Can I compile and link it? We need to use libtool LIBS="$LIBS $LIBEVENT_LIBS" CFLAGS="$LIBEVENT_CFLAGS $CFLAGS" + CC="${SHELL-/bin/sh} libtool link $CC" AC_TRY_LINK([ @%:@include @%:@include -@%:@include ], [ event_init(); ], +@%:@include ], [ event_base_new(); ], [ libevent_linked=yes ], [ libevent_linked=no ]) if test x"$libevent_linked" = x"yes"; then AC_SUBST([LIBEVENT_LIBS]) AC_SUBST([LIBEVENT_CFLAGS]) - AC_MSG_RESULT([ok with "$LIBEVENT_LIBS $LIBEVENT_CFLAGS"]) + AC_MSG_RESULT([ok with $LIBEVENT_LIBS $LIBEVENT_CFLAGS]) else - AC_MSG_RESULT([failed with "$LIBEVENT_LIBS $LIBEVENT_CFLAGS"]) + if test x"$LIBEVENT_LIBS" = x; then + AC_MSG_RESULT([no libevent]) + else + AC_MSG_RESULT([failed with $LIBEVENT_LIBS $LIBEVENT_CFLAGS]) + fi AC_MSG_ERROR([ -*** libevent is required. Grab it from $LIBEVENT_URL +*** libevent 2.x is required. Grab it from $LIBEVENT_URL *** or install libevent-dev package]) fi + CC="$_save_CC" LIBS="$_save_LIBS" CFLAGS="$_save_CFLAGS" ]) diff --git a/src/Makefile.am b/src/Makefile.am index a6875f8d..a82a5f45 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,7 +13,7 @@ liblldpd_la_LIBADD = libcommon.la @LIBEVENT_LIBS@ # Add SNMP support if needed if USE_SNMP liblldpd_la_SOURCES += agent.c agent_priv.c agent.h -liblldpd_la_CFLAGS = @NETSNMP_CFLAGS@ +liblldpd_la_CFLAGS += @NETSNMP_CFLAGS@ liblldpd_la_LIBADD += @NETSNMP_LIBS@ endif -- 2.39.5