xref: /openbmc/linux/tools/bpf/Makefile (revision ba61bb17)
1# SPDX-License-Identifier: GPL-2.0
2include ../scripts/Makefile.include
3
4prefix ?= /usr/local
5
6CC = gcc
7LEX = flex
8YACC = bison
9MAKE = make
10INSTALL ?= install
11
12CFLAGS += -Wall -O2
13CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/include/uapi -I$(srctree)/include
14
15ifeq ($(srctree),)
16srctree := $(patsubst %/,%,$(dir $(CURDIR)))
17srctree := $(patsubst %/,%,$(dir $(srctree)))
18endif
19
20ifeq ($(V),1)
21  Q =
22else
23  Q = @
24endif
25
26FEATURE_USER = .bpf
27FEATURE_TESTS = libbfd disassembler-four-args
28FEATURE_DISPLAY = libbfd disassembler-four-args
29
30check_feat := 1
31NON_CHECK_FEAT_TARGETS := clean bpftool_clean
32ifdef MAKECMDGOALS
33ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
34  check_feat := 0
35endif
36endif
37
38ifeq ($(check_feat),1)
39ifeq ($(FEATURES_DUMP),)
40include $(srctree)/tools/build/Makefile.feature
41else
42include $(FEATURES_DUMP)
43endif
44endif
45
46ifeq ($(feature-disassembler-four-args), 1)
47CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
48endif
49
50$(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y
51	$(QUIET_BISON)$(YACC) -o $@ -d $<
52
53$(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l
54	$(QUIET_FLEX)$(LEX) -o $@ $<
55
56$(OUTPUT)%.o: $(srctree)/tools/bpf/%.c
57	$(QUIET_CC)$(COMPILE.c) -o $@ $<
58
59$(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c
60	$(QUIET_CC)$(COMPILE.c) -o $@ $<
61$(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c
62	$(QUIET_CC)$(COMPILE.c) -o $@ $<
63
64PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
65
66all: $(PROGS) bpftool
67
68$(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'
69$(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o
70	$(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl
71
72$(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o
73	$(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline
74
75$(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o
76	$(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^
77
78$(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c
79$(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c
80$(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c
81
82clean: bpftool_clean
83	$(call QUIET_CLEAN, bpf-progs)
84	$(Q)rm -rf $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
85	       $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*
86	$(call QUIET_CLEAN, core-gen)
87	$(Q)rm -f $(OUTPUT)FEATURE-DUMP.bpf
88
89install: $(PROGS) bpftool_install
90	$(call QUIET_INSTALL, bpf_jit_disasm)
91	$(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin
92	$(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm
93	$(call QUIET_INSTALL, bpf_dbg)
94	$(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg
95	$(call QUIET_INSTALL, bpf_asm)
96	$(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm
97
98bpftool:
99	$(call descend,bpftool)
100
101bpftool_install:
102	$(call descend,bpftool,install)
103
104bpftool_clean:
105	$(call descend,bpftool,clean)
106
107.PHONY: all install clean bpftool bpftool_install bpftool_clean
108