blob: cd0fc05464e7fcc0fea7778efbc7f1e8394ad296 [file] [log] [blame]
Thomas Gleixnerec8f24b2019-05-19 13:07:45 +01001# SPDX-License-Identifier: GPL-2.0-only
Jakub Kicinski71bb4282017-10-04 20:10:04 -07002include ../../scripts/Makefile.include
Jakub Kicinski71bb4282017-10-04 20:10:04 -07003include ../../scripts/utilities.mak
4
5ifeq ($(srctree),)
6srctree := $(patsubst %/,%,$(dir $(CURDIR)))
7srctree := $(patsubst %/,%,$(dir $(srctree)))
8srctree := $(patsubst %/,%,$(dir $(srctree)))
Jakub Kicinski71bb4282017-10-04 20:10:04 -07009endif
10
11ifeq ($(V),1)
12 Q =
13else
14 Q = @
15endif
16
Quentin Monnet658e85a2017-12-07 15:00:17 -080017BPF_DIR = $(srctree)/tools/lib/bpf/
Jakub Kicinski71bb4282017-10-04 20:10:04 -070018
19ifneq ($(OUTPUT),)
Quentin Monnet658e85a2017-12-07 15:00:17 -080020 BPF_PATH = $(OUTPUT)
Jakub Kicinski71bb4282017-10-04 20:10:04 -070021else
Quentin Monnet658e85a2017-12-07 15:00:17 -080022 BPF_PATH = $(BPF_DIR)
Jakub Kicinski71bb4282017-10-04 20:10:04 -070023endif
24
25LIBBPF = $(BPF_PATH)libbpf.a
26
Quentin Monnete0a43aa2019-08-30 12:00:37 +010027BPFTOOL_VERSION := $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
Roman Gushchin4bfe3bd2017-12-27 19:16:28 +000028
Jakub Kicinski71bb4282017-10-04 20:10:04 -070029$(LIBBPF): FORCE
Jakub Kicinskidc989d22018-07-16 10:57:16 -070030 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a
Jakub Kicinski71bb4282017-10-04 20:10:04 -070031
32$(LIBBPF)-clean:
33 $(call QUIET_CLEAN, libbpf)
34 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
35
Quentin Monnet658e85a2017-12-07 15:00:17 -080036prefix ?= /usr/local
Quentin Monnet507e5902017-11-28 17:44:32 -080037bash_compdir ?= /usr/share/bash-completion/completions
Jakub Kicinski71bb4282017-10-04 20:10:04 -070038
Jakub Kicinski71bb4282017-10-04 20:10:04 -070039CFLAGS += -O2
Quentin Monneta9436dc2019-08-14 12:37:24 +010040CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers
41CFLAGS += $(filter-out -Wswitch-enum,$(EXTRA_WARNINGS))
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
Peter Wua664a832019-08-09 01:39:11 +010056LIBS = -lelf -lz $(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
Peter Wud66fa3c2019-08-13 01:38:33 +010062FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib
63FEATURE_DISPLAY = libbfd disassembler-four-args zlib
Roman Gushchinfb982662017-12-27 19:16:29 +000064
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)
Stanislav Fomichev6e8ccb42019-01-15 14:03:27 -080098 LIBS += -lbfd -ldl -lopcodes
99else ifeq ($(feature-libbfd-liberty),1)
100 LIBS += -lbfd -ldl -lopcodes -liberty
101else ifeq ($(feature-libbfd-liberty-z),1)
102 LIBS += -lbfd -ldl -lopcodes -liberty -lz
103endif
104
105ifneq ($(filter -lbfd,$(LIBS)),)
Stanislav Fomichev29a9c102018-11-12 13:44:10 -0800106CFLAGS += -DHAVE_LIBBFD_SUPPORT
107SRCS += $(BFD_SRCS)
Stanislav Fomichev29a9c102018-11-12 13:44:10 -0800108endif
109
Quentin Monnet658e85a2017-12-07 15:00:17 -0800110OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
Jakub Kicinskic9c35992017-10-09 10:30:13 -0700111
112$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
113 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700114
Peter Wud66fa3c2019-08-13 01:38:33 +0100115$(OUTPUT)feature.o: | zdep
116
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700117$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
Jiri Olsac8506162018-10-08 10:22:59 +0200118 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700119
120$(OUTPUT)%.o: %.c
121 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
122
123clean: $(LIBBPF)-clean
124 $(call QUIET_CLEAN, bpftool)
Quentin Monnet658e85a2017-12-07 15:00:17 -0800125 $(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
Jakub Kicinskicc5b3402018-03-15 23:26:17 -0700126 $(call QUIET_CLEAN, core-gen)
127 $(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700128
Quentin Monnet658e85a2017-12-07 15:00:17 -0800129install: $(OUTPUT)bpftool
130 $(call QUIET_INSTALL, bpftool)
131 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin
132 $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool
133 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir)
134 $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir)
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700135
Quentin Monnetd3244242017-12-07 15:00:18 -0800136uninstall:
137 $(call QUIET_UNINST, bpftool)
138 $(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
139 $(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool
140
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700141doc:
Quentin Monnet658e85a2017-12-07 15:00:17 -0800142 $(call descend,Documentation)
143
144doc-clean:
145 $(call descend,Documentation,clean)
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700146
147doc-install:
Quentin Monnet658e85a2017-12-07 15:00:17 -0800148 $(call descend,Documentation,install)
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700149
Quentin Monnetd3244242017-12-07 15:00:18 -0800150doc-uninstall:
151 $(call descend,Documentation,uninstall)
152
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700153FORCE:
154
Peter Wud66fa3c2019-08-13 01:38:33 +0100155zdep:
156 @if [ "$(feature-zlib)" != "1" ]; then echo "No zlib found"; exit 1 ; fi
157
158.PHONY: all FORCE clean install uninstall zdep
Quentin Monnetd3244242017-12-07 15:00:18 -0800159.PHONY: doc doc-clean doc-install doc-uninstall
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700160.DEFAULT_GOAL := all