Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1 | include ../../scripts/Makefile.include |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 2 | include ../../scripts/utilities.mak |
| 3 | |
| 4 | ifeq ($(srctree),) |
| 5 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
| 6 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 7 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 8 | endif |
| 9 | |
| 10 | ifeq ($(V),1) |
| 11 | Q = |
| 12 | else |
| 13 | Q = @ |
| 14 | endif |
| 15 | |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 16 | BPF_DIR = $(srctree)/tools/lib/bpf/ |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 17 | |
| 18 | ifneq ($(OUTPUT),) |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 19 | BPF_PATH = $(OUTPUT) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 20 | else |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 21 | BPF_PATH = $(BPF_DIR) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 22 | endif |
| 23 | |
| 24 | LIBBPF = $(BPF_PATH)libbpf.a |
| 25 | |
Roman Gushchin | 4bfe3bd | 2017-12-27 19:16:28 +0000 | [diff] [blame] | 26 | BPFTOOL_VERSION=$(shell make --no-print-directory -sC ../../.. kernelversion) |
| 27 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 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 | |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 35 | prefix ?= /usr/local |
Quentin Monnet | 507e590 | 2017-11-28 17:44:32 -0800 | [diff] [blame] | 36 | bash_compdir ?= /usr/share/bash-completion/completions |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 37 | |
| 38 | CC = gcc |
| 39 | |
| 40 | CFLAGS += -O2 |
Jiri Benc | 72ab55e | 2018-03-08 23:00:35 +0100 | [diff] [blame] | 41 | CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers |
Jakub Kicinski | f412eed | 2018-05-03 18:37:16 -0700 | [diff] [blame^] | 42 | CFLAGS += -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 |
Roman Gushchin | 4bfe3bd | 2017-12-27 19:16:28 +0000 | [diff] [blame] | 48 | CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"' |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 49 | LIBS = -lelf -lbfd -lopcodes $(LIBBPF) |
| 50 | |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 51 | INSTALL ?= install |
| 52 | RM ?= rm -f |
| 53 | |
Roman Gushchin | fb98266 | 2017-12-27 19:16:29 +0000 | [diff] [blame] | 54 | FEATURE_USER = .bpftool |
| 55 | FEATURE_TESTS = libbfd disassembler-four-args |
| 56 | FEATURE_DISPLAY = libbfd disassembler-four-args |
| 57 | |
| 58 | check_feat := 1 |
| 59 | NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall |
| 60 | ifdef MAKECMDGOALS |
| 61 | ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) |
| 62 | check_feat := 0 |
| 63 | endif |
| 64 | endif |
| 65 | |
| 66 | ifeq ($(check_feat),1) |
| 67 | ifeq ($(FEATURES_DUMP),) |
| 68 | include $(srctree)/tools/build/Makefile.feature |
| 69 | else |
| 70 | include $(FEATURES_DUMP) |
| 71 | endif |
| 72 | endif |
| 73 | |
| 74 | ifeq ($(feature-disassembler-four-args), 1) |
| 75 | CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE |
| 76 | endif |
| 77 | |
Jakub Kicinski | 90126e3 | 2018-03-15 23:26:14 -0700 | [diff] [blame] | 78 | include $(wildcard $(OUTPUT)*.d) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 79 | |
| 80 | all: $(OUTPUT)bpftool |
| 81 | |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 82 | SRCS = $(wildcard *.c) |
| 83 | OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o |
Jakub Kicinski | c9c3599 | 2017-10-09 10:30:13 -0700 | [diff] [blame] | 84 | |
| 85 | $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c |
| 86 | $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 87 | |
| 88 | $(OUTPUT)bpftool: $(OBJS) $(LIBBPF) |
| 89 | $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ $(LIBS) |
| 90 | |
| 91 | $(OUTPUT)%.o: %.c |
| 92 | $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< |
| 93 | |
| 94 | clean: $(LIBBPF)-clean |
| 95 | $(call QUIET_CLEAN, bpftool) |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 96 | $(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d |
Jakub Kicinski | cc5b340 | 2018-03-15 23:26:17 -0700 | [diff] [blame] | 97 | $(call QUIET_CLEAN, core-gen) |
| 98 | $(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 99 | |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 100 | install: $(OUTPUT)bpftool |
| 101 | $(call QUIET_INSTALL, bpftool) |
| 102 | $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin |
| 103 | $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool |
| 104 | $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir) |
| 105 | $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 106 | |
Quentin Monnet | d324424 | 2017-12-07 15:00:18 -0800 | [diff] [blame] | 107 | uninstall: |
| 108 | $(call QUIET_UNINST, bpftool) |
| 109 | $(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool |
| 110 | $(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool |
| 111 | |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 112 | doc: |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 113 | $(call descend,Documentation) |
| 114 | |
| 115 | doc-clean: |
| 116 | $(call descend,Documentation,clean) |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 117 | |
| 118 | doc-install: |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 119 | $(call descend,Documentation,install) |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 120 | |
Quentin Monnet | d324424 | 2017-12-07 15:00:18 -0800 | [diff] [blame] | 121 | doc-uninstall: |
| 122 | $(call descend,Documentation,uninstall) |
| 123 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 124 | FORCE: |
| 125 | |
Quentin Monnet | d324424 | 2017-12-07 15:00:18 -0800 | [diff] [blame] | 126 | .PHONY: all FORCE clean install uninstall |
| 127 | .PHONY: doc doc-clean doc-install doc-uninstall |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 128 | .DEFAULT_GOAL := all |