blob: 74288a2197abfcbf8763984516faee7f19253b50 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001include ../../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)"'
49LIBS = -lelf -lbfd -lopcodes $(LIBBPF)
50
51INSTALL ?= install
52RM ?= rm -f
53
54FEATURE_USER = .bpftool
55FEATURE_TESTS = libbfd disassembler-four-args reallocarray
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
78ifeq ($(feature-reallocarray), 0)
79CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
80endif
81
82include $(wildcard $(OUTPUT)*.d)
83
84all: $(OUTPUT)bpftool
85
86SRCS = $(wildcard *.c)
87OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
88
89$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
90 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
91
92$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
93 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
94
95$(OUTPUT)%.o: %.c
96 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
97
98clean: $(LIBBPF)-clean
99 $(call QUIET_CLEAN, bpftool)
100 $(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
101 $(call QUIET_CLEAN, core-gen)
102 $(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool
103
104install: $(OUTPUT)bpftool
105 $(call QUIET_INSTALL, bpftool)
106 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin
107 $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool
108 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir)
109 $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir)
110
111uninstall:
112 $(call QUIET_UNINST, bpftool)
113 $(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
114 $(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool
115
116doc:
117 $(call descend,Documentation)
118
119doc-clean:
120 $(call descend,Documentation,clean)
121
122doc-install:
123 $(call descend,Documentation,install)
124
125doc-uninstall:
126 $(call descend,Documentation,uninstall)
127
128FORCE:
129
130.PHONY: all FORCE clean install uninstall
131.PHONY: doc doc-clean doc-install doc-uninstall
132.DEFAULT_GOAL := all