]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tools: ynl: add install target for generated content
authorJan Stancek <jstancek@redhat.com>
Wed, 8 Jan 2025 13:56:16 +0000 (14:56 +0100)
committerJakub Kicinski <kuba@kernel.org>
Thu, 9 Jan 2025 20:53:27 +0000 (12:53 -0800)
Generate docs using ynl_gen_rst and add install target for
headers, specs and generates rst files.

Factor out SPECS_DIR since it's repeated many times.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Reviewed-by: Donald Hunter <donald.hunter@gmail.com>
Link: https://patch.msgid.link/645c68e3d201f1ef4276e3daddfe06262a0c2804.1736343575.git.jstancek@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/net/ynl/generated/.gitignore
tools/net/ynl/generated/Makefile

index ade488626d26c9538a50fa75f7238c8c537ac27d..859a6fb446e14f398705c6c1ecefb9f748109e23 100644 (file)
@@ -1,2 +1,3 @@
 *-user.c
 *-user.h
+*.rst
index 00af721b1571baf589e9f8b738443c0fd8dea583..21f9e299dc75990b42cddb149341e49867a08e4e 100644 (file)
@@ -7,32 +7,44 @@ ifeq ("$(DEBUG)","1")
   CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan
 endif
 
+INSTALL     ?= install
+prefix      ?= /usr
+datarootdir ?= $(prefix)/share
+docdir      ?= $(datarootdir)/doc
+includedir  ?= $(prefix)/include
+
 include ../Makefile.deps
 
 YNL_GEN_ARG_ethtool:=--user-header linux/ethtool_netlink.h \
        --exclude-op stats-get
 
 TOOL:=../pyynl/ynl_gen_c.py
+TOOL_RST:=../pyynl/ynl_gen_rst.py
 
+SPECS_DIR:=../../../../Documentation/netlink/specs
 GENS_PATHS=$(shell grep -nrI --files-without-match \
                'protocol: netlink' \
-               ../../../../Documentation/netlink/specs/)
-GENS=$(patsubst ../../../../Documentation/netlink/specs/%.yaml,%,${GENS_PATHS})
+               $(SPECS_DIR))
+GENS=$(patsubst $(SPECS_DIR)/%.yaml,%,${GENS_PATHS})
 SRCS=$(patsubst %,%-user.c,${GENS})
 HDRS=$(patsubst %,%-user.h,${GENS})
 OBJS=$(patsubst %,%-user.o,${GENS})
 
-all: protos.a $(HDRS) $(SRCS) $(KHDRS) $(KSRCS) $(UAPI)
+SPECS_PATHS=$(wildcard $(SPECS_DIR)/*.yaml)
+SPECS=$(patsubst $(SPECS_DIR)/%.yaml,%,${SPECS_PATHS})
+RSTS=$(patsubst %,%.rst,${SPECS})
+
+all: protos.a $(HDRS) $(SRCS) $(KHDRS) $(KSRCS) $(UAPI) $(RSTS)
 
 protos.a: $(OBJS)
        @echo -e "\tAR $@"
        @ar rcs $@ $(OBJS)
 
-%-user.h: ../../../../Documentation/netlink/specs/%.yaml $(TOOL)
+%-user.h: $(SPECS_DIR)/%.yaml $(TOOL)
        @echo -e "\tGEN $@"
        @$(TOOL) --mode user --header --spec $< -o $@ $(YNL_GEN_ARG_$*)
 
-%-user.c: ../../../../Documentation/netlink/specs/%.yaml $(TOOL)
+%-user.c: $(SPECS_DIR)/%.yaml $(TOOL)
        @echo -e "\tGEN $@"
        @$(TOOL) --mode user --source --spec $< -o $@ $(YNL_GEN_ARG_$*)
 
@@ -40,14 +52,37 @@ protos.a: $(OBJS)
        @echo -e "\tCC $@"
        @$(COMPILE.c) $(CFLAGS_$*) -o $@ $<
 
+%.rst: $(SPECS_DIR)/%.yaml $(TOOL_RST)
+       @echo -e "\tGEN_RST $@"
+       @$(TOOL_RST) -o $@ -i $<
+
 clean:
        rm -f *.o
 
 distclean: clean
-       rm -f *.c *.h *.a
+       rm -f *.c *.h *.a *.rst
 
 regen:
        @../ynl-regen.sh
 
-.PHONY: all clean distclean regen
+install-headers: $(HDRS)
+       @echo -e "\tINSTALL generated headers"
+       @$(INSTALL) -d $(DESTDIR)$(includedir)/ynl
+       @$(INSTALL) -m 0644 *.h $(DESTDIR)$(includedir)/ynl/
+
+install-rsts: $(RSTS)
+       @echo -e "\tINSTALL generated docs"
+       @$(INSTALL) -d $(DESTDIR)$(docdir)/ynl
+       @$(INSTALL) -m 0644 $(RSTS) $(DESTDIR)$(docdir)/ynl/
+
+install-specs:
+       @echo -e "\tINSTALL specs"
+       @$(INSTALL) -d $(DESTDIR)$(datarootdir)/ynl
+       @$(INSTALL) -m 0644 ../../../../Documentation/netlink/*.yaml $(DESTDIR)$(datarootdir)/ynl/
+       @$(INSTALL) -d $(DESTDIR)$(datarootdir)/ynl/specs
+       @$(INSTALL) -m 0644 $(SPECS_DIR)/*.yaml $(DESTDIR)$(datarootdir)/ynl/specs/
+
+install: install-headers install-rsts install-specs
+
+.PHONY: all clean distclean regen install install-headers install-rsts install-specs
 .DEFAULT_GOAL: all