]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
configure: detect libedit without pkg-config
authorVincent Bernat <bernat@luffy.cx>
Sat, 5 Jan 2013 15:59:41 +0000 (16:59 +0100)
committerVincent Bernat <bernat@luffy.cx>
Sat, 5 Jan 2013 15:59:41 +0000 (16:59 +0100)
BSD comes with libedit shipped and without pkg-config being able to
detect it. Fallback to manual detection of the headers and check if we
can compile a program with it.

configure.ac
m4/libedit.m4 [new file with mode: 0644]

index 4b69dd351f5375402b4aed2cb51baf75ad0d75b9..cc0327eff8c72a4f670eab68c406e2ae2504aa2d 100644 (file)
@@ -101,7 +101,7 @@ PKG_CHECK_MODULES([CHECK], [check >= 0.9.4], [have_check=yes], [have_check=no])
 lldp_CHECK_LIBEVENT
 
 # editline
-PKG_CHECK_MODULES([EDITLINE], [libedit >= 2.9])
+lldp_CHECK_EDITLINE
 
 #######################
 ### Options
diff --git a/m4/libedit.m4 b/m4/libedit.m4
new file mode 100644 (file)
index 0000000..10d67fb
--- /dev/null
@@ -0,0 +1,40 @@
+#
+# lldp_CHECK_EDITLINE
+#
+
+AC_DEFUN([lldp_CHECK_EDITLINE], [
+  _save_LIBS="$LIBS"
+  _save_CFLAGS="$CFLAGS"
+
+  # First, try with pkg-config
+  PKG_CHECK_MODULES([EDITLINE], [libedit >= 2.9], [], [
+    # Nothing appropriate. Maybe it is installed anyway.
+    AC_CHECK_HEADER([histedit.h], [],
+      [AC_MSG_ERROR([*** unable to find editline/libedit])])
+    EDITLINE_CFLAGS=""
+    EDITLINE_LIBS="-ledit -lcurses"
+  ])
+
+  # Check if everything works as expected
+  LIBS="$LIBS $EDITLINE_LIBS"
+  CFLAGS="$CFLAGS $EDITLINE_CFLAGS"
+  AC_MSG_CHECKING([if libedit version is compatible])
+  AC_COMPILE_IFELSE(
+    [AC_LANG_PROGRAM([[
+@%:@include <stdlib.h>
+@%:@include <histedit.h>
+    ]], [[
+int i = H_SETSIZE; (void)i;
+el_init("", NULL, NULL, NULL);
+exit(0);
+    ]])],
+    [ AC_MSG_RESULT([yes]) ],
+    [ AC_MSG_RESULT([no])
+      AC_MSG_ERROR([*** libedit does not work as expected])])])
+
+  LIBS="$_save_LIBS"
+  CFLAGS="$_save_CFLAGS"
+
+  AC_SUBST([EDITLINE_CFLAGS])
+  AC_SUBST([EDITLINE_LIBS])
+])