net: ipa: rename db_enable flag
[linux-2.6-microblaze.git] / tools / bpf / bpftool / Makefile
1 # SPDX-License-Identifier: GPL-2.0-only
2 include ../../scripts/Makefile.include
3 include ../../scripts/utilities.mak
4
5 ifeq ($(srctree),)
6 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
7 srctree := $(patsubst %/,%,$(dir $(srctree)))
8 srctree := $(patsubst %/,%,$(dir $(srctree)))
9 endif
10
11 ifeq ($(V),1)
12   Q =
13 else
14   Q = @
15 endif
16
17 BPF_DIR = $(srctree)/tools/lib/bpf/
18
19 ifneq ($(OUTPUT),)
20   LIBBPF_OUTPUT = $(OUTPUT)/libbpf/
21   LIBBPF_PATH = $(LIBBPF_OUTPUT)
22 else
23   LIBBPF_PATH = $(BPF_DIR)
24 endif
25
26 LIBBPF = $(LIBBPF_PATH)libbpf.a
27
28 BPFTOOL_VERSION := $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
29
30 $(LIBBPF): FORCE
31         $(if $(LIBBPF_OUTPUT),@mkdir -p $(LIBBPF_OUTPUT))
32         $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) $(LIBBPF_OUTPUT)libbpf.a
33
34 $(LIBBPF)-clean:
35         $(call QUIET_CLEAN, libbpf)
36         $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) clean >/dev/null
37
38 prefix ?= /usr/local
39 bash_compdir ?= /usr/share/bash-completion/completions
40
41 CFLAGS += -O2
42 CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers
43 CFLAGS += $(filter-out -Wswitch-enum,$(EXTRA_WARNINGS))
44 CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
45         -I$(srctree)/kernel/bpf/ \
46         -I$(srctree)/tools/include \
47         -I$(srctree)/tools/include/uapi \
48         -I$(srctree)/tools/lib \
49         -I$(srctree)/tools/perf
50 CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
51 ifneq ($(EXTRA_CFLAGS),)
52 CFLAGS += $(EXTRA_CFLAGS)
53 endif
54 ifneq ($(EXTRA_LDFLAGS),)
55 LDFLAGS += $(EXTRA_LDFLAGS)
56 endif
57
58 INSTALL ?= install
59 RM ?= rm -f
60 CLANG ?= clang
61
62 FEATURE_USER = .bpftool
63 FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib libcap \
64         clang-bpf-global-var
65 FEATURE_DISPLAY = libbfd disassembler-four-args zlib libcap \
66         clang-bpf-global-var
67
68 check_feat := 1
69 NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
70 ifdef MAKECMDGOALS
71 ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
72   check_feat := 0
73 endif
74 endif
75
76 ifeq ($(check_feat),1)
77 ifeq ($(FEATURES_DUMP),)
78 include $(srctree)/tools/build/Makefile.feature
79 else
80 include $(FEATURES_DUMP)
81 endif
82 endif
83
84 ifeq ($(feature-disassembler-four-args), 1)
85 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
86 endif
87
88 ifeq ($(feature-reallocarray), 0)
89 CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
90 endif
91
92 LIBS = $(LIBBPF) -lelf -lz
93 ifeq ($(feature-libcap), 1)
94 CFLAGS += -DUSE_LIBCAP
95 LIBS += -lcap
96 endif
97
98 include $(wildcard $(OUTPUT)*.d)
99
100 all: $(OUTPUT)bpftool
101
102 BFD_SRCS = jit_disasm.c
103
104 SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
105
106 ifeq ($(feature-libbfd),1)
107   LIBS += -lbfd -ldl -lopcodes
108 else ifeq ($(feature-libbfd-liberty),1)
109   LIBS += -lbfd -ldl -lopcodes -liberty
110 else ifeq ($(feature-libbfd-liberty-z),1)
111   LIBS += -lbfd -ldl -lopcodes -liberty -lz
112 endif
113
114 ifneq ($(filter -lbfd,$(LIBS)),)
115 CFLAGS += -DHAVE_LIBBFD_SUPPORT
116 SRCS += $(BFD_SRCS)
117 endif
118
119 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
120 _OBJS = $(filter-out $(OUTPUT)prog.o,$(OBJS)) $(OUTPUT)_prog.o
121
122 ifeq ($(feature-clang-bpf-global-var),1)
123         __OBJS = $(OBJS)
124 else
125         __OBJS = $(_OBJS)
126 endif
127
128 $(OUTPUT)_prog.o: prog.c
129         $(QUIET_CC)$(COMPILE.c) -MMD -DBPFTOOL_WITHOUT_SKELETONS -o $@ $<
130
131 $(OUTPUT)_bpftool: $(_OBJS) $(LIBBPF)
132         $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(_OBJS) $(LIBS)
133
134 skeleton/profiler.bpf.o: skeleton/profiler.bpf.c $(LIBBPF)
135         $(QUIET_CLANG)$(CLANG) \
136                 -I$(srctree)/tools/include/uapi/ \
137                 -I$(LIBBPF_PATH) -I$(srctree)/tools/lib \
138                 -g -O2 -target bpf -c $< -o $@
139
140 profiler.skel.h: $(OUTPUT)_bpftool skeleton/profiler.bpf.o
141         $(QUIET_GEN)$(OUTPUT)./_bpftool gen skeleton skeleton/profiler.bpf.o > $@
142
143 $(OUTPUT)prog.o: prog.c profiler.skel.h
144         $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
145
146 $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
147         $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
148
149 $(OUTPUT)feature.o: | zdep
150
151 $(OUTPUT)bpftool: $(__OBJS) $(LIBBPF)
152         $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(__OBJS) $(LIBS)
153
154 $(OUTPUT)%.o: %.c
155         $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
156
157 clean: $(LIBBPF)-clean
158         $(call QUIET_CLEAN, bpftool)
159         $(Q)$(RM) -- $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
160         $(Q)$(RM) -- $(OUTPUT)_bpftool profiler.skel.h skeleton/profiler.bpf.o
161         $(Q)$(RM) -r -- $(OUTPUT)libbpf/
162         $(call QUIET_CLEAN, core-gen)
163         $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpftool
164         $(Q)$(RM) -r -- $(OUTPUT)feature/
165
166 install: $(OUTPUT)bpftool
167         $(call QUIET_INSTALL, bpftool)
168         $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin
169         $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool
170         $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir)
171         $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir)
172
173 uninstall:
174         $(call QUIET_UNINST, bpftool)
175         $(Q)$(RM) -- $(DESTDIR)$(prefix)/sbin/bpftool
176         $(Q)$(RM) -- $(DESTDIR)$(bash_compdir)/bpftool
177
178 doc:
179         $(call descend,Documentation)
180
181 doc-clean:
182         $(call descend,Documentation,clean)
183
184 doc-install:
185         $(call descend,Documentation,install)
186
187 doc-uninstall:
188         $(call descend,Documentation,uninstall)
189
190 FORCE:
191
192 zdep:
193         @if [ "$(feature-zlib)" != "1" ]; then echo "No zlib found"; exit 1 ; fi
194
195 .PHONY: all FORCE clean install uninstall zdep
196 .PHONY: doc doc-clean doc-install doc-uninstall
197 .DEFAULT_GOAL := all