1 From 57d6c3d36045aab8957ffeb7324728bf17faf8bd Mon Sep 17 00:00:00 2001
2 From: Bart Van Assche <bvanassche@acm.org>
3 Date: Mon, 2 Feb 2015 20:31:29 +0100
4 Subject: [PATCH] configure: Eliminate the hard-coded libnl-3 include path
6 See also commit 3dde41998625fe0e24119a2e1f4509ba3ba2fd9a.
8 (cherry picked from commit 852dcd644cfe4cfc7177649eaec163d6221f2be1)
10 Original commit included modifications to configure script.
11 Do not keep these modifications, since they caused lots of conflicts, and
12 configure script is meant to be automatically generated.
14 Signed-off-by: Julien Floret <julien.floret@6wind.com>
20 configure.d/config_os_libs2 | 30 ++++++-
21 m4/pkg.m4 | 214 ++++++++++++++++++++++++++++++++++++++++++++
22 3 files changed, 243 insertions(+), 2 deletions(-)
23 create mode 100644 m4/pkg.m4
25 diff --git a/aclocal.m4 b/aclocal.m4
26 index cd80c7486f2f..45e3608ed480 100644
29 @@ -22,3 +22,4 @@ m4_include([m4/ltversion.m4])
30 m4_include([m4/lt~obsolete.m4])
31 m4_include([m4/netsnmp_arg.m4])
32 m4_include([m4/netsnmp_search_libs.m4])
33 +m4_include([m4/pkg.m4])
34 diff --git a/configure.d/config_os_libs2 b/configure.d/config_os_libs2
35 index 47491e24ce0a..10bd414b879e 100644
36 --- a/configure.d/config_os_libs2
37 +++ b/configure.d/config_os_libs2
38 @@ -225,11 +225,37 @@ fi
39 if test "x$with_nl" != "xno"; then
41 linux*) # Check for libnl (linux)
42 + # The test below verifies whether the libnl-3 package been installed.
43 + # This test works as follows:
44 + # - If pkg-config was not installed at the time autogen.sh was run,
45 + # the definition of the PKG_CHECK_EXISTS() macro will not be found by
46 + # autogen.sh. Augogen.sh will generate a configure script that prints
47 + # a warning about pkg-config and proceeds as if libnl-3 has not been
49 + # - If pkg-config was installed at the time autogen.sh was run,
50 + # the generated configure script will try to detect the presence of
51 + # the libnl-3 library by looking up compile and linker flags in the
52 + # file called libnl-3.pc.
53 + # - pkg-config settings can be overridden via the configure variables
54 + # LIBNL3_CFLAGS and LIBNL3_LIBS (added by the pkg-config m4 macro's to
55 + # the configure script -- see also ./configure --help).
56 + # - The LIBNL3_CFLAGS and LIBNL3_LIBS configure variables can be used
57 + # even if the pkg-config executable is not present on the system on
58 + # which the configure script is run.
61 + [PKG_CHECK_EXISTS([libnl-3.0],
62 + [PKG_CHECK_MODULES([LIBNL3], [libnl-3.0])])
64 + AC_MSG_WARN([pkg-config has not been installed or is too old.])
65 + AC_MSG_WARN([Detection of libnl-3.0 will be skipped.])
68 netsnmp_save_CPPFLAGS="$CPPFLAGS"
69 - CPPFLAGS="-I/usr/include/libnl3 $CPPFLAGS"
70 + CPPFLAGS="${LIBNL3_CFLAGS} $CPPFLAGS"
71 NETSNMP_SEARCH_LIBS(nl_connect, nl-3,
72 [AC_CHECK_HEADERS(netlink/netlink.h)
73 - EXTERNAL_MIBGROUP_INCLUDES="$EXTERNAL_MIBGROUP_INCLUDES -I/usr/include/libnl3"],
74 + EXTERNAL_MIBGROUP_INCLUDES="$EXTERNAL_MIBGROUP_INCLUDES ${LIBNL3_CFLAGS}"],
75 [CPPFLAGS="$netsnmp_save_CPPFLAGS"], [], [], [LMIBLIBS])
76 if test "x$ac_cv_header_netlink_netlink_h" != xyes; then
77 NETSNMP_SEARCH_LIBS(nl_connect, nl, [
78 diff --git a/m4/pkg.m4 b/m4/pkg.m4
80 index 000000000000..c5b26b52e6cd
84 +# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
85 +# serial 1 (pkg-config-0.24)
87 +# Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
89 +# This program is free software; you can redistribute it and/or modify
90 +# it under the terms of the GNU General Public License as published by
91 +# the Free Software Foundation; either version 2 of the License, or
92 +# (at your option) any later version.
94 +# This program is distributed in the hope that it will be useful, but
95 +# WITHOUT ANY WARRANTY; without even the implied warranty of
96 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
97 +# General Public License for more details.
99 +# You should have received a copy of the GNU General Public License
100 +# along with this program; if not, write to the Free Software
101 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
103 +# As a special exception to the GNU General Public License, if you
104 +# distribute this file as part of a program that contains a
105 +# configuration script generated by Autoconf, you may include it under
106 +# the same distribution terms that you use for the rest of that program.
108 +# PKG_PROG_PKG_CONFIG([MIN-VERSION])
109 +# ----------------------------------
110 +AC_DEFUN([PKG_PROG_PKG_CONFIG],
111 +[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
112 +m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
113 +m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
114 +AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
115 +AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
116 +AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
118 +if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
119 + AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
121 +if test -n "$PKG_CONFIG"; then
122 + _pkg_min_version=m4_default([$1], [0.9.0])
123 + AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
124 + if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
125 + AC_MSG_RESULT([yes])
127 + AC_MSG_RESULT([no])
131 +])# PKG_PROG_PKG_CONFIG
133 +# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
135 +# Check to see whether a particular set of modules exists. Similar
136 +# to PKG_CHECK_MODULES(), but does not set variables or print errors.
138 +# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
139 +# only at the first occurence in configure.ac, so if the first place
140 +# it's called might be skipped (such as if it is within an "if", you
141 +# have to call PKG_CHECK_EXISTS manually
142 +# --------------------------------------------------------------
143 +AC_DEFUN([PKG_CHECK_EXISTS],
144 +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
145 +if test -n "$PKG_CONFIG" && \
146 + AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
147 + m4_default([$2], [:])
148 +m4_ifvaln([$3], [else
152 +# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
153 +# ---------------------------------------------
154 +m4_define([_PKG_CONFIG],
155 +[if test -n "$$1"; then
157 + elif test -n "$PKG_CONFIG"; then
158 + PKG_CHECK_EXISTS([$3],
159 + [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
160 + test "x$?" != "x0" && pkg_failed=yes ],
167 +# _PKG_SHORT_ERRORS_SUPPORTED
168 +# -----------------------------
169 +AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
170 +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
171 +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
172 + _pkg_short_errors_supported=yes
174 + _pkg_short_errors_supported=no
176 +])# _PKG_SHORT_ERRORS_SUPPORTED
179 +# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
180 +# [ACTION-IF-NOT-FOUND])
183 +# Note that if there is a possibility the first call to
184 +# PKG_CHECK_MODULES might not happen, you should be sure to include an
185 +# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
188 +# --------------------------------------------------------------
189 +AC_DEFUN([PKG_CHECK_MODULES],
190 +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
191 +AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
192 +AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
195 +AC_MSG_CHECKING([for $1])
197 +_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
198 +_PKG_CONFIG([$1][_LIBS], [libs], [$2])
200 +m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
201 +and $1[]_LIBS to avoid the need to call pkg-config.
202 +See the pkg-config man page for more details.])
204 +if test $pkg_failed = yes; then
205 + AC_MSG_RESULT([no])
206 + _PKG_SHORT_ERRORS_SUPPORTED
207 + if test $_pkg_short_errors_supported = yes; then
208 + $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
210 + $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
212 + # Put the nasty error message in config.log where it belongs
213 + echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
215 + m4_default([$4], [AC_MSG_ERROR(
216 +[Package requirements ($2) were not met:
220 +Consider adjusting the PKG_CONFIG_PATH environment variable if you
221 +installed software in a non-standard prefix.
225 +elif test $pkg_failed = untried; then
226 + AC_MSG_RESULT([no])
227 + m4_default([$4], [AC_MSG_FAILURE(
228 +[The pkg-config script could not be found or is too old. Make sure it
229 +is in your PATH or set the PKG_CONFIG environment variable to the full
234 +To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
237 + $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
238 + $1[]_LIBS=$pkg_cv_[]$1[]_LIBS
239 + AC_MSG_RESULT([yes])
242 +])# PKG_CHECK_MODULES
245 +# PKG_INSTALLDIR(DIRECTORY)
246 +# -------------------------
247 +# Substitutes the variable pkgconfigdir as the location where a module
248 +# should install pkg-config .pc files. By default the directory is
249 +# $libdir/pkgconfig, but the default can be changed by passing
250 +# DIRECTORY. The user can override through the --with-pkgconfigdir
252 +AC_DEFUN([PKG_INSTALLDIR],
253 +[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
254 +m4_pushdef([pkg_description],
255 + [pkg-config installation directory @<:@]pkg_default[@:>@])
256 +AC_ARG_WITH([pkgconfigdir],
257 + [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
258 + [with_pkgconfigdir=]pkg_default)
259 +AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
260 +m4_popdef([pkg_default])
261 +m4_popdef([pkg_description])
262 +]) dnl PKG_INSTALLDIR
265 +# PKG_NOARCH_INSTALLDIR(DIRECTORY)
266 +# -------------------------
267 +# Substitutes the variable noarch_pkgconfigdir as the location where a
268 +# module should install arch-independent pkg-config .pc files. By
269 +# default the directory is $datadir/pkgconfig, but the default can be
270 +# changed by passing DIRECTORY. The user can override through the
271 +# --with-noarch-pkgconfigdir parameter.
272 +AC_DEFUN([PKG_NOARCH_INSTALLDIR],
273 +[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
274 +m4_pushdef([pkg_description],
275 + [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
276 +AC_ARG_WITH([noarch-pkgconfigdir],
277 + [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
278 + [with_noarch_pkgconfigdir=]pkg_default)
279 +AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
280 +m4_popdef([pkg_default])
281 +m4_popdef([pkg_description])
282 +]) dnl PKG_NOARCH_INSTALLDIR
285 +# PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
286 +# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
287 +# -------------------------------------------
288 +# Retrieves the value of the pkg-config variable for the given module.
289 +AC_DEFUN([PKG_CHECK_VAR],
290 +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
291 +AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
293 +_PKG_CONFIG([$1], [variable="][$3]["], [$2])
294 +AS_VAR_COPY([$1], [pkg_cv_][$1])
296 +AS_VAR_IF([$1], [""], [$5], [$4])dnl