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