]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
build: automatic detection of optional features
authorVincent Bernat <vincent@bernat.im>
Sun, 10 May 2015 10:58:16 +0000 (12:58 +0200)
committerVincent Bernat <vincent@bernat.im>
Sun, 10 May 2015 10:58:16 +0000 (12:58 +0200)
`./configure` can now detect optional features. This works with XML and
JSON output as well as for SNMP support. The defaults are still the
same, so a user has to pass `auto` keyword to the requested option (for
example `--with-json=auto`).

NEWS
configure.ac
m4/jansson.m4
m4/json-c.m4
m4/snmp.m4
m4/xml2.m4

diff --git a/NEWS b/NEWS
index 0e28e2fa159a41649f68085d52a6ea5d8c8fb73a..b04b99cb6e475ef411002442f37450f39fdbceec 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+lldpd (0.7.15)
+  * Features:
+    + Optional features can be configured with "auto" to autodetect if
+      they are usable.
+
 lldpd (0.7.14)
   * Features:
     + Shutdown LLPDU are sent on MSAP change and when lldpd exits.
index a269751f1c5fbc03303c9b3a1b68fdb1c5676a7f..95a8eab45d1bd2159dd6385adaae78215be03497 100644 (file)
@@ -164,12 +164,12 @@ m4_ifdef([PKG_INSTALLDIR], [PKG_INSTALLDIR],
 AC_ARG_WITH([readline],
   AS_HELP_STRING(
     [--with-readline],
-    [Enable the use of readline-like library @<:@default=check@:>@]),
+    [Enable the use of readline-like library @<:@default=auto@:>@]),
   [],
-  [with_readline=check])
+  [with_readline=auto])
 if test x"$with_readline" != x"no"; then
    AX_LIB_READLINE
-   if test x"$with_readline" != x"check"; then
+   if test x"$with_readline" != x"check" -a x"$with_readline" != x"auto"; then
      if test x"$ax_cv_lib_readline" = x"no"; then
        AC_MSG_FAILURE([*** no readline support found])
      fi
@@ -182,34 +182,40 @@ fi
 AC_ARG_WITH([snmp],
   AS_HELP_STRING(
     [--with-snmp],
-    [Enable the use of SNMP @<:@default=no@:>@]
-  ))
-if test x"$with_snmp" = x"yes"; then
-   lldp_CHECK_SNMP
-fi
+    [Enable the use of SNMP @<:@default=no@:>@]),
+  [],
+  [with_snmp=no])
+lldp_CHECK_SNMP
 
 # XML
 AC_ARG_WITH([xml],
   AS_HELP_STRING(
     [--with-xml],
-    [Enable XML output via libxml2 @<:@default=no@:>@]
-  ))
-if test x"$with_xml" = x"yes"; then
-   lldp_CHECK_XML2
-fi
+    [Enable XML output via libxml2 @<:@default=no@:>@]),
+  [],
+  [with_xml=no])
+lldp_CHECK_XML2
 
 # JSON
 AC_ARG_WITH([json],
   AS_HELP_STRING(
     [--with-json],
-    [Enable JSON output via janson,json-c,no @<:@default=no@:>@]
-  ))
-if test x"$with_json" = x"yes"; then
-   with_json=jansson
-fi
-if test x"$with_json" = x"jansson"; then
+    [Enable JSON output via janson,json-c,no @<:@default=no@:>@]),
+  [],
+  [with_json=no])
+if test x"$with_json" = x"yes" -o x"$with_json" = x"auto"; then
+   _with_json="$with_json"
+   with_json=auto
+   lldp_CHECK_JANSSON
+   if test x"$with_json" = x"no"; then
+     with_json=auto
+     lldp_CHECK_JSONC
+   fi
+   if test x"$with_json" = x"no" -a x"$_with_json" = x"yes"; then
+     AC_MSG_FAILURE([*** no JSON support found])
+   fi
+else
    lldp_CHECK_JANSSON
-elif test x"$with_json" = x"json-c"; then
    lldp_CHECK_JSONC
 fi
 
