From 6466fcb423f2a7f4af2a4558b9871488c5628671 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 27 May 2017 13:37:06 +0200 Subject: [PATCH] configure.ac: improve libnetsnmpagent detection Turn it into a separate check, which also makes it possible to disable it. snmp_agent and snmp are separate plugins, and on at least Fedora are packaged separately. A beneficial side effect is that this reduces overlinking of snmp.so with libnetsnmpagent.so --- Makefile.am | 6 ++-- configure.ac | 94 ++++++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 73 insertions(+), 27 deletions(-) diff --git a/Makefile.am b/Makefile.am index 37125bc7..fa85720f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1493,9 +1493,9 @@ endif if BUILD_PLUGIN_SNMP_AGENT pkglib_LTLIBRARIES += snmp_agent.la snmp_agent_la_SOURCES = src/snmp_agent.c -snmp_agent_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBNETSNMP_CPPFLAGS) -snmp_agent_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBNETSNMP_LDFLAGS) -snmp_agent_la_LIBADD = $(BUILD_WITH_LIBNETSNMP_LIBS) +snmp_agent_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBNETSNMPAGENT_CPPFLAGS) +snmp_agent_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBNETSNMPAGENT_LDFLAGS) +snmp_agent_la_LIBADD = $(BUILD_WITH_LIBNETSNMPAGENT_LIBS) endif if BUILD_PLUGIN_STATSD diff --git a/configure.ac b/configure.ac index 1751a93c..cbad867e 100644 --- a/configure.ac +++ b/configure.ac @@ -3769,7 +3769,6 @@ AC_SUBST([LIBNETAPP_LIBS]) # }}} # --with-libnetsnmp {{{ -with_libnetsnmpagent="no" AC_ARG_WITH([libnetsnmp], [AS_HELP_STRING([--with-libnetsnmp@<:@=PREFIX@:>@], [Path to libnetsnmp.])], [ @@ -3781,7 +3780,6 @@ AC_ARG_WITH([libnetsnmp], with_libnetsnmp_cppflags="-I$withval/include" with_libnetsnmp_ldflags="-I$withval/lib" with_libnetsnmp="yes" - with_libnetsnmpagent="yes" fi; fi ], [with_libnetsnmp="yes"] @@ -3796,9 +3794,14 @@ if test "x$with_libnetsnmp" = "xyes"; then [with_libnetsnmp="no (net-snmp/net-snmp-config.h not found)"] ) - AC_CHECK_HEADERS([net-snmp/agent/net-snmp-agent-includes.h], - [], - [with_libnetsnmpagent="no (net-snmp/agent/net-snmp-agent-includes.h not found)"] + AC_CHECK_HEADERS([net-snmp/net-snmp-includes.h], + [with_libnetsnmp="yes"], + [with_libnetsnmp="no (net-snmp/net-snmp-includes.h not found)"], + [[ + #if HAVE_NET_SNMP_NET_SNMP_CONFIG_H + # include + #endif + ]] ) CPPFLAGS="$SAVE_CPPFLAGS" @@ -3809,15 +3812,8 @@ if test "x$with_libnetsnmp" = "xyes"; then LDFLAGS="$LDFLAGS $with_libnetsnmp_ldflags" AC_CHECK_LIB([netsnmp], [init_snmp], - [with_libnetsnmp="yes"], - [with_libnetsnmp="no (libnetsnmp not found)"], - [$with_snmp_libs] - ) - - AC_CHECK_LIB([netsnmpagent], [init_agent], - [with_libnetsnmpagent="yes"], - [with_libnetsnmpagent="no (libnetsnmpagent not found)"], - [$with_snmp_libs] + [], + [with_libnetsnmp="no (libnetsnmp not found)"] ) LDFLAGS="$SAVE_LDFLAGS" @@ -3829,15 +3825,69 @@ if test "x$with_libnetsnmp" = "xyes"; then BUILD_WITH_LIBNETSNMP_LIBS="-lnetsnmp" fi -if test "x$with_libnetsnmpagent" = "xyes"; then - BUILD_WITH_LIBNETSNMP_LIBS+=" -lnetsnmpagent" -fi - AC_SUBST([BUILD_WITH_LIBNETSNMP_CPPFLAGS]) AC_SUBST([BUILD_WITH_LIBNETSNMP_LDFLAGS]) AC_SUBST([BUILD_WITH_LIBNETSNMP_LIBS]) # }}} +# --with-libnetsmpagent {{{ +AC_ARG_WITH([libnetsnmpagent], + [AS_HELP_STRING([--with-libnetsnmpagent@<:@=PREFIX@:>@], [Path to libnetsnmpagent.])], + [ + if test "x$withval" = "xno"; then + with_libnetsnmpagent="no" + else if test "x$withval" = "xyes"; then + with_libnetsnmpagent="yes" + else + with_libnetsnmpagent_cppflags="-I$withval/include" + with_libnetsnmpagent_ldflags="-I$withval/lib" + with_libnetsnmpagent="yes" + fi; fi + ], + [with_libnetsnmpagent="yes"] +) + +if test "x$with_libnetsnmpagent" = "xyes"; then + SAVE_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $with_libnetsnmpagent_cppflags" + + AC_CHECK_HEADERS([net-snmp/agent/net-snmp-agent-includes.h], + [], + [with_libnetsnmpagent="no (net-snmp/agent/net-snmp-agent-includes.h not found)"], + [[ + #if HAVE_NET_SNMP_NET_SNMP_CONFIG_H + # include + #endif + #if HAVE_NET_SNMP_NET_SNMP_INCLUDES_H + # include + #endif + ]] + ) + + CPPFLAGS="$SAVE_CPPFLAGS" +fi + +if test "x$with_libnetsnmpagent" = "xyes"; then + SAVE_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $with_libnetsnmpagent_ldflags" + + AC_CHECK_LIB([netsnmpagent], [init_agent], + [], + [with_libnetsnmpagent="no (libnetsnmpagent not found)"] + ) + + LDFLAGS="$SAVE_LDFLAGS" +fi + +if test "x$with_libnetsnmpagent" = "xyes"; then + BUILD_WITH_LIBNETSNMPAGENT_LIBS="-lnetsnmpagent" +fi + +AC_SUBST([BUILD_WITH_LIBNETSNMPAGENT_CPPFLAGS]) +AC_SUBST([BUILD_WITH_LIBNETSNMPAGENT_LDFLAGS]) +AC_SUBST([BUILD_WITH_LIBNETSNMPAGENT_LIBS]) +# }}} + # --with-liboping {{{ AC_ARG_WITH([liboping], [AS_HELP_STRING([--with-liboping@<:@=PREFIX@:>@], [Path to liboping.])], @@ -6060,7 +6110,6 @@ plugin_processes="no" plugin_protocols="no" plugin_python="no" plugin_serial="no" -plugin_snmp_agent="no" plugin_smart="no" plugin_swap="no" plugin_tape="no" @@ -6354,10 +6403,6 @@ if test "x$with_kvm_getswapinfo" = "xyes"; then plugin_swap="yes" fi -if test "x$with_libnetsnmp" = "xyes" && test "x$with_libnetsnmpagent" = "xyes"; then - plugin_snmp_agent="yes" -fi - if test "x$have_swapctl" = "xyes" && test "x$c_cv_have_swapctl_two_args" = "xyes"; then plugin_swap="yes" fi @@ -6520,7 +6565,7 @@ AC_PLUGIN([serial], [$plugin_serial], [serial port traffic AC_PLUGIN([sigrok], [$with_libsigrok], [sigrok acquisition sources]) AC_PLUGIN([smart], [$plugin_smart], [SMART statistics]) AC_PLUGIN([snmp], [$with_libnetsnmp], [SNMP querying plugin]) -AC_PLUGIN([snmp_agent], [$plugin_snmp_agent], [SNMP agent plugin]) +AC_PLUGIN([snmp_agent], [$with_libnetsnmpagent], [SNMP agent plugin]) AC_PLUGIN([statsd], [yes], [StatsD plugin]) AC_PLUGIN([swap], [$plugin_swap], [Swap usage statistics]) AC_PLUGIN([syslog], [$have_syslog], [Syslog logging plugin]) @@ -6798,6 +6843,7 @@ AC_MSG_RESULT([ libmosquitto . . . . $with_libmosquitto]) AC_MSG_RESULT([ libmysql . . . . . . $with_libmysql]) AC_MSG_RESULT([ libnetapp . . . . . . $with_libnetapp]) AC_MSG_RESULT([ libnetsnmp . . . . . $with_libnetsnmp]) +AC_MSG_RESULT([ libnetsnmpagent . . . $with_libnetsnmpagent]) AC_MSG_RESULT([ libnotify . . . . . . $with_libnotify]) AC_MSG_RESULT([ libopenipmi . . . . . $with_libopenipmipthread]) AC_MSG_RESULT([ liboping . . . . . . $with_liboping]) -- 2.11.0