Makefile.docs 2.1 KB

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