index 770de2ad9844c5b7c2b796393332694ddec0301e..291a177e564bd0ade73b0bfd660d40182da3ba65 100644 (file)
@@ -3,11 +3,18 @@
 #
 
 AC_DEFUN([lldp_CHECK_JANSSON], [
-   PKG_CHECK_MODULES([JANSSON], [jansson >= 2], [],
-      [AC_MSG_ERROR([*** unable to find libjansson])])
-
-   AC_SUBST([JANSSON_LIBS])
-   AC_SUBST([JANSSON_CFLAGS])
-   AC_DEFINE_UNQUOTED([USE_JSON], 1, [Define to indicate to enable JSON support])
-   AC_DEFINE_UNQUOTED([USE_JANSSON], 1, [Define to indicate to enable JSON support through jansson])
+ if test x"$with_json" = x"auto" -o x"$with_json" = x"jansson"; then
+   PKG_CHECK_MODULES([JANSSON], [jansson >= 2], [
+     AC_SUBST([JANSSON_LIBS])
+     AC_SUBST([JANSSON_CFLAGS])
+     AC_DEFINE_UNQUOTED([USE_JSON], 1, [Define to indicate to enable JSON support])
+     AC_DEFINE_UNQUOTED([USE_JANSSON], 1, [Define to indicate to enable JSON support through jansson])
+     with_json=jansson
+   ],[
+     if test x"$with_json" = x"jansson"; then
+       AC_MSG_ERROR([*** unable to find libjansson])
+     fi
+     with_json=no
+   ])
+ fi
 ])
index 4fa65faacf69981df51af5ed89851451beca0f7b..a107cfbd7daea43951862ec3d9f71c242a701e14 100644 (file)
@@ -3,12 +3,26 @@
 #
 
 AC_DEFUN([lldp_CHECK_JSONC], [
-   PKG_CHECK_MODULES([JSONC], [json-c], [],
-      [PKG_CHECK_MODULES([JSONC], [json], [],
-        [AC_MSG_ERROR([*** unable to find json-c])])])
-
-   AC_SUBST([JSONC_LIBS])
-   AC_SUBST([JSONC_CFLAGS])
-   AC_DEFINE_UNQUOTED([USE_JSON], 1, [Define to indicate to enable JSON support])
-   AC_DEFINE_UNQUOTED([USE_JSONC], 1, [Define to indicate to enable JSON via json-c support])
+ if test x"$with_json" = x"auto" -o x"$with_json" = x"json-c"; then
+   PKG_CHECK_MODULES([JSONC], [json-c], [
+     AC_SUBST([JSONC_LIBS])
+     AC_SUBST([JSONC_CFLAGS])
+     AC_DEFINE_UNQUOTED([USE_JSON], 1, [Define to indicate to enable JSON support])
+     AC_DEFINE_UNQUOTED([USE_JSONC], 1, [Define to indicate to enable JSON via json-c support])
+     with_json=json-c
+   ],[
+     PKG_CHECK_MODULES([JSONC], [json], [
+       AC_SUBST([JSONC_LIBS])
+       AC_SUBST([JSONC_CFLAGS])
+       AC_DEFINE_UNQUOTED([USE_JSON], 1, [Define to indicate to enable JSON support])
+       AC_DEFINE_UNQUOTED([USE_JSONC], 1, [Define to indicate to enable JSON via json-c support])
+       with_json=json-c
+     ],[
+       if test x"$with_json" = x"json-c"; then
+         AC_MSG_ERROR([*** unable to find json-c])
+       fi
+       with_json=no
+     ])
+   ])
+ fi
 ])
