selftests/bpf: Templatize man page generation
authorJoe Stringer <joe@cilium.io>
Tue, 2 Mar 2021 17:19:44 +0000 (09:19 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 5 Mar 2021 02:39:45 +0000 (18:39 -0800)
Previously, the Makefile here was only targeting a single manual page so
it just hardcoded a bunch of individual rules to specifically handle
build, clean, install, uninstall for that particular page.

Upcoming commits will generate manual pages for an additional section,
so this commit prepares the makefile first by converting the existing
targets into an evaluated set of targets based on the manual page name
and section.

Signed-off-by: Joe Stringer <joe@cilium.io>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/bpf/20210302171947.2268128-13-joe@cilium.io
tools/testing/selftests/bpf/Makefile.docs

index 546c4a763b461599fed072b32efaac613e3c104c..f39ad19317c89b3e1794f33e7c676bbeab13035e 100644 (file)
@@ -39,24 +39,34 @@ $(OUTPUT)bpf-$1.rst: ../../../../include/uapi/linux/bpf.h
        $$(QUIET_GEN)../../../../scripts/bpf_doc.py $1 \
                --filename $$< > $$@
 
-$(OUTPUT)%.7: $(OUTPUT)%.rst
+$(OUTPUT)%.$2: $(OUTPUT)%.rst
 ifndef RST2MAN_DEP
-       $(error "rst2man not found, but required to generate man pages")
+       $$(error "rst2man not found, but required to generate man pages")
 endif
-       $(QUIET_GEN)rst2man $< > $@
+       $$(QUIET_GEN)rst2man $$< > $$@
 
-docs-clean:
-       $(call QUIET_CLEAN, eBPF_helpers-manpage)
-       $(Q)$(RM) $(DOC_MAN7) $(OUTPUT)$(HELPERS_RST)
+docs-clean-$1:
+       $$(call QUIET_CLEAN, eBPF_$1-manpage)
+       $(Q)$(RM) $$(DOC_MAN$2) $(OUTPUT)bpf-$1.rst
 
-docs-install: helpers
-       $(call QUIET_INSTALL, eBPF_helpers-manpage)
-       $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(man7dir)
-       $(Q)$(INSTALL) -m 644 $(DOC_MAN7) $(DESTDIR)$(man7dir)
+docs-install-$1: docs
+       $$(call QUIET_INSTALL, eBPF_$1-manpage)
+       $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$$(man$2dir)
+       $(Q)$(INSTALL) -m 644 $$(DOC_MAN$2) $(DESTDIR)$$(man$2dir)
 
-docs-uninstall:
-       $(call QUIET_UNINST, eBPF_helpers-manpage)
-       $(Q)$(RM) $(addprefix $(DESTDIR)$(man7dir)/,$(_DOC_MAN7))
-       $(Q)$(RMDIR) $(DESTDIR)$(man7dir)
+docs-uninstall-$1:
+       $$(call QUIET_UNINST, eBPF_$1-manpage)
+       $(Q)$(RM) $$(addprefix $(DESTDIR)$$(man$2dir)/,$$(_DOC_MAN$2))
+       $(Q)$(RMDIR) $(DESTDIR)$$(man$2dir)
 
-.PHONY: docs docs-clean docs-install docs-uninstall
+.PHONY: $1 docs-clean-$1 docs-install-$1 docs-uninstall-$1
+endef
+
+# Create the make targets to generate manual pages by name and section
+$(eval $(call DOCS_RULES,helpers,7))
+
+docs-clean: $(foreach doctarget,$(DOCTARGETS), docs-clean-$(doctarget))
+docs-install: $(foreach doctarget,$(DOCTARGETS), docs-install-$(doctarget))
+docs-uninstall: $(foreach doctarget,$(DOCTARGETS), docs-uninstall-$(doctarget))
+
+.PHONY: docs docs-clean docs-install docs-uninstall man7