]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
build: check if libevent as provided by pkg-config is working
authorVincent Bernat <bernat@luffy.cx>
Mon, 4 Feb 2013 07:38:08 +0000 (08:38 +0100)
committerVincent Bernat <bernat@luffy.cx>
Mon, 4 Feb 2013 07:38:08 +0000 (08:38 +0100)
If a user installs both libevent 2.0.x and libevent 1.4.x, pkg-config
may report libevent 2.0.x where it really is 1.4.x. The system is
broken in this case but we work-around this by using the shipped
libevent.

configure.ac
m4/libevent.m4

index 4b73e0cc4d5acfbe7e8f51d8526d7a44ff75efd1..96e856f8090f54cd7b79d257c91064772d03f8c3 100644 (file)
@@ -186,7 +186,7 @@ AM_CONDITIONAL([USE_XML], [test x"$with_xml" = x"yes"])
 AM_CONDITIONAL([USE_JSON], [test x"$with_json" = x"yes"])
 AC_OUTPUT
 
-if test x"$LIBEVENT_LDFLAGS" = x; then
+if test x"$LIBEVENT_EMBEDDED" = x; then
    libevent=system
 else
    libevent=embedded
index a08f52e0d7a8568299dde84ade553135dcfc9630..7ce59b84741a174da8a3766244b180c7339fd427 100644 (file)
@@ -4,19 +4,43 @@
 
 AC_DEFUN([lldp_CHECK_LIBEVENT], [
   # First, try with pkg-config
-  PKG_CHECK_MODULES([LIBEVENT], [libevent >= 2.0.5], [], [
+  PKG_CHECK_MODULES([LIBEVENT], [libevent >= 2.0.5], [
+       # Check if we have a working libevent
+       AC_MSG_CHECKING([if system libevent works as expected])
+       _save_CFLAGS="$CFLAGS"
+       _save_LIBS="$LIBS"
+       CFLAGS="$CFLAGS $LIBEVENT_CFLAGS"
+       LIBS="$LIBS $LIBEVENT_LIBS"
+       AC_TRY_LINK([
+@%:@include <sys/time.h>
+@%:@include <sys/types.h>
+@%:@include <event2/event.h>], [ struct event_base *base = event_base_new(); event_new(base, -1, 0, NULL, NULL); ],
+       [
+         AC_MSG_RESULT([yes])
+       ], [
+         AC_MSG_RESULT([no, using shipped libevent])
+         LIBEVENT_EMBEDDED=1
+       ])
+       CFLAGS="$_save_CFLAGS"
+       LIBS="$_save_LIBS"
+  ], [
     # No appropriate version, let's use the shipped copy
     AC_MSG_NOTICE([using shipped libevent])
+    LIBEVENT_EMBEDDED=1
+  ])
+
+  if test x"$LIBEVENT_EMBEDDED" != x; then
+    unset LIBEVENT_LIBS
     LIBEVENT_CFLAGS="-I\$(top_srcdir)/libevent/include -I\$(top_builddir)/libevent/include"
     LIBEVENT_LDFLAGS="\$(top_builddir)/libevent/libevent.la"
-  ])
+  fi
 
   # Override configure arguments
   ac_configure_args="$ac_configure_args --disable-libevent-regress --disable-thread-support --disable-openssl"
   ac_configure_args="$ac_configure_args --disable-malloc-replacement --disable-debug-mode --enable-function-sections"
   ac_configure_args="$ac_configure_args --disable-shared --enable-static"
   AC_CONFIG_SUBDIRS([libevent])
-  AM_CONDITIONAL([LIBEVENT_EMBEDDED], [test x"$LIBEVENT_LDFLAGS" != x])
+  AM_CONDITIONAL([LIBEVENT_EMBEDDED], [test x"$LIBEVENT_EMBEDDED" != x])
   AC_SUBST([LIBEVENT_LIBS])
   AC_SUBST([LIBEVENT_CFLAGS])
   AC_SUBST([LIBEVENT_LDFLAGS])