]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Ship an embedded copy of libevent.
authorVincent Bernat <bernat@luffy.cx>
Wed, 2 May 2012 10:50:09 +0000 (12:50 +0200)
committerVincent Bernat <bernat@luffy.cx>
Wed, 2 May 2012 11:05:33 +0000 (13:05 +0200)
This embedded copy will only be used if no system libevent is
available.

Makefile.am
README.md
configure.ac
libevent [new submodule]
m4/libevent.m4
src/Makefile.am
tests/Makefile.am

index 95c71db382ea6be6f5d778954e2c81d74cd8b825..1e9f76a8b1550fa9add2bd711cddbb448cee2b46 100644 (file)
@@ -1,3 +1,4 @@
 ACLOCAL_AMFLAGS = -I m4
 SUBDIRS = src man tests
+DIST_SUBDIRS = $(SUBDIRS) libevent
 dist_doc_DATA = README.md CHANGELOG
index caf0bdaeebc2f82102b00bb752ca7419acb950e4..af33f27ebc6851e6546920a46742290c6ee24b76 100644 (file)
--- 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
index 6413a59c824407c6609c2fb82085467194f60082..71ef10dbf72b1d05c1db3fda4be3c86bce92bce9 100644 (file)
@@ -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 <<EOF
 
 ------------------ Summary ------------------
@@ -185,6 +190,7 @@ cat <<EOF
   Prefix.........: $prefix
   C Compiler.....: $CC $CFLAGS $CPPFLAGS
   Linker.........: $LD $LDFLAGS $LIBS
+  Libevent.......: $libevent
  Optional features:
   SNMP support...: ${with_snmp-no}
   CDP............: $enable_cdp
diff --git a/libevent b/libevent
new file mode 160000 (submodule)
index 0000000..9fbfe9b
--- /dev/null
+++ b/libevent
@@ -0,0 +1 @@
+Subproject commit 9fbfe9b94838cea245472b5619dc4a111fb0dd30
index 0d056c0fa3fe4cfab03e212283e0d68d863dfab4..9457d55862b9468e19e409a6986131fc63ea9572 100644 (file)
@@ -8,105 +8,21 @@ AC_DEFUN([lldp_CHECK_LIBEVENT], [
   _save_CFLAGS="$CFLAGS"
 
   # First, try with pkg-config
-  PKG_CHECK_MODULES([LIBEVENT], [libevent >= 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 <sys/time.h>
-@%:@include <sys/types.h>
-@%:@include <event2/event.h>], [ 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])
 ])
index 4d3a63159362fe4a4022267a5935721979d7340a..febb010149b21919a2b28d6bc4487f7d126c444f 100644 (file)
@@ -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
index f1135a9b3c7fa60993df92aca646576d8f98620d..3f37cb555aee2cb76d3ba10665f8311689c2b374 100644 (file)
@@ -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