Makefile.docs 2.2 KB

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