]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tools: net: package libynl for use in selftests
authorJakub Kicinski <kuba@kernel.org>
Fri, 28 Jun 2024 00:32:50 +0000 (00:32 +0000)
committerJakub Kicinski <kuba@kernel.org>
Wed, 3 Jul 2024 01:59:33 +0000 (18:59 -0700)
Support building the C YNL userspace library into one big static file.
We can then link selftests against it for easy to use C netlink
interface.

Signed-off-by: Mina Almasry <almasrymina@google.com>
Link: https://patch.msgid.link/20240628003253.1694510-14-almasrymina@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/net/ynl/Makefile
tools/net/ynl/lib/Makefile
tools/testing/selftests/net/ynl.mk [new file with mode: 0644]

index 8e9e09d84e269104993fc5e0c0cf4d53abcd15f7..d1cdf2a8f8266fbe5034efa5c0f08111c177992d 100644 (file)
@@ -2,9 +2,12 @@
 
 SUBDIRS = lib generated samples
 
-all: $(SUBDIRS)
+all: $(SUBDIRS) libynl.a
 
 samples: | lib generated
+libynl.a: | lib generated
+       @echo -e "\tAR $@"
+       @ar rcs $@ lib/ynl.o generated/*-user.o
 
 $(SUBDIRS):
        @if [ -f "$@/Makefile" ] ; then \
@@ -17,5 +20,6 @@ clean distclean:
                        $(MAKE) -C $$dir $@; \
                fi \
        done
+       rm -f libynl.a
 
 .PHONY: all clean distclean $(SUBDIRS)
index dfff3ecd1cbabb7a1e90490d379c9e1273f9ae90..2887cc5de530fca98f945b7278f9b25f21d03eb7 100644 (file)
@@ -14,7 +14,9 @@ include $(wildcard *.d)
 all: ynl.a
 
 ynl.a: $(OBJS)
-       ar rcs $@ $(OBJS)
+       @echo -e "\tAR $@"
+       @ar rcs $@ $(OBJS)
+
 clean:
        rm -f *.o *.d *~
        rm -rf __pycache__
diff --git a/tools/testing/selftests/net/ynl.mk b/tools/testing/selftests/net/ynl.mk
new file mode 100644 (file)
index 0000000..59cb26c
--- /dev/null
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: GPL-2.0
+
+# YNL selftest build snippet
+
+# Inputs:
+#
+# YNL_GENS:      families we need in the selftests
+# YNL_PROGS:     TEST_PROGS which need YNL (TODO, none exist, yet)
+# YNL_GEN_FILES: TEST_GEN_FILES which need YNL
+
+YNL_OUTPUTS := $(patsubst %,$(OUTPUT)/%,$(YNL_GEN_FILES))
+
+$(YNL_OUTPUTS): $(OUTPUT)/libynl.a
+$(YNL_OUTPUTS): CFLAGS += \
+       -I$(top_srcdir)/usr/include/ $(KHDR_INCLUDES) \
+       -I$(top_srcdir)/tools/net/ynl/lib/ \
+       -I$(top_srcdir)/tools/net/ynl/generated/
+
+$(OUTPUT)/libynl.a:
+       $(Q)$(MAKE) -C $(top_srcdir)/tools/net/ynl GENS="$(YNL_GENS)" libynl.a
+       $(Q)cp $(top_srcdir)/tools/net/ynl/libynl.a $(OUTPUT)/libynl.a