David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 1 | # SPDX-License-Identifier: GPL-2.0-only |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | include ../../scripts/Makefile.include |
| 3 | include ../../scripts/utilities.mak |
| 4 | |
| 5 | ifeq ($(srctree),) |
| 6 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
| 7 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 8 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 9 | endif |
| 10 | |
| 11 | ifeq ($(V),1) |
| 12 | Q = |
| 13 | else |
| 14 | Q = @ |
| 15 | endif |
| 16 | |
| 17 | BPF_DIR = $(srctree)/tools/lib/bpf/ |
| 18 | |
| 19 | ifneq ($(OUTPUT),) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 20 | LIBBPF_OUTPUT = $(OUTPUT)/libbpf/ |
| 21 | LIBBPF_PATH = $(LIBBPF_OUTPUT) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 22 | else |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 23 | LIBBPF_PATH = $(BPF_DIR) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 24 | endif |
| 25 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 26 | LIBBPF = $(LIBBPF_PATH)libbpf.a |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 27 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 28 | BPFTOOL_VERSION := $(shell make -rR --no-print-directory -sC ../../.. kernelversion) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 29 | |
| 30 | $(LIBBPF): FORCE |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 31 | $(if $(LIBBPF_OUTPUT),@mkdir -p $(LIBBPF_OUTPUT)) |
| 32 | $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) $(LIBBPF_OUTPUT)libbpf.a |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 33 | |
| 34 | $(LIBBPF)-clean: |
| 35 | $(call QUIET_CLEAN, libbpf) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 36 | $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) clean >/dev/null |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 37 | |
| 38 | prefix ?= /usr/local |
| 39 | bash_compdir ?= /usr/share/bash-completion/completions |
| 40 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 41 | CFLAGS += -O2 |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 42 | CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers |
| 43 | CFLAGS += $(filter-out -Wswitch-enum,$(EXTRA_WARNINGS)) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [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 \ |
| 48 | -I$(srctree)/tools/lib/bpf \ |
| 49 | -I$(srctree)/tools/perf |
| 50 | CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"' |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 51 | ifneq ($(EXTRA_CFLAGS),) |
| 52 | CFLAGS += $(EXTRA_CFLAGS) |
| 53 | endif |
| 54 | ifneq ($(EXTRA_LDFLAGS),) |
| 55 | LDFLAGS += $(EXTRA_LDFLAGS) |
| 56 | endif |
| 57 | |
| 58 | LIBS = $(LIBBPF) -lelf -lz |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 59 | |
| 60 | INSTALL ?= install |
| 61 | RM ?= rm -f |
| 62 | |
| 63 | FEATURE_USER = .bpftool |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 64 | FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib |
| 65 | FEATURE_DISPLAY = libbfd disassembler-four-args zlib |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 66 | |
| 67 | check_feat := 1 |
| 68 | NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall |
| 69 | ifdef MAKECMDGOALS |
| 70 | ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) |
| 71 | check_feat := 0 |
| 72 | endif |
| 73 | endif |
| 74 | |
| 75 | ifeq ($(check_feat),1) |
| 76 | ifeq ($(FEATURES_DUMP),) |
| 77 | include $(srctree)/tools/build/Makefile.feature |
| 78 | else |
| 79 | include $(FEATURES_DUMP) |
| 80 | endif |
| 81 | endif |
| 82 | |
| 83 | ifeq ($(feature-disassembler-four-args), 1) |
| 84 | CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE |
| 85 | endif |
| 86 | |
| 87 | ifeq ($(feature-reallocarray), 0) |
| 88 | CFLAGS += -DCOMPAT_NEED_REALLOCARRAY |
| 89 | endif |
| 90 | |
| 91 | include $(wildcard $(OUTPUT)*.d) |
| 92 | |
| 93 | all: $(OUTPUT)bpftool |
| 94 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 95 | BFD_SRCS = jit_disasm.c |
| 96 | |
| 97 | SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c)) |
| 98 | |
| 99 | ifeq ($(feature-libbfd),1) |
| 100 | LIBS += -lbfd -ldl -lopcodes |
| 101 | else ifeq ($(feature-libbfd-liberty),1) |
| 102 | LIBS += -lbfd -ldl -lopcodes -liberty |
| 103 | else ifeq ($(feature-libbfd-liberty-z),1) |
| 104 | LIBS += -lbfd -ldl -lopcodes -liberty -lz |
| 105 | endif |
| 106 | |
| 107 | ifneq ($(filter -lbfd,$(LIBS)),) |
| 108 | CFLAGS += -DHAVE_LIBBFD_SUPPORT |
| 109 | SRCS += $(BFD_SRCS) |
| 110 | endif |
| 111 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 112 | OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o |
| 113 | |
| 114 | $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c |
| 115 | $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< |
| 116 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 117 | $(OUTPUT)feature.o: | zdep |
| 118 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 119 | $(OUTPUT)bpftool: $(OBJS) $(LIBBPF) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 120 | $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 121 | |
| 122 | $(OUTPUT)%.o: %.c |
| 123 | $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< |
| 124 | |
| 125 | clean: $(LIBBPF)-clean |
| 126 | $(call QUIET_CLEAN, bpftool) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 127 | $(Q)$(RM) -- $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d |
| 128 | $(Q)$(RM) -r -- $(OUTPUT)libbpf/ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 129 | $(call QUIET_CLEAN, core-gen) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 130 | $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpftool |
| 131 | $(Q)$(RM) -r -- $(OUTPUT)feature/ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 132 | |
| 133 | install: $(OUTPUT)bpftool |
| 134 | $(call QUIET_INSTALL, bpftool) |
| 135 | $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin |
| 136 | $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool |
| 137 | $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir) |
| 138 | $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir) |
| 139 | |
| 140 | uninstall: |
| 141 | $(call QUIET_UNINST, bpftool) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 142 | $(Q)$(RM) -- $(DESTDIR)$(prefix)/sbin/bpftool |
| 143 | $(Q)$(RM) -- $(DESTDIR)$(bash_compdir)/bpftool |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 144 | |
| 145 | doc: |
| 146 | $(call descend,Documentation) |
| 147 | |
| 148 | doc-clean: |
| 149 | $(call descend,Documentation,clean) |
| 150 | |
| 151 | doc-install: |
| 152 | $(call descend,Documentation,install) |
| 153 | |
| 154 | doc-uninstall: |
| 155 | $(call descend,Documentation,uninstall) |
| 156 | |
| 157 | FORCE: |
| 158 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 159 | zdep: |
| 160 | @if [ "$(feature-zlib)" != "1" ]; then echo "No zlib found"; exit 1 ; fi |
| 161 | |
| 162 | .PHONY: all FORCE clean install uninstall zdep |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 163 | .PHONY: doc doc-clean doc-install doc-uninstall |
| 164 | .DEFAULT_GOAL := all |