18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ciinclude ../../../scripts/Makefile.include
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ciINSTALL ?= install
58c2ecf20Sopenharmony_ciRM ?= rm -f
68c2ecf20Sopenharmony_ciRMDIR ?= rmdir --ignore-fail-on-non-empty
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciifeq ($(V),1)
98c2ecf20Sopenharmony_ci  Q =
108c2ecf20Sopenharmony_cielse
118c2ecf20Sopenharmony_ci  Q = @
128c2ecf20Sopenharmony_ciendif
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciprefix ?= /usr/local
158c2ecf20Sopenharmony_cimandir ?= $(prefix)/man
168c2ecf20Sopenharmony_ciman8dir = $(mandir)/man8
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci# Load targets for building eBPF helpers man page.
198c2ecf20Sopenharmony_ciinclude ../../Makefile.helpers
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ciMAN8_RST = $(wildcard bpftool*.rst)
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci_DOC_MAN8 = $(patsubst %.rst,%.8,$(MAN8_RST))
248c2ecf20Sopenharmony_ciDOC_MAN8 = $(addprefix $(OUTPUT),$(_DOC_MAN8))
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ciman: man8 helpers
278c2ecf20Sopenharmony_ciman8: $(DOC_MAN8)
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciRST2MAN_DEP := $(shell command -v rst2man 2>/dev/null)
308c2ecf20Sopenharmony_ciRST2MAN_OPTS += --verbose
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cilist_pages = $(sort $(basename $(filter-out $(1),$(MAN8_RST))))
338c2ecf20Sopenharmony_cisee_also = $(subst " ",, \
348c2ecf20Sopenharmony_ci	"\n" \
358c2ecf20Sopenharmony_ci	"SEE ALSO\n" \
368c2ecf20Sopenharmony_ci	"========\n" \
378c2ecf20Sopenharmony_ci	"\t**bpf**\ (2),\n" \
388c2ecf20Sopenharmony_ci	"\t**bpf-helpers**\\ (7)" \
398c2ecf20Sopenharmony_ci	$(foreach page,$(call list_pages,$(1)),",\n\t**$(page)**\\ (8)") \
408c2ecf20Sopenharmony_ci	"\n")
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci$(OUTPUT)%.8: %.rst
438c2ecf20Sopenharmony_ciifndef RST2MAN_DEP
448c2ecf20Sopenharmony_ci	$(error "rst2man not found, but required to generate man pages")
458c2ecf20Sopenharmony_ciendif
468c2ecf20Sopenharmony_ci	$(QUIET_GEN)( cat $< ; printf "%b" $(call see_also,$<) ) | rst2man $(RST2MAN_OPTS) > $@
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciclean: helpers-clean
498c2ecf20Sopenharmony_ci	$(call QUIET_CLEAN, Documentation)
508c2ecf20Sopenharmony_ci	$(Q)$(RM) $(DOC_MAN8)
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ciinstall: man helpers-install
538c2ecf20Sopenharmony_ci	$(call QUIET_INSTALL, Documentation-man)
548c2ecf20Sopenharmony_ci	$(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(man8dir)
558c2ecf20Sopenharmony_ci	$(Q)$(INSTALL) -m 644 $(DOC_MAN8) $(DESTDIR)$(man8dir)
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ciuninstall: helpers-uninstall
588c2ecf20Sopenharmony_ci	$(call QUIET_UNINST, Documentation-man)
598c2ecf20Sopenharmony_ci	$(Q)$(RM) $(addprefix $(DESTDIR)$(man8dir)/,$(_DOC_MAN8))
608c2ecf20Sopenharmony_ci	$(Q)$(RMDIR) $(DESTDIR)$(man8dir)
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci.PHONY: man man8 clean install uninstall
638c2ecf20Sopenharmony_ci.DEFAULT_GOAL := man
64