From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: dsahern@kernel.org, jhs@mojatatu.com,
Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute2-next v2 3/3] configure: use pkg-config instead of hand-rolled probes
Date: Mon, 30 Nov 2026 09:57:05 -0800 [thread overview]
Message-ID: <20261130175706.336492-3-stephen@networkplumber.org> (raw)
In-Reply-To: <20261130175706.336492-1-stephen@networkplumber.org>
libselinux, libtirpc, libmnl and libcap each had their own copy of the
same pkg-config block, and the copies had drifted: two wrote LDLIBS
before CFLAGS, two after. Add check_pkg() and use it for all four.
The libbpf version test compiled a program that only existed to fail on
LIBBPF_MAJOR_VERSION < 1. pkg-config --atleast-version=1.0 answers that
without running the compiler.
check_xtables() wrote TC_CONFIG_NO_XT so the caller could grep config.mk
to decide whether to run check_xt(). The symbol never changed anything:
tc/Makefile tested it as the outer guard around an inner TC_CONFIG_XT
test, and without the .pc file the compile test cannot set TC_CONFIG_XT
anyway. Fold the existence test into check_xt(), which now also prints
yes/no like the other probes.
The setns, name_to_handle_at and strlcpy probes stay as compile tests
since libc has no .pc file, check_ipset() reads kernel headers, and
mnl_attr_get_uint() is in no released libmnl so there is no version to
compare against.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
configure | 146 ++++++++++++++++++----------------------------------
tc/Makefile | 10 ++--
2 files changed, 53 insertions(+), 103 deletions(-)
diff --git a/configure b/configure
index ef155ab3..bb965538 100755
--- a/configure
+++ b/configure
@@ -26,16 +26,15 @@ check_toolchain()
echo "YACC:=${YACC}" >>$CONFIG
}
-check_xtables()
-{
- if ! ${PKG_CONFIG} xtables --exists; then
- echo "TC_CONFIG_NO_XT:=y" >>$CONFIG
- fi
-}
-
check_xt()
{
- #check that the xtables library is usable
+ # The xtables .pc file can be present while the headers are not
+ # usable, so compile against it rather than trusting --exists.
+ if ! ${PKG_CONFIG} xtables --exists; then
+ echo "no"
+ return
+ fi
+
cat >$TMPDIR/ipttest.c <<EOF
#include <xtables.h>
#include <linux/netfilter.h>
@@ -58,7 +57,9 @@ EOF
if $CC -I$INCLUDE -o $TMPDIR/ipttest $TMPDIR/ipttest.c \
$(${PKG_CONFIG} xtables --cflags --libs) -ldl >/dev/null 2>&1; then
echo "TC_CONFIG_XT:=y" >>$CONFIG
- echo "using xtables"
+ echo "yes"
+ else
+ echo "no"
fi
rm -f $TMPDIR/ipttest.c $TMPDIR/ipttest
}
@@ -72,6 +73,26 @@ check_lib_dir()
echo "LIBDIR:=$LIBDIR" >> $CONFIG
}
+# check_pkg <pkg-config module> <make variable> <cpp define>
+#
+# Most optional libraries follow the same shape: if pkg-config knows the
+# module, export a HAVE_ make variable for the Makefiles, add -DHAVE_ for
+# the sources, and append the module's cflags and libs.
+check_pkg()
+{
+ local mod="$1" var="$2" def="$3"
+
+ if ! ${PKG_CONFIG} "$mod" --exists; then
+ echo "no"
+ return 1
+ fi
+
+ echo "yes"
+ echo "$var:=y" >>$CONFIG
+ echo "CFLAGS += -D$def" "$(${PKG_CONFIG} "$mod" --cflags)" >>$CONFIG
+ echo 'LDLIBS +=' "$(${PKG_CONFIG} "$mod" --libs)" >>$CONFIG
+}
+
check_setns()
{
cat >$TMPDIR/setnstest.c <<EOF
@@ -144,36 +165,15 @@ EOF
check_elf()
{
- if ${PKG_CONFIG} libelf --exists; then
- echo "yes"
-
- echo 'CFLAGS += ' "$(${PKG_CONFIG} libelf --cflags)" >> $CONFIG
- echo 'LDLIBS += ' "$(${PKG_CONFIG} libelf --libs)" >>$CONFIG
- else
+ if ! ${PKG_CONFIG} libelf --exists; then
echo "no"
echo " libelf is required, install libelf-dev or elfutils-libelf-devel"
exit 1
fi
-}
-have_libbpf_basic()
-{
- cat >$TMPDIR/libbpf_test.c <<EOF
-#include <bpf/libbpf.h>
-#if LIBBPF_MAJOR_VERSION < 1
-#error libbpf 1.0 or later is required
-#endif
-int main(int argc, char **argv) {
- bpf_object__open_file(NULL, NULL);
- return 0;
-}
-EOF
-
- $CC -o $TMPDIR/libbpf_test $TMPDIR/libbpf_test.c $LIBBPF_CFLAGS $LIBBPF_LDLIBS >/dev/null 2>&1
- local ret=$?
-
- rm -f $TMPDIR/libbpf_test.c $TMPDIR/libbpf_test
- return $ret
+ echo "yes"
+ echo 'CFLAGS += ' "$(${PKG_CONFIG} libelf --cflags)" >> $CONFIG
+ echo 'LDLIBS += ' "$(${PKG_CONFIG} libelf --libs)" >>$CONFIG
}
check_libbpf()
@@ -185,51 +185,22 @@ check_libbpf()
exit 1
fi
- LIBBPF_CFLAGS=$(${PKG_CONFIG} libbpf --cflags)
- LIBBPF_LDLIBS=$(${PKG_CONFIG} libbpf --libs)
LIBBPF_VERSION=$(${PKG_CONFIG} libbpf --modversion)
- if ! have_libbpf_basic; then
+ if ! ${PKG_CONFIG} libbpf --atleast-version=1.0; then
echo "no"
echo " libbpf version $LIBBPF_VERSION is too low, please update it to at least 1.0"
exit 1
fi
- echo 'CFLAGS += ' $LIBBPF_CFLAGS >> $CONFIG
+ echo 'CFLAGS += ' "$(${PKG_CONFIG} libbpf --cflags)" >> $CONFIG
echo "CFLAGS += -DLIBBPF_VERSION=\\\"$LIBBPF_VERSION\\\"" >> $CONFIG
- echo 'LDLIBS += ' $LIBBPF_LDLIBS >> $CONFIG
+ echo 'LDLIBS += ' "$(${PKG_CONFIG} libbpf --libs)" >> $CONFIG
echo "yes"
echo " libbpf version $LIBBPF_VERSION"
}
-check_selinux()
-# SELinux is a compile time option in the ss utility
-{
- if ${PKG_CONFIG} libselinux --exists; then
- echo "HAVE_SELINUX:=y" >>$CONFIG
- echo "yes"
-
- echo 'LDLIBS +=' "$(${PKG_CONFIG} --libs libselinux)" >>$CONFIG
- echo 'CFLAGS += -DHAVE_SELINUX' "$(${PKG_CONFIG} --cflags libselinux)" >>$CONFIG
- else
- echo "no"
- fi
-}
-
-check_tirpc()
-{
- if ${PKG_CONFIG} libtirpc --exists; then
- echo "HAVE_RPC:=y" >>$CONFIG
- echo "yes"
-
- echo 'LDLIBS +=' "$(${PKG_CONFIG} --libs libtirpc)" >>$CONFIG
- echo 'CFLAGS += -DHAVE_RPC' "$(${PKG_CONFIG} --cflags libtirpc)" >>$CONFIG
- else
- echo "no"
- fi
-}
-
have_mnl_attr_get_uint()
{
cat >$TMPDIR/mnl_attr_get_uint_test.c <<EOF
@@ -250,18 +221,12 @@ EOF
check_mnl()
{
- if ${PKG_CONFIG} libmnl --exists; then
- echo "HAVE_MNL:=y" >>$CONFIG
- echo "yes"
-
- echo 'CFLAGS += -DHAVE_LIBMNL' "$(${PKG_CONFIG} libmnl --cflags)" >>$CONFIG
- echo 'LDLIBS +=' "$(${PKG_CONFIG} libmnl --libs)" >> $CONFIG
+ check_pkg libmnl HAVE_MNL HAVE_LIBMNL || return
- if have_mnl_attr_get_uint; then
- echo "CFLAGS += -DHAVE_MNL_ATTR_GET_UINT" >>$CONFIG
- fi
- else
- echo "no"
+ # mnl_attr_get_uint() is not in any released libmnl, so there is no
+ # version to test for; lib/mnl_utils.c carries a fallback.
+ if have_mnl_attr_get_uint; then
+ echo "CFLAGS += -DHAVE_MNL_ATTR_GET_UINT" >>$CONFIG
fi
}
@@ -291,19 +256,6 @@ EOF
rm -f $TMPDIR/strtest.c $TMPDIR/strtest
}
-check_cap()
-{
- if ${PKG_CONFIG} libcap --exists; then
- echo "HAVE_CAP:=y" >>$CONFIG
- echo "yes"
-
- echo 'CFLAGS += -DHAVE_LIBCAP' "$(${PKG_CONFIG} libcap --cflags)" >>$CONFIG
- echo 'LDLIBS +=' "$(${PKG_CONFIG} libcap --libs)" >> $CONFIG
- else
- echo "no"
- fi
-}
-
check_color()
{
case "$COLOR" in
@@ -424,11 +376,10 @@ check_toolchain
echo "TC schedulers"
-check_xtables
-if ! grep -q TC_CONFIG_NO_XT $CONFIG; then
- echo -n " IPT "
- check_xt
+echo -n " IPT "
+check_xt
+if grep -q TC_CONFIG_XT $CONFIG; then
echo -n " IPSET "
check_ipset
fi
@@ -442,11 +393,12 @@ check_setns
echo -n "libc has name_to_handle_at: "
check_name_to_handle_at
+# SELinux is a compile time option in the ss utility
echo -n "SELinux support: "
-check_selinux
+check_pkg libselinux HAVE_SELINUX HAVE_SELINUX
echo -n "libtirpc support: "
-check_tirpc
+check_pkg libtirpc HAVE_RPC HAVE_RPC
echo -n "libbpf support: "
check_libbpf
@@ -461,7 +413,7 @@ echo -n "need for strlcpy: "
check_strlcpy
echo -n "libcap support: "
-check_cap
+check_pkg libcap HAVE_CAP HAVE_LIBCAP
echo -n "color output: "
check_color
diff --git a/tc/Makefile b/tc/Makefile
index 0e48ba38..062a5102 100644
--- a/tc/Makefile
+++ b/tc/Makefile
@@ -81,12 +81,10 @@ TCMODULES += q_ets.o
TCSO :=
-ifneq ($(TC_CONFIG_NO_XT),y)
- ifeq ($(TC_CONFIG_XT),y)
- TCMODULES += em_ipt.o
- ifeq ($(TC_CONFIG_IPSET),y)
- TCMODULES += em_ipset.o
- endif
+ifeq ($(TC_CONFIG_XT),y)
+ TCMODULES += em_ipt.o
+ ifeq ($(TC_CONFIG_IPSET),y)
+ TCMODULES += em_ipset.o
endif
endif
--
2.53.0
next prev parent reply other threads:[~2026-11-30 17:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 17:57 [PATCH iproute2-next v2 1/3] configure: drop leftovers from removed iptables action Stephen Hemminger
2026-11-30 17:57 ` [PATCH iproute2-next v2 2/3] configure: remove dead ipset compat block and IP_CONFIG_SETNS Stephen Hemminger
2026-11-30 17:57 ` Stephen Hemminger [this message]
2026-12-02 16:40 ` [PATCH iproute2-next v2 1/3] configure: drop leftovers from removed iptables action patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130175706.336492-3-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dsahern@kernel.org \
--cc=jhs@mojatatu.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.