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 FEATURES_DUMP=$(FEATURE_DUMP_EXPORT) 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 42CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi -I$(srctree)/tools/include -I$(srctree)/tools/lib/bpf -I$(srctree)/kernel/bpf/ 43CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"' 44LIBS = -lelf -lbfd -lopcodes $(LIBBPF) 45 46INSTALL ?= install 47RM ?= rm -f 48 49FEATURE_USER = .bpftool 50FEATURE_TESTS = libbfd disassembler-four-args 51FEATURE_DISPLAY = libbfd disassembler-four-args 52 53check_feat := 1 54NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall 55ifdef MAKECMDGOALS 56ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) 57 check_feat := 0 58endif 59endif 60 61ifeq ($(check_feat),1) 62ifeq ($(FEATURES_DUMP),) 63include $(srctree)/tools/build/Makefile.feature 64else 65include $(FEATURES_DUMP) 66endif 67endif 68 69ifeq ($(feature-disassembler-four-args), 1) 70CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE 71endif 72 73include $(wildcard *.d) 74 75all: $(OUTPUT)bpftool 76 77SRCS = $(wildcard *.c) 78OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o 79 80$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c 81 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< 82 83$(OUTPUT)bpftool: $(OBJS) $(LIBBPF) 84 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ $(LIBS) 85 86$(OUTPUT)%.o: %.c 87 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< 88 89clean: $(LIBBPF)-clean 90 $(call QUIET_CLEAN, bpftool) 91 $(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d 92 93install: $(OUTPUT)bpftool 94 $(call QUIET_INSTALL, bpftool) 95 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin 96 $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool 97 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir) 98 $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir) 99 100uninstall: 101 $(call QUIET_UNINST, bpftool) 102 $(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool 103 $(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool 104 105doc: 106 $(call descend,Documentation) 107 108doc-clean: 109 $(call descend,Documentation,clean) 110 111doc-install: 112 $(call descend,Documentation,install) 113 114doc-uninstall: 115 $(call descend,Documentation,uninstall) 116 117FORCE: 118 119.PHONY: all FORCE clean install uninstall 120.PHONY: doc doc-clean doc-install doc-uninstall 121.DEFAULT_GOAL := all 122