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