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 $(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 93BFD_SRCS = jit_disasm.c 94 95SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c)) 96 97ifeq ($(feature-libbfd),1) 98CFLAGS += -DHAVE_LIBBFD_SUPPORT 99SRCS += $(BFD_SRCS) 100LIBS += -lbfd -lopcodes 101endif 102 103OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o 104 105$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c 106 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< 107 108$(OUTPUT)bpftool: $(OBJS) $(LIBBPF) 109 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) 110 111$(OUTPUT)%.o: %.c 112 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< 113 114clean: $(LIBBPF)-clean 115 $(call QUIET_CLEAN, bpftool) 116 $(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d 117 $(call QUIET_CLEAN, core-gen) 118 $(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool 119 120install: $(OUTPUT)bpftool 121 $(call QUIET_INSTALL, bpftool) 122 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin 123 $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool 124 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir) 125 $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir) 126 127uninstall: 128 $(call QUIET_UNINST, bpftool) 129 $(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool 130 $(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool 131 132doc: 133 $(call descend,Documentation) 134 135doc-clean: 136 $(call descend,Documentation,clean) 137 138doc-install: 139 $(call descend,Documentation,install) 140 141doc-uninstall: 142 $(call descend,Documentation,uninstall) 143 144FORCE: 145 146.PHONY: all FORCE clean install uninstall 147.PHONY: doc doc-clean doc-install doc-uninstall 148.DEFAULT_GOAL := all 149