blob: 4c2867481f5cf7244c06a2cf9af970403a9f22fd [file] [log] [blame]
Jakub Kicinski71bb4282017-10-04 20:10:04 -07001include ../../scripts/Makefile.include
Jakub Kicinski71bb4282017-10-04 20:10:04 -07002include ../../scripts/utilities.mak
3
4ifeq ($(srctree),)
5srctree := $(patsubst %/,%,$(dir $(CURDIR)))
6srctree := $(patsubst %/,%,$(dir $(srctree)))
7srctree := $(patsubst %/,%,$(dir $(srctree)))
Jakub Kicinski71bb4282017-10-04 20:10:04 -07008endif
9
10ifeq ($(V),1)
11 Q =
12else
13 Q = @
14endif
15
Quentin Monnet658e85a2017-12-07 15:00:17 -080016BPF_DIR = $(srctree)/tools/lib/bpf/
Jakub Kicinski71bb4282017-10-04 20:10:04 -070017
18ifneq ($(OUTPUT),)
Quentin Monnet658e85a2017-12-07 15:00:17 -080019 BPF_PATH = $(OUTPUT)
Jakub Kicinski71bb4282017-10-04 20:10:04 -070020else
Quentin Monnet658e85a2017-12-07 15:00:17 -080021 BPF_PATH = $(BPF_DIR)
Jakub Kicinski71bb4282017-10-04 20:10:04 -070022endif
23
24LIBBPF = $(BPF_PATH)libbpf.a
25
Roman Gushchin4bfe3bd2017-12-27 19:16:28 +000026BPFTOOL_VERSION=$(shell make --no-print-directory -sC ../../.. kernelversion)
27
Jakub Kicinski71bb4282017-10-04 20:10:04 -070028$(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 Monnet658e85a2017-12-07 15:00:17 -080035prefix ?= /usr/local
Quentin Monnet507e5902017-11-28 17:44:32 -080036bash_compdir ?= /usr/share/bash-completion/completions
Jakub Kicinski71bb4282017-10-04 20:10:04 -070037
38CC = gcc
39
40CFLAGS += -O2
Jiri Benc72ab55e2018-03-08 23:00:35 +010041CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers
Jiong Wang39b72cc2018-01-16 15:51:47 -080042CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi -I$(srctree)/tools/include -I$(srctree)/tools/lib/bpf -I$(srctree)/kernel/bpf/
Roman Gushchin4bfe3bd2017-12-27 19:16:28 +000043CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
Jakub Kicinski71bb4282017-10-04 20:10:04 -070044LIBS = -lelf -lbfd -lopcodes $(LIBBPF)
45
Quentin Monnet658e85a2017-12-07 15:00:17 -080046INSTALL ?= install
47RM ?= rm -f
48
Roman Gushchinfb982662017-12-27 19:16:29 +000049FEATURE_USER = .bpftool
50FEATURE_TESTS = libbfd disassembler-four-args
51FEATURE_DISPLAY = libbfd disassembler-four-args
52
53check_feat := 1
54NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
55ifdef MAKECMDGOALS
56ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
57 check_feat := 0
58endif
59endif
60
61ifeq ($(check_feat),1)
62ifeq ($(FEATURES_DUMP),)
63include $(srctree)/tools/build/Makefile.feature
64else
65include $(FEATURES_DUMP)
66endif
67endif
68
69ifeq ($(feature-disassembler-four-args), 1)
70CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
71endif
72
Jakub Kicinski71bb4282017-10-04 20:10:04 -070073include $(wildcard *.d)
74
75all: $(OUTPUT)bpftool
76
Quentin Monnet658e85a2017-12-07 15:00:17 -080077SRCS = $(wildcard *.c)
78OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
Jakub Kicinskic9c35992017-10-09 10:30:13 -070079
80$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
81 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
Jakub Kicinski71bb4282017-10-04 20:10:04 -070082
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
89clean: $(LIBBPF)-clean
90 $(call QUIET_CLEAN, bpftool)
Quentin Monnet658e85a2017-12-07 15:00:17 -080091 $(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
Jakub Kicinski71bb4282017-10-04 20:10:04 -070092
Quentin Monnet658e85a2017-12-07 15:00:17 -080093install: $(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 Kicinski71bb4282017-10-04 20:10:04 -070099
Quentin Monnetd3244242017-12-07 15:00:18 -0800100uninstall:
101 $(call QUIET_UNINST, bpftool)
102 $(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
103 $(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool
104
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700105doc:
Quentin Monnet658e85a2017-12-07 15:00:17 -0800106 $(call descend,Documentation)
107
108doc-clean:
109 $(call descend,Documentation,clean)
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700110
111doc-install:
Quentin Monnet658e85a2017-12-07 15:00:17 -0800112 $(call descend,Documentation,install)
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700113
Quentin Monnetd3244242017-12-07 15:00:18 -0800114doc-uninstall:
115 $(call descend,Documentation,uninstall)
116
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700117FORCE:
118
Quentin Monnetd3244242017-12-07 15:00:18 -0800119.PHONY: all FORCE clean install uninstall
120.PHONY: doc doc-clean doc-install doc-uninstall
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700121.DEFAULT_GOAL := all