index 95e4786a8b3f185875fdcc38df73cc353ece102f..b820fdb2759856288ab081425fbf0230373299fd 100644 (file)
@@ -2,55 +2,79 @@
 # lldp_CHECK_SNMP
 #
 AC_DEFUN([lldp_CHECK_SNMP], [
+  if test x"$with_snmp" != x"no"; then
    AC_PATH_TOOL([NETSNMP_CONFIG], [net-snmp-config], [no])
    if test x"$NETSNMP_CONFIG" = x"no"; then
-      AC_MSG_ERROR([*** unable to find net-snmp-config])
-   fi
-   NETSNMP_LIBS=`${NETSNMP_CONFIG} --agent-libs`
-   NETSNMP_CFLAGS="`${NETSNMP_CONFIG} --base-cflags` -DNETSNMP_NO_INLINE"
+      dnl No luck
+      if test x"$with_snmp" = x"yes"; then
+         AC_MSG_FAILURE([*** no NetSNMP support found])
+      fi
+      with_snmp=no
+   else
+      dnl Check it is working as expected
+      NETSNMP_LIBS=`${NETSNMP_CONFIG} --agent-libs`
+      NETSNMP_CFLAGS="`${NETSNMP_CONFIG} --base-cflags` -DNETSNMP_NO_INLINE"
 
-   _save_flags="$CFLAGS"
-   _save_libs="$LIBS"
-   CFLAGS="$CFLAGS ${NETSNMP_CFLAGS}"
-   LIBS="$LIBS ${NETSNMP_LIBS}"
-   AC_MSG_CHECKING([whether C compiler supports flag "${NETSNMP_CFLAGS} ${NETSNMP_LIBS}" from Net-SNMP])
-   AC_LINK_IFELSE([AC_LANG_PROGRAM([
+      _save_flags="$CFLAGS"
+      _save_libs="$LIBS"
+      CFLAGS="$CFLAGS ${NETSNMP_CFLAGS}"
+      LIBS="$LIBS ${NETSNMP_LIBS}"
+      AC_MSG_CHECKING([whether C compiler supports flag "${NETSNMP_CFLAGS} ${NETSNMP_LIBS}" from Net-SNMP])
+      AC_LINK_IFELSE([AC_LANG_PROGRAM([
 int main(void);
 ],
 [
 {
   return 0;
 }
-])],[AC_MSG_RESULT(yes)],[
-AC_MSG_RESULT(no)
-AC_MSG_ERROR([*** incorrect CFLAGS from net-snmp-config])])
-   # Is Net-SNMP usable?
-   AC_CHECK_LIB([netsnmp], [snmp_register_callback], [:],
-       [AC_MSG_ERROR([*** unable to use net-snmp])], ${NETSNMP_LIBS})
-   # Do we have subagent support?
-   AC_CHECK_FUNCS([netsnmp_enable_subagent], [:],
-       [AC_MSG_ERROR([*** no subagent support in net-snmp])])
-
-   AC_SUBST([NETSNMP_LIBS])
-   AC_SUBST([NETSNMP_CFLAGS])
-   AC_DEFINE_UNQUOTED([USE_SNMP], 1, [Define to indicate to enable SNMP support])
+])],[
+        AC_MSG_RESULT(yes)
+        dnl Is Net-SNMP usable?
+        AC_CHECK_LIB([netsnmp], [snmp_register_callback], [
+          dnl Do we have subagent support?
+          AC_CHECK_FUNCS([netsnmp_enable_subagent], [
+            dnl Yes, we need to check a few more things
+            AC_SUBST([NETSNMP_LIBS])
+            AC_SUBST([NETSNMP_CFLAGS])
+            AC_DEFINE_UNQUOTED([USE_SNMP], 1, [Define to indicate to enable SNMP support])
+            with_snmp=yes
 
-   # Should we use f_create_from_tstring_new or f_create_from_tstring?
-   AC_CHECK_MEMBERS([netsnmp_tdomain.f_create_from_tstring_new],,,
-       [
+            dnl Should we use f_create_from_tstring_new or f_create_from_tstring?
+            AC_CHECK_MEMBERS([netsnmp_tdomain.f_create_from_tstring_new],,,[
 @%:@include <net-snmp/net-snmp-config.h>
 @%:@include <net-snmp/net-snmp-includes.h>
 @%:@include <net-snmp/library/snmp_transport.h>
-])
-   # Do we have a usable <net-snmp/agent/util_funcs.h> header?
-   AC_CHECK_HEADERS([net-snmp/agent/util_funcs.h],,,[
+            ])
+            dnl Do we have a usable <net-snmp/agent/util_funcs.h> header?
+            AC_CHECK_HEADERS([net-snmp/agent/util_funcs.h],,,[
 @%:@include <net-snmp/net-snmp-config.h>
 @%:@include <net-snmp/net-snmp-includes.h>
 @%:@include <net-snmp/library/snmp_transport.h>
 @%:@include <net-snmp/agent/net-snmp-agent-includes.h>
 @%:@include <net-snmp/agent/snmp_vars.h>
-   ])
+            ])
+          ],[
+            if test x"$with_snmp" = x"yes"; then
+              AC_MSG_ERROR([*** no subagent support in net-snmp])
+            fi
+            with_snmp=no
+          ])
+        ],[
+          if test x"$with_snmp" = x"yes"; then
+            AC_MSG_ERROR([*** unable to use net-snmp])
+          fi
+          with_snmp=no
+        ])
+      ],[
+        AC_MSG_RESULT(no)
+        if test x"$with_snmp" = x"yes"; then
+          AC_MSG_ERROR([*** incorrect CFLAGS from net-snmp-config])
+        fi
+        with_snmp=no
+      ])
 
-   CFLAGS="$_save_flags"
-   LIBS="$_save_libs"
+      CFLAGS="$_save_flags"
+      LIBS="$_save_libs"
+   fi
+  fi
 ])
