1# SPDX-License-Identifier: GPL-2.0-only 2 3include ../../../scripts/Makefile.include 4include ../../../scripts/utilities.mak 5 6INSTALL ?= install 7RM ?= rm -f 8RMDIR ?= rmdir --ignore-fail-on-non-empty 9 10ifeq ($(V),1) 11 Q = 12else 13 Q = @ 14endif 15 16prefix ?= /usr/local 17mandir ?= $(prefix)/man 18man2dir = $(mandir)/man2 19man7dir = $(mandir)/man7 20 21SYSCALL_RST = bpf-syscall.rst 22MAN2_RST = $(SYSCALL_RST) 23 24HELPERS_RST = bpf-helpers.rst 25MAN7_RST = $(HELPERS_RST) 26 27_DOC_MAN2 = $(patsubst %.rst,%.2,$(MAN2_RST)) 28DOC_MAN2 = $(addprefix $(OUTPUT),$(_DOC_MAN2)) 29 30_DOC_MAN7 = $(patsubst %.rst,%.7,$(MAN7_RST)) 31DOC_MAN7 = $(addprefix $(OUTPUT),$(_DOC_MAN7)) 32 33DOCTARGETS := helpers syscall 34 35docs: $(DOCTARGETS) 36syscall: man2 37helpers: man7 38man2: $(DOC_MAN2) 39man7: $(DOC_MAN7) 40 41RST2MAN_DEP := $(shell command -v rst2man 2>/dev/null) 42 43# Configure make rules for the man page bpf-$1.$2. 44# $1 - target for scripts/bpf_doc.py 45# $2 - man page section to generate the troff file 46define DOCS_RULES = 47$(OUTPUT)bpf-$1.rst: ../../../../include/uapi/linux/bpf.h 48 $$(QUIET_GEN)../../../../scripts/bpf_doc.py $1 \ 49 --filename $$< > $$@ 50 51$(OUTPUT)%.$2: $(OUTPUT)%.rst 52ifndef RST2MAN_DEP 53 $$(error "rst2man not found, but required to generate man pages") 54endif 55 $$(QUIET_GEN)rst2man $$< > $$@ 56 57docs-clean-$1: 58 $$(call QUIET_CLEAN, eBPF_$1-manpage) 59 $(Q)$(RM) $$(DOC_MAN$2) $(OUTPUT)bpf-$1.rst 60 61docs-install-$1: docs 62 $$(call QUIET_INSTALL, eBPF_$1-manpage) 63 $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$$(man$2dir) 64 $(Q)$(INSTALL) -m 644 $$(DOC_MAN$2) $(DESTDIR)$$(man$2dir) 65 66docs-uninstall-$1: 67 $$(call QUIET_UNINST, eBPF_$1-manpage) 68 $(Q)$(RM) $$(addprefix $(DESTDIR)$$(man$2dir)/,$$(_DOC_MAN$2)) 69 $(Q)$(RMDIR) $(DESTDIR)$$(man$2dir) 70 71.PHONY: $1 docs-clean-$1 docs-install-$1 docs-uninstall-$1 72endef 73 74# Create the make targets to generate manual pages by name and section 75$(eval $(call DOCS_RULES,helpers,7)) 76$(eval $(call DOCS_RULES,syscall,2)) 77 78docs-clean: $(foreach doctarget,$(DOCTARGETS), docs-clean-$(doctarget)) 79docs-install: $(foreach doctarget,$(DOCTARGETS), docs-install-$(doctarget)) 80docs-uninstall: $(foreach doctarget,$(DOCTARGETS), docs-uninstall-$(doctarget)) 81 82.PHONY: docs docs-clean docs-install docs-uninstall man2 man7 83