xref: /openbmc/linux/tools/bpf/bpftool/Makefile (revision 565485b8)
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)
96CFLAGS += -DHAVE_LIBBFD_SUPPORT
97SRCS += $(BFD_SRCS)
98LIBS += -lbfd -lopcodes
99endif
100
101OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
102
103$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
104	$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
105
106$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
107	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
108
109$(OUTPUT)%.o: %.c
110	$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
111
112clean: $(LIBBPF)-clean
113	$(call QUIET_CLEAN, bpftool)
114	$(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
115	$(call QUIET_CLEAN, core-gen)
116	$(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool
117
118install: $(OUTPUT)bpftool
119	$(call QUIET_INSTALL, bpftool)
120	$(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin
121	$(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool
122	$(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir)
123	$(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir)
124
125uninstall:
126	$(call QUIET_UNINST, bpftool)
127	$(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
128	$(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool
129
130doc:
131	$(call descend,Documentation)
132
133doc-clean:
134	$(call descend,Documentation,clean)
135
136doc-install:
137	$(call descend,Documentation,install)
138
139doc-uninstall:
140	$(call descend,Documentation,uninstall)
141
142FORCE:
143
144.PHONY: all FORCE clean install uninstall
145.PHONY: doc doc-clean doc-install doc-uninstall
146.DEFAULT_GOAL := all
147