Makefile 3.4 KB
Newer Older
J
Jakub Kicinski 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
include ../../scripts/Makefile.include
include ../../scripts/utilities.mak

ifeq ($(srctree),)
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
srctree := $(patsubst %/,%,$(dir $(srctree)))
srctree := $(patsubst %/,%,$(dir $(srctree)))
endif

ifeq ($(V),1)
  Q =
else
  Q = @
endif

16
BPF_DIR = $(srctree)/tools/lib/bpf/
J
Jakub Kicinski 已提交
17 18

ifneq ($(OUTPUT),)
19
  BPF_PATH = $(OUTPUT)
J
Jakub Kicinski 已提交
20
else
21
  BPF_PATH = $(BPF_DIR)
J
Jakub Kicinski 已提交
22 23 24 25
endif

LIBBPF = $(BPF_PATH)libbpf.a

26
BPFTOOL_VERSION := $(shell make --no-print-directory -sC ../../.. kernelversion)
27

J
Jakub Kicinski 已提交
28
$(LIBBPF): FORCE
29
	$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a
J
Jakub Kicinski 已提交
30 31 32 33 34

$(LIBBPF)-clean:
	$(call QUIET_CLEAN, libbpf)
	$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null

35
prefix ?= /usr/local
36
bash_compdir ?= /usr/share/bash-completion/completions
J
Jakub Kicinski 已提交
37 38

CFLAGS += -O2
39
CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers
40 41 42 43 44 45
CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
	-I$(srctree)/kernel/bpf/ \
	-I$(srctree)/tools/include \
	-I$(srctree)/tools/include/uapi \
	-I$(srctree)/tools/lib/bpf \
	-I$(srctree)/tools/perf
46
CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
47 48 49
ifneq ($(EXTRA_CFLAGS),)
CFLAGS += $(EXTRA_CFLAGS)
endif
50 51 52
ifneq ($(EXTRA_LDFLAGS),)
LDFLAGS += $(EXTRA_LDFLAGS)
endif
53

S
Stanislav Fomichev 已提交
54
LIBS = -lelf $(LIBBPF)
J
Jakub Kicinski 已提交
55

56 57 58
INSTALL ?= install
RM ?= rm -f

59
FEATURE_USER = .bpftool
60
FEATURE_TESTS = libbfd disassembler-four-args reallocarray
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
FEATURE_DISPLAY = libbfd disassembler-four-args

check_feat := 1
NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
ifdef MAKECMDGOALS
ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
  check_feat := 0
endif
endif

ifeq ($(check_feat),1)
ifeq ($(FEATURES_DUMP),)
include $(srctree)/tools/build/Makefile.feature
else
include $(FEATURES_DUMP)
endif
endif

ifeq ($(feature-disassembler-four-args), 1)
CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
endif

83 84 85 86
ifeq ($(feature-reallocarray), 0)
CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
endif

87
include $(wildcard $(OUTPUT)*.d)
J
Jakub Kicinski 已提交
88 89 90

all: $(OUTPUT)bpftool

S
Stanislav Fomichev 已提交
91 92 93 94 95 96 97 98 99 100
BFD_SRCS = jit_disasm.c

SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))

ifeq ($(feature-libbfd),1)
CFLAGS += -DHAVE_LIBBFD_SUPPORT
SRCS += $(BFD_SRCS)
LIBS += -lbfd -lopcodes
endif

101
OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
102 103 104

$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
	$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
J
Jakub Kicinski 已提交
105 106

$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
107
	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
J
Jakub Kicinski 已提交
108 109 110 111 112 113

$(OUTPUT)%.o: %.c
	$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<

clean: $(LIBBPF)-clean
	$(call QUIET_CLEAN, bpftool)
114
	$(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
115 116
	$(call QUIET_CLEAN, core-gen)
	$(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool
J
Jakub Kicinski 已提交
117

118 119 120 121 122 123
install: $(OUTPUT)bpftool
	$(call QUIET_INSTALL, bpftool)
	$(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin
	$(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool
	$(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir)
	$(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir)
J
Jakub Kicinski 已提交
124

125 126 127 128 129
uninstall:
	$(call QUIET_UNINST, bpftool)
	$(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
	$(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool

J
Jakub Kicinski 已提交
130
doc:
131 132 133 134
	$(call descend,Documentation)

doc-clean:
	$(call descend,Documentation,clean)
J
Jakub Kicinski 已提交
135 136

doc-install:
137
	$(call descend,Documentation,install)
J
Jakub Kicinski 已提交
138

139 140 141
doc-uninstall:
	$(call descend,Documentation,uninstall)

J
Jakub Kicinski 已提交
142 143
FORCE:

144 145
.PHONY: all FORCE clean install uninstall
.PHONY: doc doc-clean doc-install doc-uninstall
J
Jakub Kicinski 已提交
146
.DEFAULT_GOAL := all