2017-10-05 11:10:04 +08:00
|
|
|
include ../../scripts/Makefile.include
|
|
|
|
include ../../scripts/utilities.mak
|
|
|
|
|
|
|
|
ifeq ($(srctree),)
|
|
|
|
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
|
|
|
|
srctree := $(patsubst %/,%,$(dir $(srctree)))
|
|
|
|
srctree := $(patsubst %/,%,$(dir $(srctree)))
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(V),1)
|
|
|
|
Q =
|
|
|
|
else
|
|
|
|
Q = @
|
|
|
|
endif
|
|
|
|
|
2017-12-08 07:00:17 +08:00
|
|
|
BPF_DIR = $(srctree)/tools/lib/bpf/
|
2017-10-05 11:10:04 +08:00
|
|
|
|
|
|
|
ifneq ($(OUTPUT),)
|
2017-12-08 07:00:17 +08:00
|
|
|
BPF_PATH = $(OUTPUT)
|
2017-10-05 11:10:04 +08:00
|
|
|
else
|
2017-12-08 07:00:17 +08:00
|
|
|
BPF_PATH = $(BPF_DIR)
|
2017-10-05 11:10:04 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
LIBBPF = $(BPF_PATH)libbpf.a
|
|
|
|
|
2018-06-29 05:41:35 +08:00
|
|
|
BPFTOOL_VERSION := $(shell make --no-print-directory -sC ../../.. kernelversion)
|
2017-12-28 03:16:28 +08:00
|
|
|
|
2017-10-05 11:10:04 +08:00
|
|
|
$(LIBBPF): FORCE
|
2018-07-17 01:57:16 +08:00
|
|
|
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a
|
2017-10-05 11:10:04 +08:00
|
|
|
|
|
|
|
$(LIBBPF)-clean:
|
|
|
|
$(call QUIET_CLEAN, libbpf)
|
|
|
|
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
|
|
|
|
|
2017-12-08 07:00:17 +08:00
|
|
|
prefix ?= /usr/local
|
tools: bpftool: unify installation directories
Programs and documentation not managed by package manager are generally
installed under /usr/local/, instead of the user's home directory. In
particular, `man` is generally able to find manual pages under
`/usr/local/share/man`.
bpftool generally follows perf's example, and perf installs to home
directory. However bpftool requires root credentials, so it seems
sensible to follow the more common convention of installing files under
/usr/local instead. So, make /usr/local the default prefix for
installing the binary with `make install`, and the documentation with
`make doc-install`. Also, create /usr/local/sbin if it does not exist.
Note that the bash-completion file, however, is still installed under
/usr/share/bash-completion/completions, as the default setup for bash
does not attempt to load completion files under /usr/local/.
Reported-by: David Beckett <david.beckett@netronome.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2017-11-29 09:44:32 +08:00
|
|
|
bash_compdir ?= /usr/share/bash-completion/completions
|
2017-10-05 11:10:04 +08:00
|
|
|
|
|
|
|
CFLAGS += -O2
|
2018-03-09 06:00:35 +08:00
|
|
|
CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers
|
2018-05-04 09:37:16 +08:00
|
|
|
CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
|
|
|
|
-I$(srctree)/kernel/bpf/ \
|
|
|
|
-I$(srctree)/tools/include \
|
|
|
|
-I$(srctree)/tools/include/uapi \
|
|
|
|
-I$(srctree)/tools/lib/bpf \
|
|
|
|
-I$(srctree)/tools/perf
|
2017-12-28 03:16:28 +08:00
|
|
|
CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
|
2018-10-08 16:22:58 +08:00
|
|
|
ifneq ($(EXTRA_CFLAGS),)
|
|
|
|
CFLAGS += $(EXTRA_CFLAGS)
|
|
|
|
endif
|
2018-10-08 16:22:59 +08:00
|
|
|
ifneq ($(EXTRA_LDFLAGS),)
|
|
|
|
LDFLAGS += $(EXTRA_LDFLAGS)
|
|
|
|
endif
|
2018-10-08 16:22:58 +08:00
|
|
|
|
2018-11-13 05:44:10 +08:00
|
|
|
LIBS = -lelf $(LIBBPF)
|
2017-10-05 11:10:04 +08:00
|
|
|
|
2017-12-08 07:00:17 +08:00
|
|
|
INSTALL ?= install
|
|
|
|
RM ?= rm -f
|
|
|
|
|
2017-12-28 03:16:29 +08:00
|
|
|
FEATURE_USER = .bpftool
|
2018-07-11 05:43:05 +08:00
|
|
|
FEATURE_TESTS = libbfd disassembler-four-args reallocarray
|
2017-12-28 03:16:29 +08:00
|
|
|
FEATURE_DISPLAY = libbfd disassembler-four-args
|
|
|
|
|
|
|
|
check_feat := 1
|
|
|
|
NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
|
|
|
|
ifdef MAKECMDGOALS
|
|
|
|
ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
|
|
|
|
check_feat := 0
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(check_feat),1)
|
|
|
|
ifeq ($(FEATURES_DUMP),)
|
|
|
|
include $(srctree)/tools/build/Makefile.feature
|
|
|
|
else
|
|
|
|
include $(FEATURES_DUMP)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(feature-disassembler-four-args), 1)
|
|
|
|
CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
|
|
|
|
endif
|
|
|
|
|
2018-07-11 05:43:05 +08:00
|
|
|
ifeq ($(feature-reallocarray), 0)
|
|
|
|
CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
|
|
|
|
endif
|
|
|
|
|
2018-03-16 14:26:14 +08:00
|
|
|
include $(wildcard $(OUTPUT)*.d)
|
2017-10-05 11:10:04 +08:00
|
|
|
|
|
|
|
all: $(OUTPUT)bpftool
|
|
|
|
|
2018-11-13 05:44:10 +08:00
|
|
|
BFD_SRCS = jit_disasm.c
|
|
|
|
|
|
|
|
SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
|
|
|
|
|
|
|
|
ifeq ($(feature-libbfd),1)
|
|
|
|
CFLAGS += -DHAVE_LIBBFD_SUPPORT
|
|
|
|
SRCS += $(BFD_SRCS)
|
|
|
|
LIBS += -lbfd -lopcodes
|
|
|
|
endif
|
|
|
|
|
2017-12-08 07:00:17 +08:00
|
|
|
OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
|
2017-10-10 01:30:13 +08:00
|
|
|
|
|
|
|
$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
|
|
|
|
$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
|
2017-10-05 11:10:04 +08:00
|
|
|
|
|
|
|
$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
|
2018-10-08 16:22:59 +08:00
|
|
|
$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
|
2017-10-05 11:10:04 +08:00
|
|
|
|
|
|
|
$(OUTPUT)%.o: %.c
|
|
|
|
$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
|
|
|
|
|
|
|
|
clean: $(LIBBPF)-clean
|
|
|
|
$(call QUIET_CLEAN, bpftool)
|
2017-12-08 07:00:17 +08:00
|
|
|
$(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
|
2018-03-16 14:26:17 +08:00
|
|
|
$(call QUIET_CLEAN, core-gen)
|
|
|
|
$(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool
|
2017-10-05 11:10:04 +08:00
|
|
|
|
2017-12-08 07:00:17 +08:00
|
|
|
install: $(OUTPUT)bpftool
|
|
|
|
$(call QUIET_INSTALL, bpftool)
|
|
|
|
$(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin
|
|
|
|
$(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool
|
|
|
|
$(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir)
|
|
|
|
$(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir)
|
2017-10-05 11:10:04 +08:00
|
|
|
|
2017-12-08 07:00:18 +08:00
|
|
|
uninstall:
|
|
|
|
$(call QUIET_UNINST, bpftool)
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool
|
|
|
|
|
2017-10-05 11:10:05 +08:00
|
|
|
doc:
|
2017-12-08 07:00:17 +08:00
|
|
|
$(call descend,Documentation)
|
|
|
|
|
|
|
|
doc-clean:
|
|
|
|
$(call descend,Documentation,clean)
|
2017-10-05 11:10:05 +08:00
|
|
|
|
|
|
|
doc-install:
|
2017-12-08 07:00:17 +08:00
|
|
|
$(call descend,Documentation,install)
|
2017-10-05 11:10:05 +08:00
|
|
|
|
2017-12-08 07:00:18 +08:00
|
|
|
doc-uninstall:
|
|
|
|
$(call descend,Documentation,uninstall)
|
|
|
|
|
2017-10-05 11:10:04 +08:00
|
|
|
FORCE:
|
|
|
|
|
2017-12-08 07:00:18 +08:00
|
|
|
.PHONY: all FORCE clean install uninstall
|
|
|
|
.PHONY: doc doc-clean doc-install doc-uninstall
|
2017-10-05 11:10:04 +08:00
|
|
|
.DEFAULT_GOAL := all
|