Thomas Gleixner | ec8f24b | 2019-05-19 13:07:45 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0-only |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 2 | include ../../scripts/Makefile.include |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 3 | include ../../scripts/utilities.mak |
| 4 | |
| 5 | ifeq ($(srctree),) |
| 6 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
| 7 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 8 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 9 | endif |
| 10 | |
| 11 | ifeq ($(V),1) |
| 12 | Q = |
| 13 | else |
| 14 | Q = @ |
| 15 | endif |
| 16 | |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 17 | BPF_DIR = $(srctree)/tools/lib/bpf/ |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 18 | |
| 19 | ifneq ($(OUTPUT),) |
Quentin Monnet | 45c5589d | 2019-08-30 12:00:38 +0100 | [diff] [blame] | 20 | LIBBPF_OUTPUT = $(OUTPUT)/libbpf/ |
| 21 | LIBBPF_PATH = $(LIBBPF_OUTPUT) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 22 | else |
Quentin Monnet | 45c5589d | 2019-08-30 12:00:38 +0100 | [diff] [blame] | 23 | LIBBPF_PATH = $(BPF_DIR) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 24 | endif |
| 25 | |
Quentin Monnet | 45c5589d | 2019-08-30 12:00:38 +0100 | [diff] [blame] | 26 | LIBBPF = $(LIBBPF_PATH)libbpf.a |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 27 | |
Quentin Monnet | e0a43aa | 2019-08-30 12:00:37 +0100 | [diff] [blame] | 28 | BPFTOOL_VERSION := $(shell make -rR --no-print-directory -sC ../../.. kernelversion) |
Roman Gushchin | 4bfe3bd | 2017-12-27 19:16:28 +0000 | [diff] [blame] | 29 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 30 | $(LIBBPF): FORCE |
Quentin Monnet | 45c5589d | 2019-08-30 12:00:38 +0100 | [diff] [blame] | 31 | $(if $(LIBBPF_OUTPUT),@mkdir -p $(LIBBPF_OUTPUT)) |
| 32 | $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) $(LIBBPF_OUTPUT)libbpf.a |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 33 | |
| 34 | $(LIBBPF)-clean: |
| 35 | $(call QUIET_CLEAN, libbpf) |
Quentin Monnet | 45c5589d | 2019-08-30 12:00:38 +0100 | [diff] [blame] | 36 | $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) clean >/dev/null |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 37 | |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 38 | prefix ?= /usr/local |
Quentin Monnet | 507e590 | 2017-11-28 17:44:32 -0800 | [diff] [blame] | 39 | bash_compdir ?= /usr/share/bash-completion/completions |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 40 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 41 | CFLAGS += -O2 |
Quentin Monnet | a9436dc | 2019-08-14 12:37:24 +0100 | [diff] [blame] | 42 | CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers |
| 43 | CFLAGS += $(filter-out -Wswitch-enum,$(EXTRA_WARNINGS)) |
Jakub Kicinski | f412eed | 2018-05-03 18:37:16 -0700 | [diff] [blame] | 44 | CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \ |
| 45 | -I$(srctree)/kernel/bpf/ \ |
| 46 | -I$(srctree)/tools/include \ |
| 47 | -I$(srctree)/tools/include/uapi \ |
Toke Høiland-Jørgensen | 229c3b4 | 2020-01-20 14:06:46 +0100 | [diff] [blame] | 48 | -I$(srctree)/tools/lib \ |
Jakub Kicinski | f412eed | 2018-05-03 18:37:16 -0700 | [diff] [blame] | 49 | -I$(srctree)/tools/perf |
Roman Gushchin | 4bfe3bd | 2017-12-27 19:16:28 +0000 | [diff] [blame] | 50 | CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"' |
Jiri Olsa | 0ef6bf3 | 2018-10-08 10:22:58 +0200 | [diff] [blame] | 51 | ifneq ($(EXTRA_CFLAGS),) |
| 52 | CFLAGS += $(EXTRA_CFLAGS) |
| 53 | endif |
Jiri Olsa | c850616 | 2018-10-08 10:22:59 +0200 | [diff] [blame] | 54 | ifneq ($(EXTRA_LDFLAGS),) |
| 55 | LDFLAGS += $(EXTRA_LDFLAGS) |
| 56 | endif |
Jiri Olsa | 0ef6bf3 | 2018-10-08 10:22:58 +0200 | [diff] [blame] | 57 | |
Quentin Monnet | 5b84ad2 | 2019-08-30 12:00:40 +0100 | [diff] [blame] | 58 | LIBS = $(LIBBPF) -lelf -lz |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 59 | |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 60 | INSTALL ?= install |
| 61 | RM ?= rm -f |
Song Liu | 47c09d6 | 2020-03-09 10:32:15 -0700 | [diff] [blame] | 62 | CLANG ?= clang |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 63 | |
Roman Gushchin | fb98266 | 2017-12-27 19:16:29 +0000 | [diff] [blame] | 64 | FEATURE_USER = .bpftool |
Peter Wu | d66fa3c | 2019-08-13 01:38:33 +0100 | [diff] [blame] | 65 | FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib |
| 66 | FEATURE_DISPLAY = libbfd disassembler-four-args zlib |
Roman Gushchin | fb98266 | 2017-12-27 19:16:29 +0000 | [diff] [blame] | 67 | |
| 68 | check_feat := 1 |
| 69 | NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall |
| 70 | ifdef MAKECMDGOALS |
| 71 | ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) |
| 72 | check_feat := 0 |
| 73 | endif |
| 74 | endif |
| 75 | |
| 76 | ifeq ($(check_feat),1) |
| 77 | ifeq ($(FEATURES_DUMP),) |
| 78 | include $(srctree)/tools/build/Makefile.feature |
| 79 | else |
| 80 | include $(FEATURES_DUMP) |
| 81 | endif |
| 82 | endif |
| 83 | |
| 84 | ifeq ($(feature-disassembler-four-args), 1) |
| 85 | CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE |
| 86 | endif |
| 87 | |
Jakub Kicinski | 531b014 | 2018-07-10 14:43:05 -0700 | [diff] [blame] | 88 | ifeq ($(feature-reallocarray), 0) |
| 89 | CFLAGS += -DCOMPAT_NEED_REALLOCARRAY |
| 90 | endif |
| 91 | |
Jakub Kicinski | 90126e3 | 2018-03-15 23:26:14 -0700 | [diff] [blame] | 92 | include $(wildcard $(OUTPUT)*.d) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 93 | |
| 94 | all: $(OUTPUT)bpftool |
| 95 | |
Stanislav Fomichev | 29a9c10 | 2018-11-12 13:44:10 -0800 | [diff] [blame] | 96 | BFD_SRCS = jit_disasm.c |
| 97 | |
| 98 | SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c)) |
| 99 | |
| 100 | ifeq ($(feature-libbfd),1) |
Stanislav Fomichev | 6e8ccb4 | 2019-01-15 14:03:27 -0800 | [diff] [blame] | 101 | LIBS += -lbfd -ldl -lopcodes |
| 102 | else ifeq ($(feature-libbfd-liberty),1) |
| 103 | LIBS += -lbfd -ldl -lopcodes -liberty |
| 104 | else ifeq ($(feature-libbfd-liberty-z),1) |
| 105 | LIBS += -lbfd -ldl -lopcodes -liberty -lz |
| 106 | endif |
| 107 | |
| 108 | ifneq ($(filter -lbfd,$(LIBS)),) |
Stanislav Fomichev | 29a9c10 | 2018-11-12 13:44:10 -0800 | [diff] [blame] | 109 | CFLAGS += -DHAVE_LIBBFD_SUPPORT |
| 110 | SRCS += $(BFD_SRCS) |
Stanislav Fomichev | 29a9c10 | 2018-11-12 13:44:10 -0800 | [diff] [blame] | 111 | endif |
| 112 | |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 113 | OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o |
Song Liu | 47c09d6 | 2020-03-09 10:32:15 -0700 | [diff] [blame] | 114 | _OBJS = $(filter-out $(OUTPUT)prog.o,$(OBJS)) $(OUTPUT)_prog.o |
| 115 | |
| 116 | $(OUTPUT)_prog.o: prog.c |
| 117 | $(QUIET_CC)$(COMPILE.c) -MMD -DBPFTOOL_WITHOUT_SKELETONS -o $@ $< |
| 118 | |
| 119 | $(OUTPUT)_bpftool: $(_OBJS) $(LIBBPF) |
| 120 | $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(_OBJS) $(LIBS) |
| 121 | |
| 122 | skeleton/profiler.bpf.o: skeleton/profiler.bpf.c |
| 123 | $(QUIET_CLANG)$(CLANG) -I$(srctree)/tools/lib -g -O2 -target bpf -c $< -o $@ |
| 124 | |
| 125 | profiler.skel.h: $(OUTPUT)_bpftool skeleton/profiler.bpf.o |
| 126 | $(QUIET_GEN)$(OUTPUT)./_bpftool gen skeleton skeleton/profiler.bpf.o > $@ |
| 127 | |
| 128 | $(OUTPUT)prog.o: prog.c profiler.skel.h |
| 129 | $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< |
Jakub Kicinski | c9c3599 | 2017-10-09 10:30:13 -0700 | [diff] [blame] | 130 | |
| 131 | $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c |
| 132 | $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 133 | |
Peter Wu | d66fa3c | 2019-08-13 01:38:33 +0100 | [diff] [blame] | 134 | $(OUTPUT)feature.o: | zdep |
| 135 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 136 | $(OUTPUT)bpftool: $(OBJS) $(LIBBPF) |
Quentin Monnet | 5b84ad2 | 2019-08-30 12:00:40 +0100 | [diff] [blame] | 137 | $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 138 | |
| 139 | $(OUTPUT)%.o: %.c |
| 140 | $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< |
| 141 | |
| 142 | clean: $(LIBBPF)-clean |
| 143 | $(call QUIET_CLEAN, bpftool) |
Quentin Monnet | fbdb620 | 2019-08-30 12:00:39 +0100 | [diff] [blame] | 144 | $(Q)$(RM) -- $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d |
Song Liu | 47c09d6 | 2020-03-09 10:32:15 -0700 | [diff] [blame] | 145 | $(Q)$(RM) -- $(OUTPUT)_bpftool profiler.skel.h skeleton/profiler.bpf.o |
Quentin Monnet | fbdb620 | 2019-08-30 12:00:39 +0100 | [diff] [blame] | 146 | $(Q)$(RM) -r -- $(OUTPUT)libbpf/ |
Jakub Kicinski | cc5b340 | 2018-03-15 23:26:17 -0700 | [diff] [blame] | 147 | $(call QUIET_CLEAN, core-gen) |
Quentin Monnet | fbdb620 | 2019-08-30 12:00:39 +0100 | [diff] [blame] | 148 | $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpftool |
| 149 | $(Q)$(RM) -r -- $(OUTPUT)feature/ |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 150 | |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 151 | install: $(OUTPUT)bpftool |
| 152 | $(call QUIET_INSTALL, bpftool) |
| 153 | $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin |
| 154 | $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool |
| 155 | $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir) |
| 156 | $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 157 | |
Quentin Monnet | d324424 | 2017-12-07 15:00:18 -0800 | [diff] [blame] | 158 | uninstall: |
| 159 | $(call QUIET_UNINST, bpftool) |
Quentin Monnet | fbdb620 | 2019-08-30 12:00:39 +0100 | [diff] [blame] | 160 | $(Q)$(RM) -- $(DESTDIR)$(prefix)/sbin/bpftool |
| 161 | $(Q)$(RM) -- $(DESTDIR)$(bash_compdir)/bpftool |
Quentin Monnet | d324424 | 2017-12-07 15:00:18 -0800 | [diff] [blame] | 162 | |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 163 | doc: |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 164 | $(call descend,Documentation) |
| 165 | |
| 166 | doc-clean: |
| 167 | $(call descend,Documentation,clean) |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 168 | |
| 169 | doc-install: |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 170 | $(call descend,Documentation,install) |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 171 | |
Quentin Monnet | d324424 | 2017-12-07 15:00:18 -0800 | [diff] [blame] | 172 | doc-uninstall: |
| 173 | $(call descend,Documentation,uninstall) |
| 174 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 175 | FORCE: |
| 176 | |
Peter Wu | d66fa3c | 2019-08-13 01:38:33 +0100 | [diff] [blame] | 177 | zdep: |
| 178 | @if [ "$(feature-zlib)" != "1" ]; then echo "No zlib found"; exit 1 ; fi |
| 179 | |
| 180 | .PHONY: all FORCE clean install uninstall zdep |
Quentin Monnet | d324424 | 2017-12-07 15:00:18 -0800 | [diff] [blame] | 181 | .PHONY: doc doc-clean doc-install doc-uninstall |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 182 | .DEFAULT_GOAL := all |