From e5c9465245e44aa922673b5c9d579b7c3ad77834 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 2 May 2012 12:50:09 +0200 Subject: [PATCH] Ship an embedded copy of libevent. This embedded copy will only be used if no system libevent is available. --- Makefile.am | 1 + README.md | 10 +---- configure.ac | 14 ++++-- libevent | 1 + m4/libevent.m4 | 110 ++++++---------------------------------------- src/Makefile.am | 11 ++++- tests/Makefile.am | 2 +- 7 files changed, 38 insertions(+), 111 deletions(-) create mode 160000 libevent diff --git a/Makefile.am b/Makefile.am index 95c71db3..1e9f76a8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,4 @@ ACLOCAL_AMFLAGS = -I m4 SUBDIRS = src man tests +DIST_SUBDIRS = $(SUBDIRS) libevent dist_doc_DATA = README.md CHANGELOG diff --git a/README.md b/README.md index caf0bdae..af33f27e 100644 --- a/README.md +++ b/README.md @@ -32,14 +32,8 @@ 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 https://github.com/downloads/libevent/libevent/libevent-2.0.18-stable.tar.gz - ./configure --with-libevent=libevent-2.0.18-stable.tar.gz - make - sudo make install +If your system does not have libevent, ./configure will use the +shipped copy and compile it statically. 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 diff --git a/configure.ac b/configure.ac index 6413a59c..71ef10db 100644 --- a/configure.ac +++ b/configure.ac @@ -128,6 +128,9 @@ AC_CACHE_SAVE ## Unit tests wich check PKG_CHECK_MODULES([CHECK], [check >= 0.9.4], [have_check=yes], [have_check=no]) +# Libevent +lldp_CHECK_LIBEVENT([$with_libevent]) + ####################### ### Options @@ -151,10 +154,6 @@ if test x"$with_xml" = x"yes"; then lldp_CHECK_XML2 fi -# Libevent -lldp_ARG_WITH([libevent], [Location of libevent directory, la or archive], []) -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]) @@ -178,6 +177,12 @@ AM_CONDITIONAL([USE_SNMP], [test x"$with_snmp" = x"yes"]) AM_CONDITIONAL([USE_XML], [test x"$with_xml" = x"yes"]) AC_OUTPUT +if test x"$LIBEVENT_LDFLAGS" = x; then + libevent=system +else + libevent=embedded +fi + cat <= 1.4.3], [], [:]) + PKG_CHECK_MODULES([LIBEVENT], [libevent >= 2.0.5], [], [ + # No appropriate version, let's use the shipped copy + AC_MSG_NOTICE([using shipped libevent]) + LIBEVENT_CFLAGS="-I\$(top_srcdir)/libevent/include -I\$(top_builddir)/libevent/include" + LIBEVENT_LIBS="\$(top_builddir)/libevent/libevent.la" + LIBEVENT_LDFLAGS="\$(top_builddir)/libevent/libevent.la" + ]) - AC_MSG_CHECKING([how to compile with libevent]) - if test x"$1" = x -o x"$1" = x"yes"; then - # Nothing specified, use default location from pkg-config - LIBS="$LIBS $LIBEVENT_LIBS" - CFLAGS="$LIBEVENT_CFLAGS $CFLAGS" - AC_TRY_LINK([ -@%:@include -@%:@include -@%:@include ], [ event_base_new(); ], - [ libevent_linked=yes ], [ libevent_linked=no ]) - - if test x"$libevent_linked" = x"yes"; then - AC_MSG_RESULT([ok with $LIBEVENT_LIBS $LIBEVENT_CFLAGS]) - else - 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 2.x is required. Grab it from $LIBEVENT_URL - *** or install libevent-dev package]) - fi - LIBS="$_save_LIBS" - CFLAGS="$_save_CFLAGS" - else - # Black magic.... - if test -d "$1"; then - libevent_dir=`readlink -f "$1"` - # Directory, dynamic linking - if test -d "${libevent_dir}/lib"; then - LIBEVENT_LIBS="-L${libevent_dir}/lib -levent" - else - LIBEVENT_LIBS="-L${libevent_dir} -levent" - fi - if test -d "${libevent_dir}/include"; then - LIBEVENT_CFLAGS="-I${libevent_dir}/include" - else - LIBEVENT_CFLAGS="-I${libevent_dir}" - fi - else if test -f "$1"; then - case "$1" in - *.la) - 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`readlink -f "$includedir"` - break - fi - done - AC_MSG_RESULT([ok with $LIBEVENT_LIBS $LIBEVENT_CFLAGS]) - ;; - *.tar.gz) - # This won't work for cross compilation. Dunno how to handle this. - AC_MSG_RESULT([from archive $1]) - AC_MSG_CHECKING([compilation of libevent in $1]) - { - dir=`(umask 077 && mktemp -d "\`pwd\`/libeventXXXXXX") 2>/dev/null` && - test -d "$dir" - } || { - AC_MSG_RESULT([failed to create temporary directory]) - AC_MSG_ERROR([*** unable to compile libevent]) - } - gunzip -c "$1" | tar -C $dir -xf - - (exec >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD && - cd $dir/libevent* && - ./configure \ - --disable-libevent-regress \ - --disable-thread-support \ - --prefix=$dir/build --enable-static --disable-shared && - make && - make install) || { - AC_MSG_RESULT([failed to compile libevent]) - AC_MSG_ERROR([*** unable to compile libevent]) - } - LIBEVENT_LIBS=`readlink -f $dir/build/lib/libevent.la` - levdir=`AS_DIRNAME(["$LIBEVENT_LIBS"])` - test -d "$levdir/../include" || { - AC_MSG_RESULT([failed to locate static libevent.la]) - AC_MSG_ERROR([*** unable to compile libevent]) - } - LIBEVENT_CFLAGS=-I`readlink -f "$levdir/../include"` - AC_MSG_RESULT([successful!]) - ;; - *) - AC_MSG_RESULT(failed) - AC_MSG_ERROR([*** dunno what to do with $1]) - ;; - esac - else - AC_MSG_RESULT(failed) - AC_MSG_ERROR([*** non-existant directory/file/archive ($1) specified for libevent!]) - fi - fi + # Override configure arguments + ac_configure_args="$ac_configure_args --disable-libevent-regress --disable-thread-support --disable-shared --enable-static" + if test x"$LIBEVENT_LDFLAGS" != x; then + AC_CONFIG_SUBDIRS([libevent]) fi - + AM_CONDITIONAL([LIBEVENT_EMBEDDED], [test x"$LIBEVENT_LDFLAGS" != x]) AC_SUBST([LIBEVENT_LIBS]) AC_SUBST([LIBEVENT_CFLAGS]) + AC_SUBST([LIBEVENT_LDFLAGS]) ]) diff --git a/src/Makefile.am b/src/Makefile.am index 4d3a6315..febb0101 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,7 +19,7 @@ endif ## lldpd lldpd_SOURCES = main.c -lldpd_LDADD = liblldpd.la @LIBEVENT_LIBS@ +lldpd_LDADD = liblldpd.la @LIBEVENT_LDFLAGS@ ## lldpctl lldpctl_SOURCES = lldpctl.h lldpctl.c display.c writer.h text_writer.c kv_writer.c @@ -29,3 +29,12 @@ lldpctl_SOURCES += xml_writer.c lldpctl_CFLAGS = @XML2_CFLAGS@ lldpctl_LDADD += @XML2_LIBS@ endif + +## libevent +if LIBEVENT_EMBEDDED +event.c: $(top_builddir)/libevent/include/event2-config.h $(top_builddir)/libevent/libevent.la +$(top_builddir)/libevent/include/event2-config.h: $(top_builddir)/libevent/config.h + (cd $(top_builddir)/libevent && $(MAKE) include/event2/event-config.h) +$(top_builddir)/libevent/libevent.la: $(top_srcdir)/libevent/*.c $(top_srcdir)/libevent/*.h + (cd $(top_builddir)/libevent && $(MAKE) libevent.la) +endif diff --git a/tests/Makefile.am b/tests/Makefile.am index f1135a9b..3f37cb55 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -26,7 +26,7 @@ check_ifaddrs_SOURCES = check_ifaddrs.c \ $(top_srcdir)/src/getifaddrs.c AM_CFLAGS = @CHECK_CFLAGS@ -LDADD = $(top_builddir)/src/liblldpd.la @CHECK_LIBS@ @LIBEVENT_LIBS@ +LDADD = $(top_builddir)/src/liblldpd.la @CHECK_LIBS@ @LIBEVENT_LDFLAGS@ if USE_SNMP TESTS += check_snmp -- 2.39.5