GNU Linux-libre 4.19.263-gnu1
[releases.git] / tools / bpf / bpftool / Makefile
1 include ../../scripts/Makefile.include
2 include ../../scripts/utilities.mak
3
4 ifeq ($(srctree),)
5 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
6 srctree := $(patsubst %/,%,$(dir $(srctree)))
7 srctree := $(patsubst %/,%,$(dir $(srctree)))
8 endif
9
10 ifeq ($(V),1)
11   Q =
12 else
13   Q = @
14 endif
15
16 BPF_DIR = $(srctree)/tools/lib/bpf/
17
18 ifneq ($(OUTPUT),)
19   BPF_PATH = $(OUTPUT)
20 else
21   BPF_PATH = $(BPF_DIR)
22 endif
23
24 LIBBPF = $(BPF_PATH)libbpf.a
25
26 BPFTOOL_VERSION := $(shell make --no-print-directory -sC ../../.. kernelversion)
27
28 $(LIBBPF): FORCE
29         $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a
30
31 $(LIBBPF)-clean:
32         $(call QUIET_CLEAN, libbpf)
33         $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
34
35 prefix ?= /usr/local
36 bash_compdir ?= /usr/share/bash-completion/completions
37
38 CC = gcc
39
40 CFLAGS += -O2
41 CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers
42 CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
43         -I$(srctree)/kernel/bpf/ \
44         -I$(srctree)/tools/include \
45         -I$(srctree)/tools/include/uapi \
46         -I$(srctree)/tools/lib/bpf \
47         -I$(srctree)/tools/perf
48 CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
49 LIBS = -lelf -lbfd -lopcodes $(LIBBPF)
50
51 INSTALL ?= install
52 RM ?= rm -f
53
54 FEATURE_USER = .bpftool
55 FEATURE_TESTS = libbfd disassembler-four-args reallocarray
56 FEATURE_DISPLAY = libbfd disassembler-four-args
57
58 check_feat := 1
59 NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
60 ifdef MAKECMDGOALS
61 ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
62   check_feat := 0
63 endif
64 endif
65
66 ifeq ($(check_feat),1)
67 ifeq ($(FEATURES_DUMP),)
68 include $(srctree)/tools/build/Makefile.feature
69 else
70 include $(FEATURES_DUMP)
71 endif
72 endif
73
74 ifeq ($(feature-disassembler-four-args), 1)
75 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
76 endif
77
78 ifeq ($(feature-reallocarray), 0)
79 CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
80 endif
81
82 include $(wildcard $(OUTPUT)*.d)
83
84 all: $(OUTPUT)bpftool
85
86 SRCS = $(wildcard *.c)
87 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
88
89 $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
90         $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
91
92 $(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
93         $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
94
95 $(OUTPUT)%.o: %.c
96         $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
97
98 clean: $(LIBBPF)-clean
99         $(call QUIET_CLEAN, bpftool)
100         $(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
101         $(call QUIET_CLEAN, core-gen)
102         $(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool
103
104 install: $(OUTPUT)bpftool
105         $(call QUIET_INSTALL, bpftool)
106         $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin
107         $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool
108         $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir)
109         $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir)
110
111 uninstall:
112         $(call QUIET_UNINST, bpftool)
113         $(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
114         $(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool
115
116 doc:
117         $(call descend,Documentation)
118
119 doc-clean:
120         $(call descend,Documentation,clean)
121
122 doc-install:
123         $(call descend,Documentation,install)
124
125 doc-uninstall:
126         $(call descend,Documentation,uninstall)
127
128 FORCE:
129
130 .PHONY: all FORCE clean install uninstall
131 .PHONY: doc doc-clean doc-install doc-uninstall
132 .DEFAULT_GOAL := all