blob: 892dbf095bffd79ac6bbc9b3a70a33efa3955f54 [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
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)"'
Jakub Kicinski71bb4282017-10-04 20:10:04 -070049LIBS = -lelf -lbfd -lopcodes $(LIBBPF)
50
Quentin Monnet658e85a2017-12-07 15:00:17 -080051INSTALL ?= install
52RM ?= rm -f
53
Roman Gushchinfb982662017-12-27 19:16:29 +000054FEATURE_USER = .bpftool
55FEATURE_TESTS = libbfd disassembler-four-args
56FEATURE_DISPLAY = libbfd disassembler-four-args
57
58check_feat := 1
59NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
60ifdef MAKECMDGOALS
61ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
62 check_feat := 0
63endif
64endif
65
66ifeq ($(check_feat),1)
67ifeq ($(FEATURES_DUMP),)
68include $(srctree)/tools/build/Makefile.feature
69else
70include $(FEATURES_DUMP)
71endif
72endif
73
74ifeq ($(feature-disassembler-four-args), 1)
75CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
76endif
77
Jakub Kicinski90126e32018-03-15 23:26:14 -070078include $(wildcard $(OUTPUT)*.d)
Jakub Kicinski71bb4282017-10-04 20:10:04 -070079
80all: $(OUTPUT)bpftool
81
Quentin Monnet658e85a2017-12-07 15:00:17 -080082SRCS = $(wildcard *.c)
83OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
Jakub Kicinskic9c35992017-10-09 10:30:13 -070084
85$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
86 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
Jakub Kicinski71bb4282017-10-04 20:10:04 -070087
88$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
89 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
90
91$(OUTPUT)%.o: %.c
92 $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
93
94clean: $(LIBBPF)-clean
95 $(call QUIET_CLEAN, bpftool)
Quentin Monnet658e85a2017-12-07 15:00:17 -080096 $(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
Jakub Kicinskicc5b3402018-03-15 23:26:17 -070097 $(call QUIET_CLEAN, core-gen)
98 $(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool
Jakub Kicinski71bb4282017-10-04 20:10:04 -070099
Quentin Monnet658e85a2017-12-07 15:00:17 -0800100install: $(OUTPUT)bpftool
101 $(call QUIET_INSTALL, bpftool)
102 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin
103 $(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool
104 $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir)
105 $(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir)
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700106
Quentin Monnetd3244242017-12-07 15:00:18 -0800107uninstall:
108 $(call QUIET_UNINST, bpftool)
109 $(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
110 $(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool
111
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700112doc:
Quentin Monnet658e85a2017-12-07 15:00:17 -0800113 $(call descend,Documentation)
114
115doc-clean:
116 $(call descend,Documentation,clean)
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700117
118doc-install:
Quentin Monnet658e85a2017-12-07 15:00:17 -0800119 $(call descend,Documentation,install)
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700120
Quentin Monnetd3244242017-12-07 15:00:18 -0800121doc-uninstall:
122 $(call descend,Documentation,uninstall)
123
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700124FORCE:
125
Quentin Monnetd3244242017-12-07 15:00:18 -0800126.PHONY: all FORCE clean install uninstall
127.PHONY: doc doc-clean doc-install doc-uninstall
Jakub Kicinski71bb4282017-10-04 20:10:04 -0700128.DEFAULT_GOAL := all