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 |
Jiong Wang | 39b72cc | 2018-01-16 15:51:47 -0800 | [diff] [blame] | 42 | CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi -I$(srctree)/tools/include -I$(srctree)/tools/lib/bpf -I$(srctree)/kernel/bpf/ |
Roman Gushchin | 4bfe3bd | 2017-12-27 19:16:28 +0000 | [diff] [blame] | 43 | CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"' |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 44 | LIBS = -lelf -lbfd -lopcodes $(LIBBPF) |
| 45 | |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 46 | INSTALL ?= install |
| 47 | RM ?= rm -f |
| 48 | |
Roman Gushchin | fb98266 | 2017-12-27 19:16:29 +0000 | [diff] [blame] | 49 | FEATURE_USER = .bpftool |
| 50 | FEATURE_TESTS = libbfd disassembler-four-args |
| 51 | FEATURE_DISPLAY = libbfd disassembler-four-args |
| 52 | |
| 53 | check_feat := 1 |
| 54 | NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall |
| 55 | ifdef MAKECMDGOALS |
| 56 | ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) |
| 57 | check_feat := 0 |
| 58 | endif |
| 59 | endif |
| 60 | |
| 61 | ifeq ($(check_feat),1) |
| 62 | ifeq ($(FEATURES_DUMP),) |
| 63 | include $(srctree)/tools/build/Makefile.feature |
| 64 | else |
| 65 | include $(FEATURES_DUMP) |
| 66 | endif |
| 67 | endif |
| 68 | |
| 69 | ifeq ($(feature-disassembler-four-args), 1) |
| 70 | CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE |
| 71 | endif |
| 72 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 73 | include $(wildcard *.d) |
| 74 | |
| 75 | all: $(OUTPUT)bpftool |
| 76 | |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 77 | SRCS = $(wildcard *.c) |
| 78 | OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o |
Jakub Kicinski | c9c3599 | 2017-10-09 10:30:13 -0700 | [diff] [blame] | 79 | |
| 80 | $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c |
| 81 | $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 82 | |
| 83 | $(OUTPUT)bpftool: $(OBJS) $(LIBBPF) |
| 84 | $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ $(LIBS) |
| 85 | |
| 86 | $(OUTPUT)%.o: %.c |
| 87 | $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< |
| 88 | |
| 89 | clean: $(LIBBPF)-clean |
| 90 | $(call QUIET_CLEAN, bpftool) |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 91 | $(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 92 | |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 93 | install: $(OUTPUT)bpftool |
| 94 | $(call QUIET_INSTALL, bpftool) |
| 95 | $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin |
| 96 | $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool |
| 97 | $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir) |
| 98 | $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 99 | |
Quentin Monnet | d324424 | 2017-12-07 15:00:18 -0800 | [diff] [blame] | 100 | uninstall: |
| 101 | $(call QUIET_UNINST, bpftool) |
| 102 | $(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool |
| 103 | $(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool |
| 104 | |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 105 | doc: |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 106 | $(call descend,Documentation) |
| 107 | |
| 108 | doc-clean: |
| 109 | $(call descend,Documentation,clean) |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 110 | |
| 111 | doc-install: |
Quentin Monnet | 658e85a | 2017-12-07 15:00:17 -0800 | [diff] [blame] | 112 | $(call descend,Documentation,install) |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 113 | |
Quentin Monnet | d324424 | 2017-12-07 15:00:18 -0800 | [diff] [blame] | 114 | doc-uninstall: |
| 115 | $(call descend,Documentation,uninstall) |
| 116 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 117 | FORCE: |
| 118 | |
Quentin Monnet | d324424 | 2017-12-07 15:00:18 -0800 | [diff] [blame] | 119 | .PHONY: all FORCE clean install uninstall |
| 120 | .PHONY: doc doc-clean doc-install doc-uninstall |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 121 | .DEFAULT_GOAL := all |