From: Jo-Philipp Wich <jo@mein.io>
Date: Fri, 6 Jan 2017 13:41:00 +0100
Subject: [PATCH] configure: allow overriding hardcoded /usr/include/libnl3

In a cross-compile setting we do not want to probe the host systems
/usr/include path, therfore allow to disable this include path by passing
ac_cv_header_netlink_netlink_h=yes to configure.

Also disable the testing for libraries providing nl_connect when
netsnmp_cv_func_nl_connect_LIBS is predefined since the proprietary
NETSNMP_SEARCH_LIBS() macro will clobber the internal link flags upon
encountering predefined cache variables, causing all subsequent configure
link tests to fail due to a stray "no" word getting passed to the linker.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
--- a/configure.d/config_os_libs2
+++ b/configure.d/config_os_libs2
@@ -252,14 +252,22 @@ if test "x$with_nl" != "xno"; then
     case $target_os in
     linux*) # Check for libnl (linux)
         netsnmp_save_CPPFLAGS="$CPPFLAGS"
-        CPPFLAGS="${LIBNL3_CFLAGS} ${LIBNLROUTE3_CFLAGS} $CPPFLAGS"
-        NETSNMP_SEARCH_LIBS(nl_connect, nl-3,
-            [AC_CHECK_HEADERS(netlink/netlink.h)
-            EXTERNAL_MIBGROUP_INCLUDES="$EXTERNAL_MIBGROUP_INCLUDES ${LIBNL3_CFLAGS}"],
-            [CPPFLAGS="$netsnmp_save_CPPFLAGS"], [], [LMIBLIBS])
+        netsnmp_netlink_include_flags=""
         if test "x$ac_cv_header_netlink_netlink_h" != xyes; then
-            NETSNMP_SEARCH_LIBS(nl_connect, nl, [
-                AC_CHECK_HEADERS(netlink/netlink.h)], [], [], LMIBLIBS)
+            netsnmp_netlink_include_flags="-I/usr/include/libnl3"
+        fi
+        CPPFLAGS="$netsnmp_netlink_include_flags $CPPFLAGS"
+        if test "x$netsnmp_cv_func_nl_connect_LIBS" = x; then
+            NETSNMP_SEARCH_LIBS(nl_connect, nl-3,
+                [AC_CHECK_HEADERS(netlink/netlink.h)
+                EXTERNAL_MIBGROUP_INCLUDES="$EXTERNAL_MIBGROUP_INCLUDES $netsnmp_netlink_include_flags"],
+                [CPPFLAGS="$netsnmp_save_CPPFLAGS"], [], [], [LMIBLIBS])
+            if test "x$ac_cv_header_netlink_netlink_h" != xyes; then
+                NETSNMP_SEARCH_LIBS(nl_connect, nl, [
+                    AC_CHECK_HEADERS(netlink/netlink.h)], [], [], LMIBLIBS)
+            fi
+        else
+            LMIBLIBS="$LMIBLIBS $netsnmp_cv_func_nl_connect_LIBS"
         fi
         if test "x$ac_cv_header_netlink_netlink_h" = xyes; then
             AC_EGREP_HEADER([nl_socket_free], [netlink/socket.h],
