1include ../../scripts/Makefile.include 2 3include ../../scripts/utilities.mak 4 5ifeq ($(srctree),) 6srctree := $(patsubst %/,%,$(dir $(CURDIR))) 7srctree := $(patsubst %/,%,$(dir $(srctree))) 8srctree := $(patsubst %/,%,$(dir $(srctree))) 9#$(info Determined 'srctree' to be $(srctree)) 10endif 11 12ifneq ($(objtree),) 13#$(info Determined 'objtree' to be $(objtree)) 14endif 15 16ifneq ($(OUTPUT),) 17#$(info Determined 'OUTPUT' to be $(OUTPUT)) 18# Adding $(OUTPUT) as a directory to look for source files, 19# because use generated output files as sources dependency 20# for flex/bison parsers. 21VPATH += $(OUTPUT) 22export VPATH 23endif 24 25ifeq ($(V),1) 26 Q = 27else 28 Q = @ 29endif 30 31BPF_DIR = $(srctree)/tools/lib/bpf/ 32 33ifneq ($(OUTPUT),) 34 BPF_PATH=$(OUTPUT) 35else 36 BPF_PATH=$(BPF_DIR) 37endif 38 39LIBBPF = $(BPF_PATH)libbpf.a 40 41$(LIBBPF): FORCE 42 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a FEATURES_DUMP=$(FEATURE_DUMP_EXPORT) 43 44$(LIBBPF)-clean: 45 $(call QUIET_CLEAN, libbpf) 46 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null 47 48prefix = /usr 49 50CC = gcc 51 52CFLAGS += -O2 53CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow 54CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi -I$(srctree)/tools/include -I$(srctree)/tools/lib/bpf -I$(srctree)/kernel/bpf/ 55LIBS = -lelf -lbfd -lopcodes $(LIBBPF) 56 57include $(wildcard *.d) 58 59all: $(OUTPUT)bpftool 60 61SRCS=$(wildcard *.c) 62OBJS=$(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o 63 64$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c 65 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< 66 67$(OUTPUT)bpftool: $(OBJS) $(LIBBPF) 68 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ $(LIBS) 69 70$(OUTPUT)%.o: %.c 71 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< 72 73clean: $(LIBBPF)-clean 74 $(call QUIET_CLEAN, bpftool) 75 $(Q)rm -rf $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d 76 77install: 78 install $(OUTPUT)bpftool $(prefix)/sbin/bpftool 79 80doc: 81 $(Q)$(MAKE) -C Documentation/ 82 83doc-install: 84 $(Q)$(MAKE) -C Documentation/ install 85 86FORCE: 87 88.PHONY: all clean FORCE 89.DEFAULT_GOAL := all 90