From 03f391011a09b28e3fd8de2bbcf33ec116298e1e Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Sat, 13 Aug 2016 17:36:48 +0200 Subject: [PATCH] Stop using net-snmp-config to detect libnetsmp net-snmp-config returns the settings used to compile and link libnetsnmp, not the settings needed to compile and link code against it. This resulted in various issues, namely overlinking, failure to compile without compiler optimisations, and overriding of our compiler flags. One example is the following, just noticed on RHEL5: cc1: warnings being treated as errors snmp.c: In function 'csnmp_config_add_host': snmp.c:767: warning: ISO C90 forbids mixed declarations and code make[3]: *** [snmp_la-snmp.lo] Error 1 We do compile in C99 mode, but net-snmp-config adds -Wdeclaration-after-statement to our build command line. The GCC on RHEL5 returns a warning, while later GCCs just ignore this. --- configure.ac | 54 ++++++++++++++++++------------------------------------ src/Makefile.am | 10 +++------- 2 files changed, 21 insertions(+), 43 deletions(-) diff --git a/configure.ac b/configure.ac index 2d4c6810..251f785f 100644 --- a/configure.ac +++ b/configure.ac @@ -3332,9 +3332,6 @@ AM_CONDITIONAL(BUILD_WITH_LIBNETAPP, test "x$with_libnetapp" = "xyes") # }}} # --with-libnetsnmp {{{ -with_snmp_config="net-snmp-config" -with_snmp_cflags="" -with_snmp_libs="" AC_ARG_WITH(libnetsnmp, [AS_HELP_STRING([--with-libnetsnmp@<:@=PREFIX@:>@], [Path to the Net-SNMPD library.])], [ if test "x$withval" = "xno" @@ -3344,57 +3341,42 @@ AC_ARG_WITH(libnetsnmp, [AS_HELP_STRING([--with-libnetsnmp@<:@=PREFIX@:>@], [Pat then with_libnetsnmp="yes" else - if test -x "$withval" - then - with_snmp_config="$withval" - with_libnetsnmp="yes" - else - with_snmp_config="$withval/bin/net-snmp-config" - with_libnetsnmp="yes" - fi + with_libnetsnmp_cppflags="-I$withval/include" + with_libnetsnmp_ldflags="-I$withval/lib" + with_libnetsnmp="yes" fi; fi ], [with_libnetsnmp="yes"]) if test "x$with_libnetsnmp" = "xyes" then - with_snmp_cflags=`$with_snmp_config --cflags 2>/dev/null` - snmp_config_status=$? - - if test $snmp_config_status -ne 0 - then - with_libnetsnmp="no ($with_snmp_config failed)" - else - SAVE_CPPFLAGS="$CPPFLAGS" - CPPFLAGS="$CPPFLAGS $with_snmp_cflags" + SAVE_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $with_libnetsnmp_cppflags" - AC_CHECK_HEADERS(net-snmp/net-snmp-config.h, [], [with_libnetsnmp="no (net-snmp/net-snmp-config.h not found)"]) + AC_CHECK_HEADERS(net-snmp/net-snmp-config.h, [], [with_libnetsnmp="no (net-snmp/net-snmp-config.h not found)"]) - CPPFLAGS="$SAVE_CPPFLAGS" - fi + CPPFLAGS="$SAVE_CPPFLAGS" fi if test "x$with_libnetsnmp" = "xyes" then - with_snmp_libs=`$with_snmp_config --libs 2>/dev/null` - snmp_config_status=$? + SAVE_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $with_libnetsnmp_ldflags" - if test $snmp_config_status -ne 0 - then - with_libnetsnmp="no ($with_snmp_config failed)" - else - AC_CHECK_LIB(netsnmp, init_snmp, + AC_CHECK_LIB(netsnmp, init_snmp, [with_libnetsnmp="yes"], [with_libnetsnmp="no (libnetsnmp not found)"], [$with_snmp_libs]) - fi + + LDFLAGS="$SAVE_LDFLAGS" fi if test "x$with_libnetsnmp" = "xyes" then - BUILD_WITH_LIBSNMP_CFLAGS="$with_snmp_cflags" - BUILD_WITH_LIBSNMP_LIBS="$with_snmp_libs" - AC_SUBST(BUILD_WITH_LIBSNMP_CFLAGS) - AC_SUBST(BUILD_WITH_LIBSNMP_LIBS) + BUILD_WITH_LIBNETSNMP_CPPFLAGS="$with_libnetsnmp_cppflags" + BUILD_WITH_LIBNETSNMP_LDFLAGS="$with_libnetsnmp_ldflags" + BUILD_WITH_LIBNETSNMP_LIBS="-lnetsnmp" fi -AM_CONDITIONAL(BUILD_WITH_LIBNETSNMP, test "x$with_libnetsnmp" = "xyes") +AC_SUBST(BUILD_WITH_LIBNETSNMP_CPPFLAGS) +AC_SUBST(BUILD_WITH_LIBNETSNMP_LDFLAGS) +AC_SUBST(BUILD_WITH_LIBNETSNMP_LIBS) # }}} # --with-liboconfig {{{ diff --git a/src/Makefile.am b/src/Makefile.am index 12c7730c..25d7bd40 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1005,13 +1005,9 @@ endif if BUILD_PLUGIN_SNMP pkglib_LTLIBRARIES += snmp.la snmp_la_SOURCES = snmp.c -snmp_la_LDFLAGS = $(PLUGIN_LDFLAGS) -snmp_la_CFLAGS = $(AM_CFLAGS) -snmp_la_LIBADD = -if BUILD_WITH_LIBNETSNMP -snmp_la_CFLAGS += $(BUILD_WITH_LIBSNMP_CFLAGS) -snmp_la_LIBADD += $(BUILD_WITH_LIBSNMP_LIBS) -endif +snmp_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBNETSNMP_CPPFLAGS) +snmp_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBNETSNMP_LDFLAGS) +snmp_la_LIBADD = $(BUILD_WITH_LIBNETSNMP_LIBS) endif if BUILD_PLUGIN_STATSD -- 2.11.0