2019-05-19 12:07:45 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
2017-10-05 03:10:04 +00: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-07 23:00:17 +00:00
|
|
|
BPF_DIR = $(srctree)/tools/lib/bpf/
|
2017-10-05 03:10:04 +00:00
|
|
|
|
|
|
|
ifneq ($(OUTPUT),)
|
2017-12-07 23:00:17 +00:00
|
|
|
BPF_PATH = $(OUTPUT)
|
2017-10-05 03:10:04 +00:00
|
|
|
else
|
2017-12-07 23:00:17 +00:00
|
|
|
BPF_PATH = $(BPF_DIR)
|
2017-10-05 03:10:04 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
LIBBPF = $(BPF_PATH)libbpf.a
|
|
|
|
|
2018-06-28 21:41:35 +00:00
|
|
|
BPFTOOL_VERSION := $(shell make --no-print-directory -sC ../../.. kernelversion)
|
2017-12-27 19:16:28 +00:00
|
|
|
|
2017-10-05 03:10:04 +00:00
|
|
|
$(LIBBPF): FORCE
|
2018-07-16 17:57:16 +00:00
|
|
|
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a
|
2017-10-05 03:10:04 +00:00
|
|
|
|
|
|
|
$(LIBBPF)-clean:
|
|
|
|
$(call QUIET_CLEAN, libbpf)
|
|
|
|
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
|
|
|
|
|
2017-12-07 23:00:17 +00: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 01:44:32 +00:00
|
|
|
bash_compdir ?= /usr/share/bash-completion/completions
|
2017-10-05 03:10:04 +00:00
|
|
|
|
|
|
|
CFLAGS += -O2
|
2018-03-08 22:00:35 +00:00
|
|
|
CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers
|
2018-05-04 01:37:16 +00: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-27 19:16:28 +00:00
|
|
|
CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
|
2018-10-08 08:22:58 +00:00
|
|
|
ifneq ($(EXTRA_CFLAGS),)
|
|
|
|
CFLAGS += $(EXTRA_CFLAGS)
|
|
|
|
endif
|
2018-10-08 08:22:59 +00:00
|
|
|
ifneq ($(EXTRA_LDFLAGS),)
|
|
|
|
LDFLAGS += $(EXTRA_LDFLAGS)
|
|
|
|
endif
|
2018-10-08 08:22:58 +00:00
|
|
|
|
2018-11-12 21:44:10 +00:00
|
|
|
LIBS = -lelf $(LIBBPF)
|
2017-10-05 03:10:04 +00:00
|
|
|
|
2017-12-07 23:00:17 +00:00
|
|
|
INSTALL ?= install
|
|
|
|
RM ?= rm -f
|
|
|
|
|
2017-12-27 19:16:29 +00:00
|
|
|
FEATURE_USER = .bpftool
|
2018-07-10 21:43:05 +00:00
|
|
|
FEATURE_TESTS = libbfd disassembler-four-args reallocarray
|
2017-12-27 19:16:29 +00: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-10 21:43:05 +00:00
|
|
|
ifeq ($(feature-reallocarray), 0)
|
|
|
|
CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
|
|
|
|
endif
|
|
|
|
|
2018-03-16 06:26:14 +00:00
|
|
|
include $(wildcard $(OUTPUT)*.d)
|
2017-10-05 03:10:04 +00:00
|
|
|
|
|
|
|
all: $(OUTPUT)bpftool
|
|
|
|
|
2018-11-12 21:44:10 +00:00
|
|
|
BFD_SRCS = jit_disasm.c
|
|
|
|
|
|
|
|
SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
|
|
|
|
|
|
|
|
ifeq ($(feature-libbfd),1)
|
2019-01-15 22:03:27 +00:00
|
|
|
LIBS += -lbfd -ldl -lopcodes
|
|
|
|
else ifeq ($(feature-libbfd-liberty),1)
|
|
|
|
LIBS += -lbfd -ldl -lopcodes -liberty
|
|
|
|
else ifeq ($(feature-libbfd-liberty-z),1)
|
|
|
|
LIBS += -lbfd -ldl -lopcodes -liberty -lz
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(filter -lbfd,$(LIBS)),)
|
2018-11-12 21:44:10 +00:00
|
|
|
CFLAGS += -DHAVE_LIBBFD_SUPPORT
|
|
|
|
SRCS += $(BFD_SRCS)
|
|
|
|
endif
|
|
|
|
|
2017-12-07 23:00:17 +00:00
|
|
|
OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
|
2017-10-09 17:30:13 +00:00
|
|
|
|
|
|
|
$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
|
|
|
|
$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
|
2017-10-05 03:10:04 +00:00
|
|
|
|
|
|
|
$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
|
2018-10-08 08:22:59 +00:00
|
|
|
$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
|
2017-10-05 03:10:04 +00:00
|
|
|
|
|
|
|
$(OUTPUT)%.o: %.c
|
|
|
|
$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
|
|
|
|
|
|
|
|
clean: $(LIBBPF)-clean
|
|
|
|
$(call QUIET_CLEAN, bpftool)
|
2017-12-07 23:00:17 +00:00
|
|
|
$(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
|
2018-03-16 06:26:17 +00:00
|
|
|
$(call QUIET_CLEAN, core-gen)
|
|
|
|
$(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool
|
2017-10-05 03:10:04 +00:00
|
|
|
|
2017-12-07 23:00:17 +00: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 03:10:04 +00:00
|
|
|
|
2017-12-07 23:00:18 +00:00
|
|
|
uninstall:
|
|
|
|
$(call QUIET_UNINST, bpftool)
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool
|
|
|
|
|
2017-10-05 03:10:05 +00:00
|
|
|
doc:
|
2017-12-07 23:00:17 +00:00
|
|
|
$(call descend,Documentation)
|
|
|
|
|
|
|
|
doc-clean:
|
|
|
|
$(call descend,Documentation,clean)
|
2017-10-05 03:10:05 +00:00
|
|
|
|
|
|
|
doc-install:
|
2017-12-07 23:00:17 +00:00
|
|
|
$(call descend,Documentation,install)
|
2017-10-05 03:10:05 +00:00
|
|
|
|
2017-12-07 23:00:18 +00:00
|
|
|
doc-uninstall:
|
|
|
|
$(call descend,Documentation,uninstall)
|
|
|
|
|
2017-10-05 03:10:04 +00:00
|
|
|
FORCE:
|
|
|
|
|
2017-12-07 23:00:18 +00:00
|
|
|
.PHONY: all FORCE clean install uninstall
|
|
|
|
.PHONY: doc doc-clean doc-install doc-uninstall
|
2017-10-05 03:10:04 +00:00
|
|
|
.DEFAULT_GOAL := all
|