xref: /openbmc/linux/tools/bpf/bpftool/Makefile (revision 2aa4d498)
1include ../../scripts/Makefile.include
2
3include ../../scripts/utilities.mak
4
5ifeq ($(srctree),)
6srctree := $(patsubst %/,%,$(dir $(CURDIR)))
7srctree := $(patsubst %/,%,$(dir $(srctree)))
8srctree := $(patsubst %/,%,$(dir $(srctree)))
9#$(info Determined 'srctree' to be $(srctree))
10endif
11
12ifneq ($(objtree),)
13#$(info Determined 'objtree' to be $(objtree))
14endif
15
16ifneq ($(OUTPUT),)
17#$(info Determined 'OUTPUT' to be $(OUTPUT))
18# Adding $(OUTPUT) as a directory to look for source files,
19# because use generated output files as sources dependency
20# for flex/bison parsers.
21VPATH += $(OUTPUT)
22export VPATH
23endif
24
25ifeq ($(V),1)
26  Q =
27else
28  Q = @
29endif
30
31BPF_DIR	= $(srctree)/tools/lib/bpf/
32
33ifneq ($(OUTPUT),)
34  BPF_PATH=$(OUTPUT)
35else
36  BPF_PATH=$(BPF_DIR)
37endif
38
39LIBBPF = $(BPF_PATH)libbpf.a
40
41$(LIBBPF): FORCE
42	$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a FEATURES_DUMP=$(FEATURE_DUMP_EXPORT)
43
44$(LIBBPF)-clean:
45	$(call QUIET_CLEAN, libbpf)
46	$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
47
48prefix = /usr
49bash_compdir ?= $(prefix)/share/bash-completion/completions
50
51CC = gcc
52
53CFLAGS += -O2
54CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow
55CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi -I$(srctree)/tools/include -I$(srctree)/tools/lib/bpf -I$(srctree)/kernel/bpf/
56LIBS = -lelf -lbfd -lopcodes $(LIBBPF)
57
58include $(wildcard *.d)
59
60all: $(OUTPUT)bpftool
61
62SRCS=$(wildcard *.c)
63OBJS=$(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
64
65$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
66	$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
67
68$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
69	$(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
70
71$(OUTPUT)%.o: %.c
72	$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
73
74clean: $(LIBBPF)-clean
75	$(call QUIET_CLEAN, bpftool)
76	$(Q)rm -rf $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
77
78install:
79	install $(OUTPUT)bpftool $(prefix)/sbin/bpftool
80	install -m 0755 -d $(bash_compdir)
81	install -m 0644 bash-completion/bpftool $(bash_compdir)
82
83doc:
84	$(Q)$(MAKE) -C Documentation/
85
86doc-install:
87	$(Q)$(MAKE) -C Documentation/ install
88
89FORCE:
90
91.PHONY: all clean FORCE
92.DEFAULT_GOAL := all
93