xref: /linux/tools/testing/selftests/bpf/Makefile.docs (revision 762f99f4f3cb41a775b5157dd761217beba65873)
1a01d935bSJoe Stringer# SPDX-License-Identifier: GPL-2.0-only
2a01d935bSJoe Stringer
3a01d935bSJoe Stringerinclude ../../../scripts/Makefile.include
4a01d935bSJoe Stringerinclude ../../../scripts/utilities.mak
5a01d935bSJoe Stringer
6a01d935bSJoe StringerINSTALL ?= install
7a01d935bSJoe StringerRM ?= rm -f
8a01d935bSJoe StringerRMDIR ?= rmdir --ignore-fail-on-non-empty
9a01d935bSJoe Stringer
10a01d935bSJoe Stringerifeq ($(V),1)
11a01d935bSJoe Stringer  Q =
12a01d935bSJoe Stringerelse
13a01d935bSJoe Stringer  Q = @
14a01d935bSJoe Stringerendif
15a01d935bSJoe Stringer
16a01d935bSJoe Stringerprefix ?= /usr/local
17a01d935bSJoe Stringermandir ?= $(prefix)/man
18accbd33aSJoe Stringerman2dir = $(mandir)/man2
19a01d935bSJoe Stringerman7dir = $(mandir)/man7
20a01d935bSJoe Stringer
21accbd33aSJoe StringerSYSCALL_RST = bpf-syscall.rst
22accbd33aSJoe StringerMAN2_RST = $(SYSCALL_RST)
23accbd33aSJoe Stringer
24a01d935bSJoe StringerHELPERS_RST = bpf-helpers.rst
25a01d935bSJoe StringerMAN7_RST = $(HELPERS_RST)
26a01d935bSJoe Stringer
27accbd33aSJoe Stringer_DOC_MAN2 = $(patsubst %.rst,%.2,$(MAN2_RST))
28accbd33aSJoe StringerDOC_MAN2 = $(addprefix $(OUTPUT),$(_DOC_MAN2))
29accbd33aSJoe Stringer
30a01d935bSJoe Stringer_DOC_MAN7 = $(patsubst %.rst,%.7,$(MAN7_RST))
31a01d935bSJoe StringerDOC_MAN7 = $(addprefix $(OUTPUT),$(_DOC_MAN7))
32a01d935bSJoe Stringer
33accbd33aSJoe StringerDOCTARGETS := helpers syscall
34a01d935bSJoe Stringer
35a01d935bSJoe Stringerdocs: $(DOCTARGETS)
36accbd33aSJoe Stringersyscall: man2
37a01d935bSJoe Stringerhelpers: man7
38accbd33aSJoe Stringerman2: $(DOC_MAN2)
39a01d935bSJoe Stringerman7: $(DOC_MAN7)
40a01d935bSJoe Stringer
41a01d935bSJoe StringerRST2MAN_DEP := $(shell command -v rst2man 2>/dev/null)
42a01d935bSJoe Stringer
43a01d935bSJoe Stringer# Configure make rules for the man page bpf-$1.$2.
44a01d935bSJoe Stringer# $1 - target for scripts/bpf_doc.py
45a01d935bSJoe Stringer# $2 - man page section to generate the troff file
46a01d935bSJoe Stringerdefine DOCS_RULES =
47a01d935bSJoe Stringer$(OUTPUT)bpf-$1.rst: ../../../../include/uapi/linux/bpf.h
48a01d935bSJoe Stringer	$$(QUIET_GEN)../../../../scripts/bpf_doc.py $1 \
49a01d935bSJoe Stringer		--filename $$< > $$@
50a01d935bSJoe Stringer
5162b379a2SJoe Stringer$(OUTPUT)%.$2: $(OUTPUT)%.rst
52a01d935bSJoe Stringerifndef RST2MAN_DEP
5362b379a2SJoe Stringer	$$(error "rst2man not found, but required to generate man pages")
54a01d935bSJoe Stringerendif
55*380afe72SJoe Stringer	$$(QUIET_GEN)rst2man --exit-status=1 $$< > $$@.tmp
56*380afe72SJoe Stringer	$$(QUIET_GEN)mv $$@.tmp $$@
57a01d935bSJoe Stringer
5862b379a2SJoe Stringerdocs-clean-$1:
5962b379a2SJoe Stringer	$$(call QUIET_CLEAN, eBPF_$1-manpage)
6062b379a2SJoe Stringer	$(Q)$(RM) $$(DOC_MAN$2) $(OUTPUT)bpf-$1.rst
61a01d935bSJoe Stringer
6262b379a2SJoe Stringerdocs-install-$1: docs
6362b379a2SJoe Stringer	$$(call QUIET_INSTALL, eBPF_$1-manpage)
6462b379a2SJoe Stringer	$(Q)$(INSTALL) -d -m 755 $(DESTDIR)$$(man$2dir)
6562b379a2SJoe Stringer	$(Q)$(INSTALL) -m 644 $$(DOC_MAN$2) $(DESTDIR)$$(man$2dir)
66a01d935bSJoe Stringer
6762b379a2SJoe Stringerdocs-uninstall-$1:
6862b379a2SJoe Stringer	$$(call QUIET_UNINST, eBPF_$1-manpage)
6962b379a2SJoe Stringer	$(Q)$(RM) $$(addprefix $(DESTDIR)$$(man$2dir)/,$$(_DOC_MAN$2))
7062b379a2SJoe Stringer	$(Q)$(RMDIR) $(DESTDIR)$$(man$2dir)
71a01d935bSJoe Stringer
7262b379a2SJoe Stringer.PHONY: $1 docs-clean-$1 docs-install-$1 docs-uninstall-$1
7362b379a2SJoe Stringerendef
7462b379a2SJoe Stringer
7562b379a2SJoe Stringer# Create the make targets to generate manual pages by name and section
7662b379a2SJoe Stringer$(eval $(call DOCS_RULES,helpers,7))
77accbd33aSJoe Stringer$(eval $(call DOCS_RULES,syscall,2))
7862b379a2SJoe Stringer
7962b379a2SJoe Stringerdocs-clean: $(foreach doctarget,$(DOCTARGETS), docs-clean-$(doctarget))
8062b379a2SJoe Stringerdocs-install: $(foreach doctarget,$(DOCTARGETS), docs-install-$(doctarget))
8162b379a2SJoe Stringerdocs-uninstall: $(foreach doctarget,$(DOCTARGETS), docs-uninstall-$(doctarget))
8262b379a2SJoe Stringer
83accbd33aSJoe Stringer.PHONY: docs docs-clean docs-install docs-uninstall man2 man7
84