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 --- 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 < #include @@ -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 +# +# 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 <>$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 <>$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