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