Skip to content

Commit 0269756

Browse files
committed
Add README and support build for all families
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 7dc3036 commit 0269756

3 files changed

Lines changed: 93 additions & 8 deletions

File tree

Makefile.deps

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
# Try to include uAPI headers from the kernel uapi/ path.
4+
# Most code under tools/ requires the respective kernel uAPI headers
5+
# to be copied to tools/include. The duplication is annoying.
6+
# All the family headers should be self-contained. We avoid the copying
7+
# by selectively including just the uAPI header of the family directly
8+
# from the kernel sources.
9+
10+
UAPI_PATH:=../
11+
12+
# scripts/headers_install.sh strips "_UAPI" from header guards so we
13+
# need the explicit -D matching what's in /usr, to avoid multiple definitions.
14+
15+
get_hdr_inc=-D$(1) -include $(UAPI_PATH)/linux/$(2)
16+
17+
CFLAGS_devlink:=$(call get_hdr_inc,_LINUX_DEVLINK_H_,devlink.h)
18+
CFLAGS_dpll:=$(call get_hdr_inc,_LINUX_DPLL_H,dpll.h)
19+
CFLAGS_ethtool:=$(call get_hdr_inc,_LINUX_ETHTOOL_H,ethtool.h) \
20+
$(call get_hdr_inc,_LINUX_ETHTOOL_NETLINK_H_,ethtool_netlink.h)
21+
CFLAGS_handshake:=$(call get_hdr_inc,_LINUX_HANDSHAKE_H,handshake.h)
22+
CFLAGS_mptcp_pm:=$(call get_hdr_inc,_LINUX_MPTCP_PM_H,mptcp_pm.h)
23+
CFLAGS_netdev:=$(call get_hdr_inc,_LINUX_NETDEV_H,netdev.h)
24+
CFLAGS_nlctrl:=$(call get_hdr_inc,__LINUX_GENERIC_NETLINK_H,genetlink.h)
25+
CFLAGS_nfsd:=$(call get_hdr_inc,_LINUX_NFSD_NETLINK_H,nfsd_netlink.h)
26+
CFLAGS_ovs_datapath:=$(call get_hdr_inc,__LINUX_OPENVSWITCH_H,openvswitch.h)
27+
CFLAGS_ovs_flow:=$(call get_hdr_inc,__LINUX_OPENVSWITCH_H,openvswitch.h)
28+
CFLAGS_ovs_vport:=$(call get_hdr_inc,__LINUX_OPENVSWITCH_H,openvswitch.h)
29+
CFLAGS_psp:=$(call get_hdr_inc,_LINUX_PSP_H,psp.h)
30+
CFLAGS_tcp_metrics:=$(call get_hdr_inc,_LINUX_TCP_METRICS_H,tcp_metrics.h)

README.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Using ynl-cpp
2+
-------------
3+
4+
YNL CPP is a best effort port of YNL C. Like YNL C is only supports
5+
static linking (because structs are auto-generated and may change
6+
version to version).
7+
8+
The best way of using it in your project is probably git submodule.
9+
10+
Building ynl-cpp
11+
----------------
12+
13+
The repo supports building code for a specific family::
14+
15+
make -C generated/ netdev_lib.a
16+
17+
or a big archive with code for all families::
18+
19+
make -C generated/
20+
21+
Updating to latest kernel versions
22+
----------------------------------
23+
24+
::
25+
26+
./update-from-kernel.sh ../linux/

generated/Makefile

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,58 @@
33
CC=gcc
44
CXX=g++
55
CFLAGS=-std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow -I../lib/
6-
CXXFLAGS=-D_LINUX_ETHTOOL_H -I../lib/ -include../linux/ethtool_netlink.h -include../linux/ethtool.h
76
ifeq ("$(DEBUG)","1")
87
CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan
98
endif
109

11-
SRCS_ETHTOOL_CPP=$(wildcard ethtool-user.cpp)
12-
OBJS_ETHTOOL_CPP=$(patsubst %.cpp,%.o,${SRCS_ETHTOOL_CPP})
10+
CXXFLAGS=-I../lib/ -I../
11+
12+
include ../Makefile.deps
13+
14+
TOOL:=../ynl-gen-cpp.py
15+
16+
GENS_PATHS=$(shell grep -nrI --files-without-match \
17+
'protocol: netlink' ../Documentation/netlink/specs/)
18+
GENS_ALL=$(patsubst ../Documentation/netlink/specs/%.yaml,%,${GENS_PATHS})
19+
GENS=$(filter-out devlink ovs_datapath ovs_flow ovs_vport nlctrl,${GENS_ALL})
20+
SRCS=$(patsubst %,%-user.cpp,${GENS})
21+
HDRS=$(patsubst %,%-user.hpp,${GENS})
22+
OBJS=$(patsubst %,%-user.cpp.o,${GENS})
23+
LIBS=$(patsubst %,%_lib.a,${GENS})
1324

1425
include $(wildcard *.d)
1526

16-
all: ethtool_lib.a
27+
ifeq ($(V),1)
28+
Q =
29+
else
30+
Q = @
31+
endif
32+
33+
all: $(LIBS)
34+
@echo -e "\tAR libynl.a"
35+
$(Q)ar rcs libynl.a $(OBJS)
36+
37+
%-user.hpp: ../Documentation/netlink/specs/%.yaml $(TOOL)
38+
@echo -e "\tGEN $@"
39+
$(Q)$(TOOL) --mode user --header --spec $< -o $@ $(YNL_GEN_ARG_$*)
40+
41+
%-user.cpp: ../Documentation/netlink/specs/%.yaml $(TOOL)
42+
@echo -e "\tGEN $@"
43+
$(Q)$(TOOL) --mode user --source --spec $< -o $@ $(YNL_GEN_ARG_$*)
1744

18-
ethtool_lib.a: $@ $(OBJS_ETHTOOL_CPP)
19-
ar rcs $@ $(OBJS_ETHTOOL_CPP)
45+
%-user.cpp.o: %-user.cpp %-user.hpp
46+
@echo -e "\tCXX $@ "
47+
$(Q)$(COMPILE.cpp) $(CFLAGS_$*) -MMD -c -o $@ $<
2048

2149
clean:
2250
rm -f *.o *.d *~
2351

2452
distclean: clean
2553
rm -f *.a
2654

27-
%.cpp.o: %.cpp
28-
$(COMPILE.cxx) -MMD -c -o $@ $<
55+
%_lib.a: $@ %-user.cpp.o
56+
@echo -e "\tAR $@"
57+
$(Q)ar rcs $@ $<
2958

3059
.PHONY: all clean distclean
3160
.DEFAULT_GOAL=all

0 commit comments

Comments
 (0)