]> git.ipfire.org Git - thirdparty/lldpd.git/blobdiff - m4/libevent.m4
osx: sync homebrew formula
[thirdparty/lldpd.git] / m4 / libevent.m4
index e22a352b24b4a2aeb20a8da0cbf7deb50ff84540..275e5a5682f113a18e384ef3aaa5b2979e29c5dd 100644 (file)
@@ -3,23 +3,69 @@
 #
 
 AC_DEFUN([lldp_CHECK_LIBEVENT], [
-  LIBEVENT_URL=http://libevent.org/
-  _save_LIBS="$LIBS"
-  _save_CFLAGS="$CFLAGS"
+  # Do we require embedded libevent?
+  AC_ARG_WITH([embedded-libevent],
+    AS_HELP_STRING(
+      [--with-embedded-libevent],
+      [Use embedded libevent @<:@default=auto@:>@]
+  ), [], [with_embedded_libevent=auto])
+  if test x"$with_embedded_libevent" = x"yes"; then
+     LIBEVENT_EMBEDDED=1
+  else
+    # If not forced, check first with pkg-config
+    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])
+       ], [
+         if test x"$with_embedded_libevent" = x"auto"; then
+           AC_MSG_RESULT([no, using shipped libevent])
+           LIBEVENT_EMBEDDED=1
+         else
+           AC_MSG_ERROR([*** unusable system libevent])
+         fi
+       ])
+       CFLAGS="$_save_CFLAGS"
+       LIBS="$_save_LIBS"
+    ], [
+      # No appropriate version, let's use the shipped copy if possible
+      if test x"$with_embedded_libevent" = x"auto"; then
+        AC_MSG_NOTICE([using shipped libevent])
+        LIBEVENT_EMBEDDED=1
+      else
+        AC_MSG_ERROR([*** libevent not found])
+      fi
+    ])
+  fi
 
-  # First, try with pkg-config
-  PKG_CHECK_MODULES([LIBEVENT], [libevent >= 2.0.5], [], [
-    # No appropriate version, let's use the shipped copy
-    AC_MSG_NOTICE([using shipped libevent])
+  if test x"$LIBEVENT_EMBEDDED" != x; then
+    unset LIBEVENT_LIBS
     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"
-  ])
+  fi
 
-  # Override configure arguments
-  ac_configure_args="$ac_configure_args --disable-libevent-regress --disable-thread-support --disable-shared --enable-static"
-  AC_CONFIG_SUBDIRS([libevent])
-  AM_CONDITIONAL([LIBEVENT_EMBEDDED], [test x"$LIBEVENT_LDFLAGS" != x])
+  # Call ./configure in libevent. Need it for make dist...
+  libevent_configure_args="$libevent_configure_args --disable-libevent-regress"
+  libevent_configure_args="$libevent_configure_args --disable-thread-support"
+  libevent_configure_args="$libevent_configure_args --disable-openssl"
+  libevent_configure_args="$libevent_configure_args --disable-malloc-replacement"
+  libevent_configure_args="$libevent_configure_args --disable-debug-mode"
+  libevent_configure_args="$libevent_configure_args --enable-function-sections"
+  libevent_configure_args="$libevent_configure_args --disable-shared"
+  libevent_configure_args="$libevent_configure_args --with-pic"
+  libevent_configure_args="$libevent_configure_args --enable-static"
+  lldp_CONFIG_SUBDIRS([libevent], [$libevent_configure_args])
+
+  AM_CONDITIONAL([LIBEVENT_EMBEDDED], [test x"$LIBEVENT_EMBEDDED" != x])
   AC_SUBST([LIBEVENT_LIBS])
   AC_SUBST([LIBEVENT_CFLAGS])
   AC_SUBST([LIBEVENT_LDFLAGS])