From: Vincent Bernat Date: Sun, 10 May 2015 10:58:16 +0000 (+0200) Subject: build: automatic detection of optional features X-Git-Tag: 0.7.15~41 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fa9b12c57b7a9dd031a7cae678e795b755f341a9;p=thirdparty%2Flldpd.git build: automatic detection of optional features `./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`). --- diff --git a/NEWS b/NEWS index 0e28e2fa..b04b99cb 100644 --- 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. diff --git a/configure.ac b/configure.ac index a269751f..95a8eab4 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/m4/jansson.m4 b/m4/jansson.m4 index 770de2ad..291a177e 100644 --- a/m4/jansson.m4 +++ b/m4/jansson.m4 @@ -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 ]) diff --git a/m4/json-c.m4 b/m4/json-c.m4 index 4fa65faa..a107cfbd 100644 --- a/m4/json-c.m4 +++ b/m4/json-c.m4 @@ -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 ]) diff --git a/m4/snmp.m4 b/m4/snmp.m4 index 95e4786a..b820fdb2 100644 --- a/m4/snmp.m4 +++ b/m4/snmp.m4 @@ -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 @%:@include @%:@include -]) - # Do we have a usable header? - AC_CHECK_HEADERS([net-snmp/agent/util_funcs.h],,,[ + ]) + dnl Do we have a usable header? + AC_CHECK_HEADERS([net-snmp/agent/util_funcs.h],,,[ @%:@include @%:@include @%:@include @%:@include @%:@include - ]) + ]) + ],[ + 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 ]) diff --git a/m4/xml2.m4 b/m4/xml2.m4 index df040603..ecf99f51 100644 --- a/m4/xml2.m4 +++ b/m4/xml2.m4 @@ -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 @%:@include ],[ 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 ])