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