xref: /openbmc/linux/tools/bpf/bpftool/Makefile (revision ba61bb17)
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 FEATURES_DUMP=$(FEATURE_DUMP_EXPORT)
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
38CC = gcc
39
40CFLAGS += -O2
41CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers
42CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
43	-I$(srctree)/kernel/bpf/ \
44	-I$(srctree)/tools/include \
45	-I$(srctree)/tools/include/uapi \
46	-I$(srctree)/tools/lib/bpf \
47	-I$(srctree)/tools/perf
48CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
49LIBS = -lelf -lbfd -lopcodes $(LIBBPF)
50
51INSTALL ?= install
52RM ?= rm -f
53
54FEATURE_USER = .bpftool
55FEATURE_TESTS = libbfd disassembler-four-args
56FEATURE_DISPLAY = libbfd disassembler-four-args
57
58check_feat := 1
59NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
60ifdef MAKECMDGOALS
61ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
62  check_feat := 0
63endif
64endif
65
66ifeq ($(check_feat),1)
67ifeq ($(FEATURES_DUMP),)
68include $(srctree)/tools/build/Makefile.feature
69else
70include $(FEATURES_DUMP)
71endif
72endif
73
74ifeq ($(feature-disassembler-four-args), 1)
75CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
76endif
77
78include $(wildcard $(OUTPUT)*.d)
79
80all: $(OUTPUT)bpftool
81
82SRCS = $(wildcard *.c)
83OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
84
85$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
86	$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
87
88$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
89	$(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
90
91$(OUTPUT)%.o: %.c
92	$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
93
94clean: $(LIBBPF)-clean
95	$(call QUIET_CLEAN, bpftool)
96	$(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
97	$(call QUIET_CLEAN, core-gen)
98	$(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool
99
100install: $(OUTPUT)bpftool
101	$(call QUIET_INSTALL, bpftool)
102	$(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin
103	$(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool
104	$(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir)
105	$(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir)
106
107uninstall:
108	$(call QUIET_UNINST, bpftool)
109	$(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
110	$(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool
111
112doc:
113	$(call descend,Documentation)
114
115doc-clean:
116	$(call descend,Documentation,clean)
117
118doc-install:
119	$(call descend,Documentation,install)
120
121doc-uninstall:
122	$(call descend,Documentation,uninstall)
123
124FORCE:
125
126.PHONY: all FORCE clean install uninstall
127.PHONY: doc doc-clean doc-install doc-uninstall
128.DEFAULT_GOAL := all
129