From: Vincent Bernat Date: Thu, 1 Jul 2010 09:29:48 +0000 (+0200) Subject: Integration of libevent into the build system. X-Git-Tag: 0.6.0~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8beb9a73b6248e04053e5e25e497cbe578f7e303;p=thirdparty%2Flldpd.git Integration of libevent into the build system. "configure" will check that libevent is present. It is possible to use --with-libevent option to tell where libevent lives. We include the possibility to use a static copy of libevent but with the absence of a .pc file, we are not sure to handle all the dependencies correctly. README file is updated with instructions about libevent, including steps to build libevent inside lldpd. --- diff --git a/README.md b/README.md index b28b1610..92c11c48 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,31 @@ 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 + +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 + make + + # Compile lldpd with static linking + cd .. + ./configure --with-libevent=libevent-1.4.13-stable/usr/local/lib/libevent.a + make + sudo make install + If it complains about a missing agent/struct.h, your installation of Net-SNMP is incomplete. The easiest way to fix this is to provide an empty struct.h: diff --git a/configure.ac b/configure.ac index 3c85065b..9f0af928 100644 --- a/configure.ac +++ b/configure.ac @@ -211,6 +211,7 @@ if test x"$with_snmp" = x"yes"; then lldp_CHECK_SNMP fi +# XML AC_ARG_WITH([xml], AC_HELP_STRING( [--with-xml], @@ -220,6 +221,10 @@ if test x"$with_xml" = x"yes"; then lldp_CHECK_XML2 fi +# Libevent +lldp_ARG_WITH([libevent], [Location of libevent directory (or libevent.a)], []) +lldp_CHECK_LIBEVENT([$with_libevent]) + # Privsep settings lldp_ARG_WITH([privsep-user], [Which user to use for privilege separation], [_lldpd]) lldp_ARG_WITH([privsep-group], [Which group to use for privilege separation], [_lldpd]) diff --git a/m4/libevent.m4 b/m4/libevent.m4 new file mode 100644 index 00000000..9e691db6 --- /dev/null +++ b/m4/libevent.m4 @@ -0,0 +1,66 @@ +# +# lldp_CHECK_LIBEVENT +# + +AC_DEFUN([lldp_CHECK_LIBEVENT], [ + LIBEVENT_URL=http://www.monkey.org/~provos/libevent/ + + AC_MSG_CHECKING([how to compile with libevent]) + _save_LIBS="$LIBS" + _save_CFLAGS="$CFLAGS" + if test x"$1" = x -o x"$1" = x"yes"; then + # Nothing specified, use default location + LIBEVENT_LIBS="-levent" + else + if test -d "$1"; then + # Directory, dynamic linking + if test -d "$1/lib"; then + LIBEVENT_LIBS="-L$1/lib -levent" + else + LIBEVENT_LIBS="-L$1 -levent" + fi + if test -d "$1/include"; then + LIBEVENT_CFLAGS="-I$1/include" + else + LIBEVENT_CFLAGS="-I$1" + fi + else if test -f "$1"; then + # Static linking is a bit difficult, we need to "guess dependencies" + LIBEVENT_LIBS="$1 -lrt" + dir=`AS_DIRNAME(["$1"])` + for includedir in "$dir/include" "$dir/../include" "$dir"; do + if test -d "$includedir"; then + LIBEVENT_CFLAGS="-I$includedir" + break + fi + done + else + AC_MSG_RESULT(failed) + AC_MSG_ERROR([*** non-existant directory ($1) specified for libevent!]) + fi + fi + fi + + # Can I compile and link it? + LIBS="$LIBS $LIBEVENT_LIBS" + CFLAGS="$LIBEVENT_CFLAGS $CFLAGS" + AC_TRY_LINK([ +@%:@include +@%:@include +@%:@include ], [ event_init(); ], + [ 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"]) + else + AC_MSG_RESULT([failed with "$LIBEVENT_LIBS $LIBEVENT_CFLAGS"]) + AC_MSG_ERROR([ +*** libevent is required. Grab it from $LIBEVENT_URL +*** or install libevent-dev package]) + fi + + LIBS="$_save_LIBS" + CFLAGS="$_save_CFLAGS" +]) diff --git a/src/Makefile.am b/src/Makefile.am index 3778ab97..a6875f8d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,7 +8,8 @@ libcommon_la_LIBADD = @LTLIBOBJS@ ## Convenience library for lldpd and tests liblldpd_la_SOURCES = frame.h frame.c lldpd.c lldp.c cdp.c sonmp.c edp.c \ interfaces.c client.c priv.c privsep_fdpass.c dmi.c ctl-server.c -liblldpd_la_LIBADD = libcommon.la +liblldpd_la_CFLAGS = @LIBEVENT_CFLAGS@ +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