GNU Linux-libre 4.19.286-gnu1
[releases.git] / tools / bpf / Makefile.helpers
1 ifndef allow-override
2   include ../scripts/Makefile.include
3   include ../scripts/utilities.mak
4 else
5   # Assume Makefile.helpers is being run from bpftool/Documentation
6   # subdirectory. Go up two more directories to fetch bpf.h header and
7   # associated script.
8   UP2DIR := ../../
9 endif
10
11 INSTALL ?= install
12 RM ?= rm -f
13 RMDIR ?= rmdir --ignore-fail-on-non-empty
14
15 ifeq ($(V),1)
16   Q =
17 else
18   Q = @
19 endif
20
21 prefix ?= /usr/local
22 mandir ?= $(prefix)/man
23 man7dir = $(mandir)/man7
24
25 HELPERS_RST = bpf-helpers.rst
26 MAN7_RST = $(HELPERS_RST)
27
28 _DOC_MAN7 = $(patsubst %.rst,%.7,$(MAN7_RST))
29 DOC_MAN7 = $(addprefix $(OUTPUT),$(_DOC_MAN7))
30
31 helpers: man7
32 man7: $(DOC_MAN7)
33
34 RST2MAN_DEP := $(shell command -v rst2man 2>/dev/null)
35
36 $(OUTPUT)$(HELPERS_RST): $(UP2DIR)../../include/uapi/linux/bpf.h
37         $(QUIET_GEN)$(UP2DIR)../../scripts/bpf_helpers_doc.py --filename $< > $@
38
39 $(OUTPUT)%.7: $(OUTPUT)%.rst
40 ifndef RST2MAN_DEP
41         $(error "rst2man not found, but required to generate man pages")
42 endif
43         $(QUIET_GEN)rst2man $< > $@
44
45 helpers-clean:
46         $(call QUIET_CLEAN, eBPF_helpers-manpage)
47         $(Q)$(RM) $(DOC_MAN7) $(OUTPUT)$(HELPERS_RST)
48
49 helpers-install: helpers
50         $(call QUIET_INSTALL, eBPF_helpers-manpage)
51         $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(man7dir)
52         $(Q)$(INSTALL) -m 644 $(DOC_MAN7) $(DESTDIR)$(man7dir)
53
54 helpers-uninstall:
55         $(call QUIET_UNINST, eBPF_helpers-manpage)
56         $(Q)$(RM) $(addprefix $(DESTDIR)$(man7dir)/,$(_DOC_MAN7))
57         $(Q)$(RMDIR) $(DESTDIR)$(man7dir)
58
59 .PHONY: helpers helpers-clean helpers-install helpers-uninstall