index df0406031e2daa8908b13a32f2f0356b4168e058..ecf99f513c86dd27506d33bdd23e934a17811f05 100644 (file)
@@ -4,37 +4,53 @@
 
 
 AC_DEFUN([lldp_CHECK_XML2], [
-   PKG_CHECK_MODULES([XML2], [libxml-2.0], [],
-   [AC_MSG_CHECKING([presence of xml2-config])
+  if test x"$with_xml" != x"no"; then
+   PKG_CHECK_MODULES([XML2], [libxml-2.0], [
+    dnl Found through pkg-config
+    AC_DEFINE_UNQUOTED([USE_XML], 1, [Define to indicate to enable XML support])
+    with_xml=yes
+   ],[
+    dnl Fallback to xml2-config
     AC_PATH_TOOL([XML2_CONFIG], [xml2-config], [no])
     if test x"$XML2_CONFIG" = x"no"; then
-      AC_MSG_ERROR([*** unable to find xml2-config])
-    fi
-    XML2_LIBS=`${XML2_CONFIG} --libs`
-    XML2_CFLAGS=`${XML2_CONFIG} --cflags`
-    AC_MSG_RESULT([found!])
-   ])
+      dnl No luck
+      if test x"$with_xml" = x"yes"; then
+         AC_MSG_FAILURE([*** no libxml2 support found])
+      fi
+      with_xml=no
+    else
+      dnl Check that it's working as expected
+      XML2_LIBS=`${XML2_CONFIG} --libs`
+      XML2_CFLAGS=`${XML2_CONFIG} --cflags`
 
-   # Check if the library is usable
-   _save_flags="$CFLAGS"
-   _save_libs="$LIBS"
-   CFLAGS="$CFLAGS ${XML2_CFLAGS}"
-   LIBS="$LIBS ${XML2_LIBS}"
-   AC_MSG_CHECKING([whether libxml-2 work as expected])
-   AC_LINK_IFELSE([AC_LANG_PROGRAM([
+      _save_flags="$CFLAGS"
+      _save_libs="$LIBS"
+      CFLAGS="$CFLAGS ${XML2_CFLAGS}"
+      LIBS="$LIBS ${XML2_LIBS}"
+      AC_MSG_CHECKING([whether libxml-2 work as expected])
+      AC_LINK_IFELSE([AC_LANG_PROGRAM([
 @%:@include <libxml/encoding.h>
 @%:@include <libxml/xmlwriter.h>
 ],[
        xmlDocPtr doc;
        xmlTextWriterPtr xw = xmlNewTextWriterDoc(&doc, 0);
         return (xw != NULL);
-])],[AC_MSG_RESULT(yes)],[
-AC_MSG_RESULT(no)
-AC_MSG_ERROR([*** unable to use libxml-2])])
-   CFLAGS="$_save_flags"
-   LIBS="$_save_libs"
-
-   AC_SUBST([XML2_LIBS])
-   AC_SUBST([XML2_CFLAGS])
-   AC_DEFINE_UNQUOTED([USE_XML], 1, [Define to indicate to enable XML support])
+])],[
+        AC_MSG_RESULT(yes)
+        AC_SUBST([XML2_LIBS])
+        AC_SUBST([XML2_CFLAGS])
+        AC_DEFINE_UNQUOTED([USE_XML], 1, [Define to indicate to enable XML support])
+        with_xml=yes
+      ],[
+        AC_MSG_RESULT(no)
+        if test x"$with_xml" = x"yes"; then
+            AC_MSG_FAILURE([*** libxml2 not working as expected])
+        fi
+        with_xml=no
+      ])
+      CFLAGS="$_save_flags"
+      LIBS="$_save_libs"
+    fi
+   ])
+  fi
 ])