blob: 20a90d8450f8ea0037301664a80bec523699d3fd [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 Monnet45c5589d2019-08-30 12:00:38 +010020 LIBBPF_OUTPUT = $(OUTPUT)/libbpf/
21 LIBBPF_PATH = $(LIBBPF_OUTPUT)
Jakub Kicinski71bb4282017-10-04 20:10:04 -070022else
Quentin Monnet45c5589d2019-08-30 12:00:38 +010023 LIBBPF_PATH = $(BPF_DIR)
Jakub Kicinski71bb4282017-10-04 20:10:04 -070024endif
25
Quentin Monnet45c5589d2019-08-30 12:00:38 +010026LIBBPF = $(LIBBPF_PATH)libbpf.a
Jakub Kicinski71bb4282017-10-04 20:10:04 -070027
Quentin Monnete0a43aa2019-08-30 12:00:37 +010028BPFTOOL_VERSION := $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
Roman Gushchin4bfe3bd2017-12-27 19:16:28 +000029
Jakub Kicinski71bb4282017-10-04 20:10:04 -070030$(LIBBPF): FORCE
Quentin Monnet45c5589d2019-08-30 12:00:38 +010031 $(if $(LIBBPF_OUTPUT),@mkdir -p $(LIBBPF_OUTPUT))
32 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) $(LIBBPF_OUTPUT)libbpf.a
Jakub Kicinski71bb4282017-10-04 20:10:04 -070033
34$(LIBBPF)-clean:
35 $(call QUIET_CLEAN, libbpf)
Quentin Monnet45c5589d2019-08-30 12:00:38 +010036 $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) clean >/dev/null
Jakub Kicinski71bb4282017-10-04 20:10:04 -070037
Quentin Monnet658e85a2017-12-07 15:00:17 -080038prefix ?= /usr/local
Quentin Monnet507e5902017-11-28 17:44:32 -080039bash_compdir ?= /usr/share/bash-completion/completions
Jakub Kicinski71bb4282017-10-04 20:10:04 -070040
Jakub Kicinski71bb4282017-10-04 20:10:04 -070041CFLAGS += -O2
Quentin Monneta9436dc2019-08-14 12:37:24 +010042CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers
43CFLAGS += $(filter-out -Wswitch-enum,$(EXTRA_WARNINGS))
Jakub Kicinskif412eed2018-05-03 18:37:16 -070044CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
45 -I$(srctree)/kernel/bpf/ \
46 -I$(srctree)/tools/include \
47 -I$(srctree)/tools/include/uapi \
Toke Høiland-Jørgensen229c3b42020-01-20 14:06:46 +010048 -I$(srctree)/tools/lib \
Jakub Kicinskif412eed2018-05-03 18:37:16 -070049 -I$(srctree)/tools/perf
Roman Gushchin4bfe3bd2017-12-27 19:16:28 +000050CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
Jiri Olsa0ef6bf32018-10-08 10:22:58 +020051ifneq ($(EXTRA_CFLAGS),)
52CFLAGS += $(EXTRA_CFLAGS)
53endif
Jiri Olsac8506162018-10-08 10:22:59 +020054ifneq ($(EXTRA_LDFLAGS),)
55LDFLAGS += $(EXTRA_LDFLAGS)
56endif
Jiri Olsa0ef6bf32018-10-08 10:22:58 +020057
Quentin Monnet5b84ad22019-08-30 12:00:40 +010058LIBS = $(LIBBPF) -lelf -lz
Jakub Kicinski71bb4282017-10-04 20:10:04 -070059
Quentin Monnet658e85a2017-12-07 15:00:17 -080060INSTALL ?= install
61RM ?= rm -f
Song Liu47c09d62020-03-09 10:32:15 -070062CLANG ?= clang
Quentin Monnet658e85a2017-12-07 15:00:17 -080063
Roman Gushchinfb982662017-12-27 19:16:29 +000064FEATURE_USER = .bpftool
Peter Wud66fa3c2019-08-13 01:38:33 +010065FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib
66FEATURE_DISPLAY = libbfd disassembler-four-args zlib
Roman Gushchinfb982662017-12-27 19:16:29 +000067
68check_feat := 1
69NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
70ifdef MAKECMDGOALS
71ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
72 check_feat := 0
73endif
74endif
75
76ifeq ($(check_feat),1)
77ifeq ($(FEATURES_DUMP),)
78include $(srctree)/tools/build/Makefile.feature
79else
80include $(FEATURES_DUMP)
81endif
82endif
83
84ifeq ($(feature-disassembler-four-args), 1)
85CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
86endif
87
Jakub Kicinski531b0142018-07-10 14:43:05 -070088ifeq ($(feature-reallocarray), 0)
89CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
90endif
91
Jakub Kicinski90126e32018-03-15 23:26:14 -070092include $(wildcard $(OUTPUT)*.d)
Jakub Kicinski71bb4282017-10-04 20:10:04 -070093
94all: $(OUTPUT)bpftool
95
Stanislav Fomichev29a9c102018-11-12 13:44:10 -080096BFD_SRCS = jit_disasm.c
97
98SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
99
100ifeq ($(feature-libbfd),1)
Stanislav Fomichev6e8ccb42019-01-15 14:03:27 -0800101 LIBS += -lbfd -ldl -lopcodes
102else ifeq ($(feature-libbfd-liberty),1)
103 LIBS += -lbfd -ldl -lopcodes -liberty
104else ifeq ($(feature-libbfd-liberty-z),1)
105 LIBS += -lbfd -ldl -lopcodes -liberty -lz
106endif
107
108ifneq ($(filter -lbfd,$(LIBS)),)
Stanislav Fomichev29a9c102018-11-12 13:44:10 -0800109CFLAGS += -DHAVE_LIBBFD_SUPPORT
110SRCS += $(BFD_SRCS)
Stanislav Fomichev29a9c102018-11-12 13:44:10 -0800111endif
112
Quentin Monnet658e85a2017-12-07 15:00:17 -0800113OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
Song Liu47c09d62020-03-09 10:32:15 -0700114_OBJS = $(filter-out $(OUTPUT)prog.o,$(OBJS)) $(OUTPUT)_prog.o
115
116$(OUTPUT)_prog.o: prog.c
117 $(QUIET_CC)$(COMPILE.c) -MMD -DBPFTOOL_WITHOUT_SKELETONS -o $@ $<
118
119$(OUTPUT)_bpftool: $(_OBJS) $(LIBBPF)
120 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(_OBJS) $(LIBS)
121
122skeleton/profiler.bpf.o: skeleton/profiler.bpf.c
123 $(QUIET_CLANG)$(CLANG) -I$(srctree)/tools/lib -g -O2 -target bpf -c $< -o $@
124
125profiler.skel.h: $(OUTPUT)_bpftool skeleton/profiler.bpf.o
126 $(QUIET_GEN)$(OUTPUT)./_bpftool gen skeleton skeleton/profiler.bpf.o > $@
127
128$(OUTPUT)prog.o: prog.c profiler.skel.h
129 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
Jakub Kicinskic9c35992017-10-09 10:30:13 -0700130
131$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
132 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700133
Peter Wud66fa3c2019-08-13 01:38:33 +0100134$(OUTPUT)feature.o: | zdep
135
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700136$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
Quentin Monnet5b84ad22019-08-30 12:00:40 +0100137 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700138
139$(OUTPUT)%.o: %.c
140 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
141
142clean: $(LIBBPF)-clean
143 $(call QUIET_CLEAN, bpftool)
Quentin Monnetfbdb6202019-08-30 12:00:39 +0100144 $(Q)$(RM) -- $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
Song Liu47c09d62020-03-09 10:32:15 -0700145 $(Q)$(RM) -- $(OUTPUT)_bpftool profiler.skel.h skeleton/profiler.bpf.o
Quentin Monnetfbdb6202019-08-30 12:00:39 +0100146 $(Q)$(RM) -r -- $(OUTPUT)libbpf/
Jakub Kicinskicc5b3402018-03-15 23:26:17 -0700147 $(call QUIET_CLEAN, core-gen)
Quentin Monnetfbdb6202019-08-30 12:00:39 +0100148 $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpftool
149 $(Q)$(RM) -r -- $(OUTPUT)feature/
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700150
Quentin Monnet658e85a2017-12-07 15:00:17 -0800151install: $(OUTPUT)bpftool
152 $(call QUIET_INSTALL, bpftool)
153 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin
154 $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool
155 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir)
156 $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir)
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700157
Quentin Monnetd3244242017-12-07 15:00:18 -0800158uninstall:
159 $(call QUIET_UNINST, bpftool)
Quentin Monnetfbdb6202019-08-30 12:00:39 +0100160 $(Q)$(RM) -- $(DESTDIR)$(prefix)/sbin/bpftool
161 $(Q)$(RM) -- $(DESTDIR)$(bash_compdir)/bpftool
Quentin Monnetd3244242017-12-07 15:00:18 -0800162
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700163doc:
Quentin Monnet658e85a2017-12-07 15:00:17 -0800164 $(call descend,Documentation)
165
166doc-clean:
167 $(call descend,Documentation,clean)
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700168
169doc-install:
Quentin Monnet658e85a2017-12-07 15:00:17 -0800170 $(call descend,Documentation,install)
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700171
Quentin Monnetd3244242017-12-07 15:00:18 -0800172doc-uninstall:
173 $(call descend,Documentation,uninstall)
174
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700175FORCE:
176
Peter Wud66fa3c2019-08-13 01:38:33 +0100177zdep:
178 @if [ "$(feature-zlib)" != "1" ]; then echo "No zlib found"; exit 1 ; fi
179
180.PHONY: all FORCE clean install uninstall zdep
Quentin Monnetd3244242017-12-07 15:00:18 -0800181.PHONY: doc doc-clean doc-install doc-uninstall
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700182.DEFAULT_GOAL := all