Makefile 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
  2. include ../../../scripts/Makefile.include
  3. INSTALL ?= install
  4. RM ?= rm -f
  5. RMDIR ?= rmdir --ignore-fail-on-non-empty
  6. ifeq ($(V),1)
  7. Q =
  8. else
  9. Q = @
  10. endif
  11. prefix ?= /usr/local
  12. mandir ?= $(prefix)/man
  13. man8dir = $(mandir)/man8
  14. MAN8_RST = $(wildcard bpftool*.rst)
  15. _DOC_MAN8 = $(patsubst %.rst,%.8,$(MAN8_RST))
  16. DOC_MAN8 = $(addprefix $(OUTPUT),$(_DOC_MAN8))
  17. man: man8
  18. man8: $(DOC_MAN8)
  19. RST2MAN_DEP := $(shell command -v rst2man 2>/dev/null)
  20. RST2MAN_OPTS += --verbose --strip-comments
  21. list_pages = $(sort $(basename $(filter-out $(1),$(MAN8_RST))))
  22. see_also = $(subst " ",, \
  23. "\n" \
  24. "SEE ALSO\n" \
  25. "========\n" \
  26. "\t**bpf**\ (2),\n" \
  27. "\t**bpf-helpers**\\ (7)" \
  28. $(foreach page,$(call list_pages,$(1)),",\n\t**$(page)**\\ (8)") \
  29. "\n")
  30. $(OUTPUT)%.8: %.rst
  31. ifndef RST2MAN_DEP
  32. $(error "rst2man not found, but required to generate man pages")
  33. endif
  34. $(QUIET_GEN)( cat $< ; printf "%b" $(call see_also,$<) ) | rst2man $(RST2MAN_OPTS) > $@
  35. clean:
  36. $(call QUIET_CLEAN, Documentation)
  37. $(Q)$(RM) $(DOC_MAN8)
  38. install: man
  39. $(call QUIET_INSTALL, Documentation-man)
  40. $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(man8dir)
  41. $(Q)$(INSTALL) -m 644 $(DOC_MAN8) $(DESTDIR)$(man8dir)
  42. uninstall:
  43. $(call QUIET_UNINST, Documentation-man)
  44. $(Q)$(RM) $(addprefix $(DESTDIR)$(man8dir)/,$(_DOC_MAN8))
  45. $(Q)$(RMDIR) $(DESTDIR)$(man8dir)
  46. .PHONY: man man8 clean install uninstall
  47. .DEFAULT_GOAL := man