blob: 1bea6b979082325e73cabeaaeb2aafd19d8d9edd [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
Jakub Kicinskic2564292018-06-28 14:41:35 -070026BPFTOOL_VERSION := $(shell make --no-print-directory -sC ../../.. kernelversion)
Roman Gushchin4bfe3bd2017-12-27 19:16:28 +000027
Jakub Kicinski71bb4282017-10-04 20:10:04 -070028$(LIBBPF): FORCE
Jakub Kicinskidc989d22018-07-16 10:57:16 -070029 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a
Jakub Kicinski71bb4282017-10-04 20:10:04 -070030
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
Jakub Kicinskif412eed2018-05-03 18:37:16 -070042CFLAGS += -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 Gushchin4bfe3bd2017-12-27 19:16:28 +000048CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
Jiri Olsa0ef6bf32018-10-08 10:22:58 +020049ifneq ($(EXTRA_CFLAGS),)
50CFLAGS += $(EXTRA_CFLAGS)
51endif
Jiri Olsac8506162018-10-08 10:22:59 +020052ifneq ($(EXTRA_LDFLAGS),)
53LDFLAGS += $(EXTRA_LDFLAGS)
54endif
Jiri Olsa0ef6bf32018-10-08 10:22:58 +020055
Stanislav Fomichev29a9c102018-11-12 13:44:10 -080056LIBS = -lelf $(LIBBPF)
Jakub Kicinski71bb4282017-10-04 20:10:04 -070057
Quentin Monnet658e85a2017-12-07 15:00:17 -080058INSTALL ?= install
59RM ?= rm -f
60
Roman Gushchinfb982662017-12-27 19:16:29 +000061FEATURE_USER = .bpftool
Jakub Kicinski531b0142018-07-10 14:43:05 -070062FEATURE_TESTS = libbfd disassembler-four-args reallocarray
Roman Gushchinfb982662017-12-27 19:16:29 +000063FEATURE_DISPLAY = libbfd disassembler-four-args
64
65check_feat := 1
66NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
67ifdef MAKECMDGOALS
68ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
69 check_feat := 0
70endif
71endif
72
73ifeq ($(check_feat),1)
74ifeq ($(FEATURES_DUMP),)
75include $(srctree)/tools/build/Makefile.feature
76else
77include $(FEATURES_DUMP)
78endif
79endif
80
81ifeq ($(feature-disassembler-four-args), 1)
82CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
83endif
84
Jakub Kicinski531b0142018-07-10 14:43:05 -070085ifeq ($(feature-reallocarray), 0)
86CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
87endif
88
Jakub Kicinski90126e32018-03-15 23:26:14 -070089include $(wildcard $(OUTPUT)*.d)
Jakub Kicinski71bb4282017-10-04 20:10:04 -070090
91all: $(OUTPUT)bpftool
92
Stanislav Fomichev29a9c102018-11-12 13:44:10 -080093BFD_SRCS = jit_disasm.c
94
95SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
96
97ifeq ($(feature-libbfd),1)
98CFLAGS += -DHAVE_LIBBFD_SUPPORT
99SRCS += $(BFD_SRCS)
100LIBS += -lbfd -lopcodes
101endif
102
Quentin Monnet658e85a2017-12-07 15:00:17 -0800103OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
Jakub Kicinskic9c35992017-10-09 10:30:13 -0700104
105$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
106 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700107
108$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
Jiri Olsac8506162018-10-08 10:22:59 +0200109 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700110
111$(OUTPUT)%.o: %.c
112 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
113
114clean: $(LIBBPF)-clean
115 $(call QUIET_CLEAN, bpftool)
Quentin Monnet658e85a2017-12-07 15:00:17 -0800116 $(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
Jakub Kicinskicc5b3402018-03-15 23:26:17 -0700117 $(call QUIET_CLEAN, core-gen)
118 $(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700119
Quentin Monnet658e85a2017-12-07 15:00:17 -0800120install: $(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 Kicinski71bb4282017-10-04 20:10:04 -0700126
Quentin Monnetd3244242017-12-07 15:00:18 -0800127uninstall:
128 $(call QUIET_UNINST, bpftool)
129 $(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
130 $(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool
131
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700132doc:
Quentin Monnet658e85a2017-12-07 15:00:17 -0800133 $(call descend,Documentation)
134
135doc-clean:
136 $(call descend,Documentation,clean)
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700137
138doc-install:
Quentin Monnet658e85a2017-12-07 15:00:17 -0800139 $(call descend,Documentation,install)
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700140
Quentin Monnetd3244242017-12-07 15:00:18 -0800141doc-uninstall:
142 $(call descend,Documentation,uninstall)
143
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700144FORCE:
145
Quentin Monnetd3244242017-12-07 15:00:18 -0800146.PHONY: all FORCE clean install uninstall
147.PHONY: doc doc-clean doc-install doc-uninstall
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700148.DEFAULT_GOAL := all