Merge tag 'reset-for-v5.3' of git://git.pengutronix.de/git/pza/linux into arm/drivers
[sfrench/cifs-2.6.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   BPF_PATH = $(OUTPUT)
21 else
22   BPF_PATH = $(BPF_DIR)
23 endif
24
25 LIBBPF = $(BPF_PATH)libbpf.a
26
27 BPFTOOL_VERSION := $(shell make --no-print-directory -sC ../../.. kernelversion)
28
29 $(LIBBPF): FORCE
30         $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a
31
32 $(LIBBPF)-clean:
33         $(call QUIET_CLEAN, libbpf)
34         $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
35
36 prefix ?= /usr/local
37 bash_compdir ?= /usr/share/bash-completion/completions
38
39 CFLAGS += -O2
40 CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers
41 CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
42         -I$(srctree)/kernel/bpf/ \
43         -I$(srctree)/tools/include \
44         -I$(srctree)/tools/include/uapi \
45         -I$(srctree)/tools/lib/bpf \
46         -I$(srctree)/tools/perf
47 CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
48 ifneq ($(EXTRA_CFLAGS),)
49 CFLAGS += $(EXTRA_CFLAGS)
50 endif
51 ifneq ($(EXTRA_LDFLAGS),)
52 LDFLAGS += $(EXTRA_LDFLAGS)
53 endif
54
55 LIBS = -lelf $(LIBBPF)
56
57 INSTALL ?= install
58 RM ?= rm -f
59
60 FEATURE_USER = .bpftool
61 FEATURE_TESTS = libbfd disassembler-four-args reallocarray
62 FEATURE_DISPLAY = libbfd disassembler-four-args
63
64 check_feat := 1
65 NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
66 ifdef MAKECMDGOALS
67 ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
68   check_feat := 0
69 endif
70 endif
71
72 ifeq ($(check_feat),1)
73 ifeq ($(FEATURES_DUMP),)
74 include $(srctree)/tools/build/Makefile.feature
75 else
76 include $(FEATURES_DUMP)
77 endif
78 endif
79
80 ifeq ($(feature-disassembler-four-args), 1)
81 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
82 endif
83
84 ifeq ($(feature-reallocarray), 0)
85 CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
86 endif
87
88 include $(wildcard $(OUTPUT)*.d)
89
90 all: $(OUTPUT)bpftool
91
92 BFD_SRCS = jit_disasm.c
93
94 SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
95
96 ifeq ($(feature-libbfd),1)
97   LIBS += -lbfd -ldl -lopcodes
98 else ifeq ($(feature-libbfd-liberty),1)
99   LIBS += -lbfd -ldl -lopcodes -liberty
100 else ifeq ($(feature-libbfd-liberty-z),1)
101   LIBS += -lbfd -ldl -lopcodes -liberty -lz
102 endif
103
104 ifneq ($(filter -lbfd,$(LIBS)),)
105 CFLAGS += -DHAVE_LIBBFD_SUPPORT
106 SRCS += $(BFD_SRCS)
107 endif
108
109 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
110
111 $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
112         $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
113
114 $(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
115         $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
116
117 $(OUTPUT)%.o: %.c
118         $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
119
120 clean: $(LIBBPF)-clean
121         $(call QUIET_CLEAN, bpftool)
122         $(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
123         $(call QUIET_CLEAN, core-gen)
124         $(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool
125
126 install: $(OUTPUT)bpftool
127         $(call QUIET_INSTALL, bpftool)
128         $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin
129         $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool
130         $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir)
131         $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir)
132
133 uninstall:
134         $(call QUIET_UNINST, bpftool)
135         $(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
136         $(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool
137
138 doc:
139         $(call descend,Documentation)
140
141 doc-clean:
142         $(call descend,Documentation,clean)
143
144 doc-install:
145         $(call descend,Documentation,install)
146
147 doc-uninstall:
148         $(call descend,Documentation,uninstall)
149
150 FORCE:
151
152 .PHONY: all FORCE clean install uninstall
153 .PHONY: doc doc-clean doc-install doc-uninstall
154 .DEFAULT_GOAL := all