]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Integration of libevent into the build system.
authorVincent Bernat <bernat@luffy.cx>
Thu, 1 Jul 2010 09:29:48 +0000 (11:29 +0200)
committerVincent Bernat <bernat@luffy.cx>
Tue, 1 May 2012 09:09:41 +0000 (11:09 +0200)
"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.

README.md
configure.ac
m4/libevent.m4 [new file with mode: 0644]
src/Makefile.am

index b28b16102a9f14ae3b5e4defdc119e1c8e52504f..92c11c48aa3f3b316a079fd487c92e769b7b52e0 100644 (file)
--- 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:
index 3c85065b99bc6e0ef850326bce40781b7ec099c9..9f0af928ec51ec71ebbfd7446a8fd148c5f7b576 100644 (file)
@@ -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 (file)
index 0000000..9e691db
--- /dev/null
@@ -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 <sys/time.h>
+@%:@include <sys/types.h>
+@%:@include <event.h>], [ 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"
+])
index 3778ab974c7acf37717d00833dc59c06a7b6af8d..a6875f8d6c35edc254a081317c44fef06543f527 100644 (file)
@@ -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