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 | |
Jakub Kicinski | c256429 | 2018-06-28 14:41:35 -0700 | [diff] [blame] | 26 | BPFTOOL_VERSION := $(shell make --no-print-directory -sC ../../.. kernelversion) |
Roman Gushchin | 4bfe3bd | 2017-12-27 19:16:28 +0000 | [diff] [blame] | 27 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 28 | $(LIBBPF): FORCE |
Jakub Kicinski | dc989d2 | 2018-07-16 10:57:16 -0700 | [diff] [blame] | 29 | $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 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)"' |
Jiri Olsa | 0ef6bf3 | 2018-10-08 10:22:58 +0200 | [diff] [blame] | 49 | ifneq ($(EXTRA_CFLAGS),) |
| 50 | CFLAGS += $(EXTRA_CFLAGS) |
| 51 | endif |
Jiri Olsa | c850616 | 2018-10-08 10:22:59 +0200 | [diff] [blame] | 52 | ifneq ($(EXTRA_LDFLAGS),) |
| 53 | LDFLAGS += $(EXTRA_LDFLAGS) |
| 54 | endif |
Jiri Olsa | 0ef6bf3 | 2018-10-08 10:22:58 +0200 | [diff] [blame] | 55 | |
Stanislav Fomichev | 29a9c10 | 2018-11-12 13:44:10 -0800 | [diff] [blame^] | 56 | LIBS = -lelf $(LIBBPF) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 57 | |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 58 | INSTALL ?= install |
| 59 | RM ?= rm -f |
| 60 | |
Roman Gushchin | fb98266 | 2017-12-27 19:16:29 +0000 | [diff] [blame] | 61 | FEATURE_USER = .bpftool |
Jakub Kicinski | 531b014 | 2018-07-10 14:43:05 -0700 | [diff] [blame] | 62 | FEATURE_TESTS = libbfd disassembler-four-args reallocarray |
Roman Gushchin | fb98266 | 2017-12-27 19:16:29 +0000 | [diff] [blame] | 63 | FEATURE_DISPLAY = libbfd disassembler-four-args |
| 64 | |
| 65 | check_feat := 1 |
| 66 | NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall |
| 67 | ifdef MAKECMDGOALS |
| 68 | ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) |
| 69 | check_feat := 0 |
| 70 | endif |
| 71 | endif |
| 72 | |
| 73 | ifeq ($(check_feat),1) |
| 74 | ifeq ($(FEATURES_DUMP),) |
| 75 | include $(srctree)/tools/build/Makefile.feature |
| 76 | else |
| 77 | include $(FEATURES_DUMP) |
| 78 | endif |
| 79 | endif |
| 80 | |
| 81 | ifeq ($(feature-disassembler-four-args), 1) |
| 82 | CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE |
| 83 | endif |
| 84 | |
Jakub Kicinski | 531b014 | 2018-07-10 14:43:05 -0700 | [diff] [blame] | 85 | ifeq ($(feature-reallocarray), 0) |
| 86 | CFLAGS += -DCOMPAT_NEED_REALLOCARRAY |
| 87 | endif |
| 88 | |
Jakub Kicinski | 90126e3 | 2018-03-15 23:26:14 -0700 | [diff] [blame] | 89 | include $(wildcard $(OUTPUT)*.d) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 90 | |
| 91 | all: $(OUTPUT)bpftool |
| 92 | |
Stanislav Fomichev | 29a9c10 | 2018-11-12 13:44:10 -0800 | [diff] [blame^] | 93 | BFD_SRCS = jit_disasm.c |
| 94 | |
| 95 | SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c)) |
| 96 | |
| 97 | ifeq ($(feature-libbfd),1) |
| 98 | CFLAGS += -DHAVE_LIBBFD_SUPPORT |
| 99 | SRCS += $(BFD_SRCS) |
| 100 | LIBS += -lbfd -lopcodes |
| 101 | endif |
| 102 | |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 103 | OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o |
Jakub Kicinski | c9c3599 | 2017-10-09 10:30:13 -0700 | [diff] [blame] | 104 | |
| 105 | $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c |
| 106 | $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 107 | |
| 108 | $(OUTPUT)bpftool: $(OBJS) $(LIBBPF) |
Jiri Olsa | c850616 | 2018-10-08 10:22:59 +0200 | [diff] [blame] | 109 | $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 110 | |
| 111 | $(OUTPUT)%.o: %.c |
| 112 | $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< |
| 113 | |
| 114 | clean: $(LIBBPF)-clean |
| 115 | $(call QUIET_CLEAN, bpftool) |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 116 | $(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d |
Jakub Kicinski | cc5b340 | 2018-03-15 23:26:17 -0700 | [diff] [blame] | 117 | $(call QUIET_CLEAN, core-gen) |
| 118 | $(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 119 | |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 120 | install: $(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) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 126 | |
Quentin Monnet | d324424 | 2017-12-07 15:00:18 -0800 | [diff] [blame] | 127 | uninstall: |
| 128 | $(call QUIET_UNINST, bpftool) |
| 129 | $(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool |
| 130 | $(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool |
| 131 | |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 132 | doc: |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 133 | $(call descend,Documentation) |
| 134 | |
| 135 | doc-clean: |
| 136 | $(call descend,Documentation,clean) |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 137 | |
| 138 | doc-install: |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 139 | $(call descend,Documentation,install) |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 140 | |
Quentin Monnet | d324424 | 2017-12-07 15:00:18 -0800 | [diff] [blame] | 141 | doc-uninstall: |
| 142 | $(call descend,Documentation,uninstall) |
| 143 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 144 | FORCE: |
| 145 | |
Quentin Monnet | d324424 | 2017-12-07 15:00:18 -0800 | [diff] [blame] | 146 | .PHONY: all FORCE clean install uninstall |
| 147 | .PHONY: doc doc-clean doc-install doc-uninstall |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 148 | .DEFAULT_GOAL := all |