treewide: Add SPDX license identifier - Makefile/Kconfig
[linux-2.6-block.git] / tools / bpf / bpftool / Makefile
CommitLineData
ec8f24b7 1# SPDX-License-Identifier: GPL-2.0-only
71bb428f 2include ../../scripts/Makefile.include
71bb428f
JK
3include ../../scripts/utilities.mak
4
5ifeq ($(srctree),)
6srctree := $(patsubst %/,%,$(dir $(CURDIR)))
7srctree := $(patsubst %/,%,$(dir $(srctree)))
8srctree := $(patsubst %/,%,$(dir $(srctree)))
71bb428f
JK
9endif
10
11ifeq ($(V),1)
12 Q =
13else
14 Q = @
15endif
16
658e85aa 17BPF_DIR = $(srctree)/tools/lib/bpf/
71bb428f
JK
18
19ifneq ($(OUTPUT),)
658e85aa 20 BPF_PATH = $(OUTPUT)
71bb428f 21else
658e85aa 22 BPF_PATH = $(BPF_DIR)
71bb428f
JK
23endif
24
25LIBBPF = $(BPF_PATH)libbpf.a
26
c256429f 27BPFTOOL_VERSION := $(shell make --no-print-directory -sC ../../.. kernelversion)
4bfe3bd3 28
71bb428f 29$(LIBBPF): FORCE
dc989d2c 30 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a
71bb428f
JK
31
32$(LIBBPF)-clean:
33 $(call QUIET_CLEAN, libbpf)
34 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
35
658e85aa 36prefix ?= /usr/local
507e590d 37bash_compdir ?= /usr/share/bash-completion/completions
71bb428f 38
71bb428f 39CFLAGS += -O2
72ab55e9 40CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers
f412eed9
JK
41CFLAGS += -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
4bfe3bd3 47CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
0ef6bf39
JO
48ifneq ($(EXTRA_CFLAGS),)
49CFLAGS += $(EXTRA_CFLAGS)
50endif
c8506165
JO
51ifneq ($(EXTRA_LDFLAGS),)
52LDFLAGS += $(EXTRA_LDFLAGS)
53endif
0ef6bf39 54
29a9c10e 55LIBS = -lelf $(LIBBPF)
71bb428f 56
658e85aa
QM
57INSTALL ?= install
58RM ?= rm -f
59
fb982666 60FEATURE_USER = .bpftool
531b014e 61FEATURE_TESTS = libbfd disassembler-four-args reallocarray
fb982666
RG
62FEATURE_DISPLAY = libbfd disassembler-four-args
63
64check_feat := 1
65NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
66ifdef MAKECMDGOALS
67ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
68 check_feat := 0
69endif
70endif
71
72ifeq ($(check_feat),1)
73ifeq ($(FEATURES_DUMP),)
74include $(srctree)/tools/build/Makefile.feature
75else
76include $(FEATURES_DUMP)
77endif
78endif
79
80ifeq ($(feature-disassembler-four-args), 1)
81CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
82endif
83
531b014e
JK
84ifeq ($(feature-reallocarray), 0)
85CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
86endif
87
90126e3a 88include $(wildcard $(OUTPUT)*.d)
71bb428f
JK
89
90all: $(OUTPUT)bpftool
91
29a9c10e
SF
92BFD_SRCS = jit_disasm.c
93
94SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
95
96ifeq ($(feature-libbfd),1)
6e8ccb4f
SF
97 LIBS += -lbfd -ldl -lopcodes
98else ifeq ($(feature-libbfd-liberty),1)
99 LIBS += -lbfd -ldl -lopcodes -liberty
100else ifeq ($(feature-libbfd-liberty-z),1)
101 LIBS += -lbfd -ldl -lopcodes -liberty -lz
102endif
103
104ifneq ($(filter -lbfd,$(LIBS)),)
29a9c10e
SF
105CFLAGS += -DHAVE_LIBBFD_SUPPORT
106SRCS += $(BFD_SRCS)
29a9c10e
SF
107endif
108
658e85aa 109OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
c9c35995
JK
110
111$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
112 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
71bb428f
JK
113
114$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
c8506165 115 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
71bb428f
JK
116
117$(OUTPUT)%.o: %.c
118 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
119
120clean: $(LIBBPF)-clean
121 $(call QUIET_CLEAN, bpftool)
658e85aa 122 $(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
cc5b3403
JK
123 $(call QUIET_CLEAN, core-gen)
124 $(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool
71bb428f 125
658e85aa
QM
126install: $(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)
71bb428f 132
d3244248
QM
133uninstall:
134 $(call QUIET_UNINST, bpftool)
135 $(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
136 $(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool
137
ff69c21a 138doc:
658e85aa
QM
139 $(call descend,Documentation)
140
141doc-clean:
142 $(call descend,Documentation,clean)
ff69c21a
JK
143
144doc-install:
658e85aa 145 $(call descend,Documentation,install)
ff69c21a 146
d3244248
QM
147doc-uninstall:
148 $(call descend,Documentation,uninstall)
149
71bb428f
JK
150FORCE:
151
d3244248
QM
152.PHONY: all FORCE clean install uninstall
153.PHONY: doc doc-clean doc-install doc-uninstall
71bb428f 154.DEFAULT_GOAL := all